Calling finalize in main thread
This commit is contained in:
parent
a2b385e88f
commit
5e19186950
4 changed files with 11 additions and 8 deletions
|
@ -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 {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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.");
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue