Changeset - 5e19186950b9
[Not reviewed]
0 4 0
Sarang Bharadwaj - 13 years ago 2012-06-03 14:33:39
sarang.bh@gmail.com
Calling finalize in main thread
4 files changed with 11 insertions and 8 deletions:
0 comments (0 inline, 0 general)
backends/twitter/ThreadPool.cpp
Show inline comments
 
@@ -2,16 +2,17 @@
 
DEFINE_LOGGER(logger, "ThreadPool")
 
boost::signals2::signal< void (Thread*, int) > onWorkCompleted;
 

	
 
void Worker(Thread *t, int wid)
 
static void Worker(Thread *t, int wid, Swift::EventLoop *loop)
 
{
 
	LOG4CXX_INFO(logger, "Starting thread " << wid)
 
	t->run();
 
	onWorkCompleted(t, wid);
 
	loop->postEvent(boost::bind(boost::ref(onWorkCompleted), t, wid), boost::shared_ptr<Swift::EventOwner>());
 
}
 

	
 

	
 
ThreadPool::ThreadPool(int maxthreads) : MAX_THREADS(maxthreads)
 
ThreadPool::ThreadPool(Swift::EventLoop *loop, int maxthreads) : MAX_THREADS(maxthreads)
 
{
 
	this->loop = loop;
 
	activeThreads = 0;
 
	worker = new boost::thread*[MAX_THREADS];
 
	for(int i=0 ; i<MAX_THREADS ; i++) {
 
@@ -99,7 +100,7 @@ void ThreadPool::scheduleFromQueue()
 
		LOG4CXX_INFO(logger, "Worker Available. Creating thread #" << w)
 
		Thread *t = requestQueue.front(); requestQueue.pop();
 
		t->setThreadID(w);
 
		worker[w] = new boost::thread(Worker, t, w);
 
		worker[w] = new boost::thread(Worker, t, w, loop);
 
		updateActiveThreadCount(-1);
 
	}
 
	criticalregion.unlock();
 
@@ -112,7 +113,7 @@ void ThreadPool::runAsThread(Thread *t)
 
	if((w = getFreeThread()) != -1) {
 
		LOG4CXX_INFO(logger, "Creating thread #" << w)
 
		t->setThreadID(w);
 
		worker[w] = new boost::thread(Worker, t, w);
 
		worker[w] = new boost::thread(Worker, t, w, loop);
 
		updateActiveThreadCount(-1);
 
	}
 
	else {
backends/twitter/ThreadPool.h
Show inline comments
 
@@ -7,6 +7,7 @@
 
#include <queue>
 
#include <iostream>
 
#include "transport/logging.h"
 
#include "Swiften/Swiften.h"
 

	
 

	
 
/*
 
@@ -54,11 +55,12 @@ class ThreadPool
 
	boost::mutex count_lock;
 
	boost::mutex pool_lock;
 
	boost::mutex criticalregion;
 
	Swift::EventLoop *loop;
 

	
 
	boost::signals2::signal  < void () > onWorkerAvailable;
 

	
 
	public:
 
	ThreadPool(int maxthreads);
 
	ThreadPool(Swift::EventLoop *loop, int maxthreads);
 
	~ThreadPool();
 
	void runAsThread(Thread *t);
 
	int getActiveThreadCount(); 
backends/twitter/libtwitcurl/twitcurl.cpp
Show inline comments
 
@@ -603,7 +603,7 @@ bool twitCurl::userLookup( std::vector<std::string> &userInfo, bool isUserId )
 
    {
 
		std::string userIds = isUserId?twitCurlDefaults::TWITCURL_USERID : twitCurlDefaults::TWITCURL_SCREENNAME;
 
		std::string sep = "";
 
		for(int i=0 ; i<std::min(100U, userInfo.size()) ; i++, sep = ",")
 
		for(int i=0 ; i<std::min(100U,(unsigned int) userInfo.size()) ; i++, sep = ",")
 
			userIds += sep + userInfo[i];
 
 
        /* Set URL */
backends/twitter/main.cpp
Show inline comments
 
@@ -73,7 +73,7 @@ class TwitterPlugin : public NetworkPlugin {
 
			m_conn->onDataRead.connect(boost::bind(&TwitterPlugin::_handleDataRead, this, _1));
 
			m_conn->connect(Swift::HostAddressPort(Swift::HostAddress(host), port));
 

	
 
			tp = new ThreadPool(10);
 
			tp = new ThreadPool(loop_, 10);
 
				
 
			LOG4CXX_INFO(logger, "Starting the plugin.");
 
		}
0 comments (0 inline, 0 general)