From: Aditya Agarwal Date: Tue, 25 Dec 2007 22:58:50 +0000 (+0000) Subject: -- Allow ThreadPoolManager tp return immediately from addTask X-Git-Tag: 0.2.0~1066 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=4b6ff2dabcc67b437f9fb9e6930cb4705bd936df;p=common%2Fthrift.git -- Allow ThreadPoolManager tp return immediately from addTask Summary: - it should be possible to specify a zero timeout if the pendingTaskQueue is already full Reviewed By: marc Test Plan: - Tested in search git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665406 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/lib/cpp/src/concurrency/ThreadManager.cpp b/lib/cpp/src/concurrency/ThreadManager.cpp index eec94be0..604602e0 100644 --- a/lib/cpp/src/concurrency/ThreadManager.cpp +++ b/lib/cpp/src/concurrency/ThreadManager.cpp @@ -421,9 +421,7 @@ void ThreadManager::Impl::removeWorker(size_t value) { } if (pendingTaskCountMax_ > 0 && (tasks_.size() >= pendingTaskCountMax_)) { - - if (canSleep()) { - + if (canSleep() && timeout >= 0) { while (pendingTaskCountMax_ > 0 && tasks_.size() >= pendingTaskCountMax_) { monitor_.wait(timeout); } diff --git a/lib/cpp/src/concurrency/ThreadManager.h b/lib/cpp/src/concurrency/ThreadManager.h index 4c564615..7bca5d0e 100644 --- a/lib/cpp/src/concurrency/ThreadManager.h +++ b/lib/cpp/src/concurrency/ThreadManager.h @@ -123,7 +123,9 @@ class ThreadManager { * @param task The task to queue for execution * * @param timeout Time to wait in milliseconds to add a task when a pending-task-count - * is specified + * is specified. Specific cases: + * timeout = 0 : Wait forever to queue task. + * timeout = -1 : Return immediately if pending task count exceeds specified max * * @throws TooManyPendingTasksException Pending task count exceeds max pending task count */