From: Roger Meier Date: Thu, 8 Dec 2011 19:34:01 +0000 (+0000) Subject: THRIFT-1442 TNonblockingServer: Refactor to allow multiple IO Threads X-Git-Tag: 0.9.1~506 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=d0cdecf4a1baec625cf73e91b0cef406c7b4039e;p=common%2Fthrift.git THRIFT-1442 TNonblockingServer: Refactor to allow multiple IO Threads Fix Warnings Patch: Dave Watson git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1212067 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/lib/cpp/src/concurrency/Mutex.cpp b/lib/cpp/src/concurrency/Mutex.cpp index 0cfa0ad7..332d415b 100644 --- a/lib/cpp/src/concurrency/Mutex.cpp +++ b/lib/cpp/src/concurrency/Mutex.cpp @@ -154,6 +154,7 @@ class Mutex::impl { PROFILE_MUTEX_NOT_LOCKED(); return false; #else + (void)milliseconds; // If pthread_mutex_timedlock isn't supported, the safest thing to do // is just do a nonblocking trylock. return trylock(); diff --git a/lib/cpp/src/server/TNonblockingServer.cpp b/lib/cpp/src/server/TNonblockingServer.cpp index ba029a9c..e8d0e713 100644 --- a/lib/cpp/src/server/TNonblockingServer.cpp +++ b/lib/cpp/src/server/TNonblockingServer.cpp @@ -866,7 +866,6 @@ TNonblockingServer::TConnection* TNonblockingServer::createConnection( Guard g(connMutex_); // pick an IO thread to handle this connection -- currently round robin - assert(nextIOThread_ >= 0); assert(nextIOThread_ < ioThreads_.size()); int selectedThreadIdx = nextIOThread_; nextIOThread_ = (nextIOThread_ + 1) % ioThreads_.size(); @@ -1158,7 +1157,7 @@ void TNonblockingServer::expireClose(boost::shared_ptr task) { void TNonblockingServer::stop() { // Breaks the event loop in all threads so that they end ASAP. - for (int i = 0; i < ioThreads_.size(); ++i) { + for (uint32_t i = 0; i < ioThreads_.size(); ++i) { ioThreads_[i]->stop(); } } @@ -1177,7 +1176,7 @@ void TNonblockingServer::serve() { numIOThreads_ = DEFAULT_IO_THREADS; } - for (int id = 0; id < numIOThreads_; ++id) { + for (uint32_t id = 0; id < numIOThreads_; ++id) { // the first IO thread also does the listening on server socket int listenFd = (id == 0 ? serverSocket_ : -1); @@ -1211,7 +1210,7 @@ void TNonblockingServer::serve() { assert(ioThreadFactory_.get()); // intentionally starting at thread 1, not 0 - for (int i = 1; i < ioThreads_.size(); ++i) { + for (uint32_t i = 1; i < ioThreads_.size(); ++i) { shared_ptr thread = ioThreadFactory_->newThread(ioThreads_[i]); ioThreads_[i]->setThread(thread); thread->start(); @@ -1223,7 +1222,7 @@ void TNonblockingServer::serve() { ioThreads_[0]->run(); // Ensure all threads are finished before exiting serve() - for (int i = 0; i < ioThreads_.size(); ++i) { + for (uint32_t i = 0; i < ioThreads_.size(); ++i) { ioThreads_[i]->join(); GlobalOutput.printf("TNonblocking: join done for IO thread #%d", i); } @@ -1353,6 +1352,7 @@ bool TNonblockingIOThread::notify(TNonblockingServer::TConnection* conn) { void TNonblockingIOThread::notifyHandler(int fd, short which, void* v) { TNonblockingIOThread* ioThread = (TNonblockingIOThread*) v; assert(ioThread); + (void)which; while (true) { TNonblockingServer::TConnection* connection = 0; diff --git a/lib/cpp/src/server/TNonblockingServer.h b/lib/cpp/src/server/TNonblockingServer.h index 84e384c2..9eedcee0 100644 --- a/lib/cpp/src/server/TNonblockingServer.h +++ b/lib/cpp/src/server/TNonblockingServer.h @@ -170,7 +170,7 @@ class TNonblockingServer : public TServer { std::vector > ioThreads_; // Index of next IO Thread to be used (for round-robin) - int nextIOThread_; + uint32_t nextIOThread_; // Synchronizes access to connection stack and similar data Mutex connMutex_;