Bring up of thread manager
facebook::thrift::concurrency::test.ThreadManagerTest::test00
Launch N tasks that block for time T, verify they all complete and that the thread manager cleans up properly
when it goes out of scope
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664725 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cpp/src/concurrency/ThreadManager.h b/lib/cpp/src/concurrency/ThreadManager.h
index 352afb9..3b87c21 100644
--- a/lib/cpp/src/concurrency/ThreadManager.h
+++ b/lib/cpp/src/concurrency/ThreadManager.h
@@ -14,53 +14,12 @@
class ThreadManager;
-/** PoolPolicy class
-
- Tracks performance of ThreadManager object and makes desired changes in thread pool count if any. */
-
-class PoolPolicy {
-
- public:
-
- PoolPolicy() {}
-
- virtual ~PoolPolicy() {}
-
- virtual void onEmpty(ThreadManager* source) const = 0;
-
- virtual void onLowWatermark(ThreadManager* source) const = 0;
-
- virtual void onHighWatermark(ThreadManager* source) const = 0;
-
-};
-
-class BasicPoolPolicy : public PoolPolicy {
-
- public:
-
- BasicPoolPolicy();
-
- virtual ~BasicPoolPolicy();
-
- virtual void onEmpty(ThreadManager* source) const;
-
- virtual void onLowWatermark(ThreadManager* source) const;
-
- virtual void onHighWatermark(ThreadManager* source) const;
-
- private:
-
- class Impl;
-
- Impl* _impl;
-};
-
/** ThreadManager class
This class manages a pool of threads. It uses a ThreadFactory to create threads. It never actually creates or destroys worker threads, rather
it maintains statistics on number of idle threads, number of active threads, task backlog, and average wait and service times and informs the
PoolPolicy object bound to instances of this manager of interesting transitions. It is then up the PoolPolicy object to decide if the thread pool
- size needs to be adjusted and call this object addThread and removeThread methods to make changes.
+ size needs to be adjusted and call this object addWorker and removeWorker methods to make changes.
This design allows different policy implementations to used this code to handle basic worker thread management and worker task execution and focus on
policy issues. The simplest policy, StaticPolicy, does nothing other than create a fixed number of threads. */
@@ -69,29 +28,17 @@
public:
- ThreadManager(size_t highWatermark=4, size_t lowWatermark=2) {};
+ ThreadManager() {}
- virtual ~ThreadManager() {};
-
- virtual const PoolPolicy* poolPolicy() const = 0;
-
- virtual void poolPolicy(const PoolPolicy* value) = 0;
+ virtual ~ThreadManager() {}
virtual const ThreadFactory* threadFactory() const = 0;
virtual void threadFactory(const ThreadFactory* value) = 0;
- virtual size_t highWatermark() const = 0;
+ virtual void addWorker(size_t value=1) = 0;
- virtual void highWatermark(size_t value) = 0;
-
- virtual size_t lowWatermark() const = 0;
-
- virtual void lowWatermark(size_t value) = 0;
-
- virtual void addThread(size_t value=1) = 0;
-
- virtual void removeThread(size_t value=1) = 0;
+ virtual void removeWorker(size_t value=1) = 0;
/** Gets the current number of idle worker threads */
@@ -117,7 +64,9 @@
virtual void remove(Runnable* task) = 0;
- static ThreadManager* newThreadManager(size_t lowWatermark=2, size_t highWatermark=4);
+ static ThreadManager* newThreadManager();
+
+ static ThreadManager* newSimpleThreadManager();
class Task;