David Reiss | ea2cba8 | 2009-03-30 21:35:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
Mark Slee | 9f0c651 | 2007-02-28 23:58:26 +0000 | [diff] [blame] | 19 | |
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 20 | #include "ThreadManager.h" |
Marc Slemko | d466b21 | 2006-07-20 00:04:18 +0000 | [diff] [blame] | 21 | #include "Exception.h" |
Marc Slemko | 0e53ccd | 2006-07-17 23:51:05 +0000 | [diff] [blame] | 22 | #include "Monitor.h" |
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 23 | |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 24 | #include <boost/shared_ptr.hpp> |
| 25 | |
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 26 | #include <assert.h> |
Marc Slemko | 0e53ccd | 2006-07-17 23:51:05 +0000 | [diff] [blame] | 27 | #include <queue> |
| 28 | #include <set> |
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 29 | |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 30 | #if defined(DEBUG) |
| 31 | #include <iostream> |
| 32 | #endif //defined(DEBUG) |
| 33 | |
T Jake Luciani | b5e6221 | 2009-01-31 22:36:20 +0000 | [diff] [blame] | 34 | namespace apache { namespace thrift { namespace concurrency { |
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 35 | |
David Reiss | d4a269c | 2007-08-23 02:37:19 +0000 | [diff] [blame] | 36 | using boost::shared_ptr; |
| 37 | using boost::dynamic_pointer_cast; |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 38 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 39 | /** |
| 40 | * ThreadManager class |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 41 | * |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 42 | * This class manages a pool of threads. It uses a ThreadFactory to create |
| 43 | * threads. It never actually creates or destroys worker threads, rather |
| 44 | * it maintains statistics on number of idle threads, number of active threads, |
| 45 | * task backlog, and average wait and service times. |
| 46 | * |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 47 | * @version $Id:$ |
| 48 | */ |
Marc Slemko | 0e53ccd | 2006-07-17 23:51:05 +0000 | [diff] [blame] | 49 | class ThreadManager::Impl : public ThreadManager { |
| 50 | |
| 51 | public: |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 52 | Impl() : |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 53 | workerCount_(0), |
| 54 | workerMaxCount_(0), |
| 55 | idleCount_(0), |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 56 | pendingTaskCountMax_(0), |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 57 | state_(ThreadManager::UNINITIALIZED) {} |
Marc Slemko | d466b21 | 2006-07-20 00:04:18 +0000 | [diff] [blame] | 58 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 59 | ~Impl() { stop(); } |
Marc Slemko | d466b21 | 2006-07-20 00:04:18 +0000 | [diff] [blame] | 60 | |
Marc Slemko | fe5ba12e | 2006-07-20 21:16:27 +0000 | [diff] [blame] | 61 | void start(); |
Marc Slemko | 0e53ccd | 2006-07-17 23:51:05 +0000 | [diff] [blame] | 62 | |
Mark Slee | 7c10eaf | 2007-03-01 02:45:10 +0000 | [diff] [blame] | 63 | void stop() { stopImpl(false); } |
| 64 | |
| 65 | void join() { stopImpl(true); } |
Marc Slemko | 0e53ccd | 2006-07-17 23:51:05 +0000 | [diff] [blame] | 66 | |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 67 | const ThreadManager::STATE state() const { |
| 68 | return state_; |
| 69 | } |
Marc Slemko | fe5ba12e | 2006-07-20 21:16:27 +0000 | [diff] [blame] | 70 | |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 71 | shared_ptr<ThreadFactory> threadFactory() const { |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 72 | Synchronized s(monitor_); |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 73 | return threadFactory_; |
Marc Slemko | 0e53ccd | 2006-07-17 23:51:05 +0000 | [diff] [blame] | 74 | } |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 75 | |
| 76 | void threadFactory(shared_ptr<ThreadFactory> value) { |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 77 | Synchronized s(monitor_); |
| 78 | threadFactory_ = value; |
Marc Slemko | 0e53ccd | 2006-07-17 23:51:05 +0000 | [diff] [blame] | 79 | } |
| 80 | |
Marc Slemko | d466b21 | 2006-07-20 00:04:18 +0000 | [diff] [blame] | 81 | void addWorker(size_t value); |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 82 | |
Marc Slemko | d466b21 | 2006-07-20 00:04:18 +0000 | [diff] [blame] | 83 | void removeWorker(size_t value); |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 84 | |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 85 | size_t idleWorkerCount() const { |
| 86 | return idleCount_; |
| 87 | } |
Marc Slemko | 0e53ccd | 2006-07-17 23:51:05 +0000 | [diff] [blame] | 88 | |
| 89 | size_t workerCount() const { |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 90 | Synchronized s(monitor_); |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 91 | return workerCount_; |
Marc Slemko | 0e53ccd | 2006-07-17 23:51:05 +0000 | [diff] [blame] | 92 | } |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 93 | |
Marc Slemko | 0e53ccd | 2006-07-17 23:51:05 +0000 | [diff] [blame] | 94 | size_t pendingTaskCount() const { |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 95 | Synchronized s(monitor_); |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 96 | return tasks_.size(); |
Marc Slemko | 0e53ccd | 2006-07-17 23:51:05 +0000 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | size_t totalTaskCount() const { |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 100 | Synchronized s(monitor_); |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 101 | return tasks_.size() + workerCount_ - idleCount_; |
Marc Slemko | 0e53ccd | 2006-07-17 23:51:05 +0000 | [diff] [blame] | 102 | } |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 103 | |
| 104 | size_t pendingTaskCountMax() const { |
| 105 | Synchronized s(monitor_); |
| 106 | return pendingTaskCountMax_; |
| 107 | } |
| 108 | |
| 109 | void pendingTaskCountMax(const size_t value) { |
| 110 | Synchronized s(monitor_); |
| 111 | pendingTaskCountMax_ = value; |
| 112 | } |
| 113 | |
| 114 | bool canSleep(); |
| 115 | |
Mark Slee | 9b82d27 | 2007-05-23 05:16:07 +0000 | [diff] [blame] | 116 | void add(shared_ptr<Runnable> value, int64_t timeout); |
Marc Slemko | 0e53ccd | 2006-07-17 23:51:05 +0000 | [diff] [blame] | 117 | |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 118 | void remove(shared_ptr<Runnable> task); |
Marc Slemko | 0e53ccd | 2006-07-17 23:51:05 +0000 | [diff] [blame] | 119 | |
David Reiss | 01fe153 | 2010-03-09 05:19:25 +0000 | [diff] [blame^] | 120 | shared_ptr<Runnable> removeNextPending(); |
| 121 | |
Marc Slemko | 0e53ccd | 2006-07-17 23:51:05 +0000 | [diff] [blame] | 122 | private: |
Mark Slee | 7c10eaf | 2007-03-01 02:45:10 +0000 | [diff] [blame] | 123 | void stopImpl(bool join); |
| 124 | |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 125 | size_t workerCount_; |
| 126 | size_t workerMaxCount_; |
| 127 | size_t idleCount_; |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 128 | size_t pendingTaskCountMax_; |
| 129 | |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 130 | ThreadManager::STATE state_; |
| 131 | shared_ptr<ThreadFactory> threadFactory_; |
Marc Slemko | 0e53ccd | 2006-07-17 23:51:05 +0000 | [diff] [blame] | 132 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 133 | |
Marc Slemko | 0e53ccd | 2006-07-17 23:51:05 +0000 | [diff] [blame] | 134 | friend class ThreadManager::Task; |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 135 | std::queue<shared_ptr<Task> > tasks_; |
| 136 | Monitor monitor_; |
| 137 | Monitor workerMonitor_; |
Marc Slemko | fe5ba12e | 2006-07-20 21:16:27 +0000 | [diff] [blame] | 138 | |
Marc Slemko | 0e53ccd | 2006-07-17 23:51:05 +0000 | [diff] [blame] | 139 | friend class ThreadManager::Worker; |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 140 | std::set<shared_ptr<Thread> > workers_; |
| 141 | std::set<shared_ptr<Thread> > deadWorkers_; |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 142 | std::map<const Thread::id_t, shared_ptr<Thread> > idMap_; |
Marc Slemko | 0e53ccd | 2006-07-17 23:51:05 +0000 | [diff] [blame] | 143 | }; |
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 144 | |
| 145 | class ThreadManager::Task : public Runnable { |
| 146 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 147 | public: |
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 148 | enum STATE { |
| 149 | WAITING, |
| 150 | EXECUTING, |
| 151 | CANCELLED, |
| 152 | COMPLETE |
| 153 | }; |
| 154 | |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 155 | Task(shared_ptr<Runnable> runnable) : |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 156 | runnable_(runnable), |
| 157 | state_(WAITING) {} |
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 158 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 159 | ~Task() {} |
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 160 | |
| 161 | void run() { |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 162 | if (state_ == EXECUTING) { |
| 163 | runnable_->run(); |
| 164 | state_ = COMPLETE; |
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 165 | } |
| 166 | } |
| 167 | |
David Reiss | 01fe153 | 2010-03-09 05:19:25 +0000 | [diff] [blame^] | 168 | shared_ptr<Runnable> getRunnable() { |
| 169 | return runnable_; |
| 170 | } |
| 171 | |
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 172 | private: |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 173 | shared_ptr<Runnable> runnable_; |
Marc Slemko | d466b21 | 2006-07-20 00:04:18 +0000 | [diff] [blame] | 174 | friend class ThreadManager::Worker; |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 175 | STATE state_; |
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 176 | }; |
| 177 | |
| 178 | class ThreadManager::Worker: public Runnable { |
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 179 | enum STATE { |
| 180 | UNINITIALIZED, |
| 181 | STARTING, |
| 182 | STARTED, |
| 183 | STOPPING, |
| 184 | STOPPED |
| 185 | }; |
| 186 | |
| 187 | public: |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 188 | Worker(ThreadManager::Impl* manager) : |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 189 | manager_(manager), |
| 190 | state_(UNINITIALIZED), |
| 191 | idle_(false) {} |
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 192 | |
| 193 | ~Worker() {} |
| 194 | |
Mark Slee | 7c10eaf | 2007-03-01 02:45:10 +0000 | [diff] [blame] | 195 | private: |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 196 | bool isActive() const { |
Mark Slee | 7c10eaf | 2007-03-01 02:45:10 +0000 | [diff] [blame] | 197 | return |
| 198 | (manager_->workerCount_ <= manager_->workerMaxCount_) || |
| 199 | (manager_->state_ == JOINING && !manager_->tasks_.empty()); |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 200 | } |
Marc Slemko | fe5ba12e | 2006-07-20 21:16:27 +0000 | [diff] [blame] | 201 | |
Mark Slee | 7c10eaf | 2007-03-01 02:45:10 +0000 | [diff] [blame] | 202 | public: |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 203 | /** |
| 204 | * Worker entry point |
| 205 | * |
| 206 | * As long as worker thread is running, pull tasks off the task queue and |
| 207 | * execute. |
| 208 | */ |
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 209 | void run() { |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 210 | bool active = false; |
Marc Slemko | fe5ba12e | 2006-07-20 21:16:27 +0000 | [diff] [blame] | 211 | bool notifyManager = false; |
| 212 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 213 | /** |
| 214 | * Increment worker semaphore and notify manager if worker count reached |
| 215 | * desired max |
| 216 | * |
| 217 | * Note: We have to release the monitor and acquire the workerMonitor |
| 218 | * since that is what the manager blocks on for worker add/remove |
| 219 | */ |
| 220 | { |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 221 | Synchronized s(manager_->monitor_); |
| 222 | active = manager_->workerCount_ < manager_->workerMaxCount_; |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 223 | if (active) { |
David Reiss | 96d2388 | 2007-07-26 21:10:32 +0000 | [diff] [blame] | 224 | manager_->workerCount_++; |
| 225 | notifyManager = manager_->workerCount_ == manager_->workerMaxCount_; |
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 226 | } |
| 227 | } |
| 228 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 229 | if (notifyManager) { |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 230 | Synchronized s(manager_->workerMonitor_); |
| 231 | manager_->workerMonitor_.notify(); |
Marc Slemko | fe5ba12e | 2006-07-20 21:16:27 +0000 | [diff] [blame] | 232 | notifyManager = false; |
| 233 | } |
| 234 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 235 | while (active) { |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 236 | shared_ptr<ThreadManager::Task> task; |
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 237 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 238 | /** |
| 239 | * While holding manager monitor block for non-empty task queue (Also |
| 240 | * check that the thread hasn't been requested to stop). Once the queue |
| 241 | * is non-empty, dequeue a task, release monitor, and execute. If the |
| 242 | * worker max count has been decremented such that we exceed it, mark |
| 243 | * ourself inactive, decrement the worker count and notify the manager |
| 244 | * (technically we're notifying the next blocked thread but eventually |
| 245 | * the manager will see it. |
| 246 | */ |
| 247 | { |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 248 | Synchronized s(manager_->monitor_); |
David Reiss | 96d2388 | 2007-07-26 21:10:32 +0000 | [diff] [blame] | 249 | active = isActive(); |
Mark Slee | 7c10eaf | 2007-03-01 02:45:10 +0000 | [diff] [blame] | 250 | |
David Reiss | 96d2388 | 2007-07-26 21:10:32 +0000 | [diff] [blame] | 251 | while (active && manager_->tasks_.empty()) { |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 252 | manager_->idleCount_++; |
Mark Slee | 7c10eaf | 2007-03-01 02:45:10 +0000 | [diff] [blame] | 253 | idle_ = true; |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 254 | manager_->monitor_.wait(); |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 255 | active = isActive(); |
Mark Slee | 7c10eaf | 2007-03-01 02:45:10 +0000 | [diff] [blame] | 256 | idle_ = false; |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 257 | manager_->idleCount_--; |
David Reiss | 96d2388 | 2007-07-26 21:10:32 +0000 | [diff] [blame] | 258 | } |
Marc Slemko | fe5ba12e | 2006-07-20 21:16:27 +0000 | [diff] [blame] | 259 | |
David Reiss | 96d2388 | 2007-07-26 21:10:32 +0000 | [diff] [blame] | 260 | if (active) { |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 261 | if (!manager_->tasks_.empty()) { |
| 262 | task = manager_->tasks_.front(); |
| 263 | manager_->tasks_.pop(); |
| 264 | if (task->state_ == ThreadManager::Task::WAITING) { |
| 265 | task->state_ = ThreadManager::Task::EXECUTING; |
David Reiss | 96d2388 | 2007-07-26 21:10:32 +0000 | [diff] [blame] | 266 | } |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 267 | |
| 268 | /* If we have a pending task max and we just dropped below it, wakeup any |
| 269 | thread that might be blocked on add. */ |
Mark Slee | 2782d6d | 2007-05-23 04:55:30 +0000 | [diff] [blame] | 270 | if (manager_->pendingTaskCountMax_ != 0 && |
| 271 | manager_->tasks_.size() == manager_->pendingTaskCountMax_ - 1) { |
David Reiss | e3a6492 | 2008-06-10 22:55:04 +0000 | [diff] [blame] | 272 | manager_->monitor_.notify(); |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 273 | } |
David Reiss | 96d2388 | 2007-07-26 21:10:32 +0000 | [diff] [blame] | 274 | } |
| 275 | } else { |
| 276 | idle_ = true; |
| 277 | manager_->workerCount_--; |
Mark Slee | 7c10eaf | 2007-03-01 02:45:10 +0000 | [diff] [blame] | 278 | notifyManager = (manager_->workerCount_ == manager_->workerMaxCount_); |
David Reiss | 96d2388 | 2007-07-26 21:10:32 +0000 | [diff] [blame] | 279 | } |
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 280 | } |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 281 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 282 | if (task != NULL) { |
David Reiss | 96d2388 | 2007-07-26 21:10:32 +0000 | [diff] [blame] | 283 | if (task->state_ == ThreadManager::Task::EXECUTING) { |
| 284 | try { |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 285 | task->run(); |
| 286 | } catch(...) { |
| 287 | // XXX need to log this |
David Reiss | 96d2388 | 2007-07-26 21:10:32 +0000 | [diff] [blame] | 288 | } |
| 289 | } |
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 290 | } |
Marc Slemko | fe5ba12e | 2006-07-20 21:16:27 +0000 | [diff] [blame] | 291 | } |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 292 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 293 | { |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 294 | Synchronized s(manager_->workerMonitor_); |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 295 | manager_->deadWorkers_.insert(this->thread()); |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 296 | if (notifyManager) { |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 297 | manager_->workerMonitor_.notify(); |
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 298 | } |
| 299 | } |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 300 | |
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 301 | return; |
| 302 | } |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 303 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 304 | private: |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 305 | ThreadManager::Impl* manager_; |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 306 | friend class ThreadManager::Impl; |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 307 | STATE state_; |
| 308 | bool idle_; |
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 309 | }; |
| 310 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 311 | |
| 312 | void ThreadManager::Impl::addWorker(size_t value) { |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 313 | std::set<shared_ptr<Thread> > newThreads; |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 314 | for (size_t ix = 0; ix < value; ix++) { |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 315 | class ThreadManager::Worker; |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 316 | shared_ptr<ThreadManager::Worker> worker = shared_ptr<ThreadManager::Worker>(new ThreadManager::Worker(this)); |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 317 | newThreads.insert(threadFactory_->newThread(worker)); |
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 318 | } |
Marc Slemko | fe5ba12e | 2006-07-20 21:16:27 +0000 | [diff] [blame] | 319 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 320 | { |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 321 | Synchronized s(monitor_); |
| 322 | workerMaxCount_ += value; |
| 323 | workers_.insert(newThreads.begin(), newThreads.end()); |
Marc Slemko | fe5ba12e | 2006-07-20 21:16:27 +0000 | [diff] [blame] | 324 | } |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 325 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 326 | for (std::set<shared_ptr<Thread> >::iterator ix = newThreads.begin(); ix != newThreads.end(); ix++) { |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 327 | shared_ptr<ThreadManager::Worker> worker = dynamic_pointer_cast<ThreadManager::Worker, Runnable>((*ix)->runnable()); |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 328 | worker->state_ = ThreadManager::Worker::STARTING; |
Marc Slemko | d466b21 | 2006-07-20 00:04:18 +0000 | [diff] [blame] | 329 | (*ix)->start(); |
Marc Slemko | a647903 | 2007-06-05 22:20:14 +0000 | [diff] [blame] | 330 | idMap_.insert(std::pair<const Thread::id_t, shared_ptr<Thread> >((*ix)->getId(), *ix)); |
Marc Slemko | d466b21 | 2006-07-20 00:04:18 +0000 | [diff] [blame] | 331 | } |
| 332 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 333 | { |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 334 | Synchronized s(workerMonitor_); |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 335 | while (workerCount_ != workerMaxCount_) { |
| 336 | workerMonitor_.wait(); |
Marc Slemko | fe5ba12e | 2006-07-20 21:16:27 +0000 | [diff] [blame] | 337 | } |
| 338 | } |
| 339 | } |
Marc Slemko | d466b21 | 2006-07-20 00:04:18 +0000 | [diff] [blame] | 340 | |
Marc Slemko | fe5ba12e | 2006-07-20 21:16:27 +0000 | [diff] [blame] | 341 | void ThreadManager::Impl::start() { |
| 342 | |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 343 | if (state_ == ThreadManager::STOPPED) { |
Marc Slemko | fe5ba12e | 2006-07-20 21:16:27 +0000 | [diff] [blame] | 344 | return; |
| 345 | } |
| 346 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 347 | { |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 348 | Synchronized s(monitor_); |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 349 | if (state_ == ThreadManager::UNINITIALIZED) { |
| 350 | if (threadFactory_ == NULL) { |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 351 | throw InvalidArgumentException(); |
| 352 | } |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 353 | state_ = ThreadManager::STARTED; |
| 354 | monitor_.notifyAll(); |
Marc Slemko | fe5ba12e | 2006-07-20 21:16:27 +0000 | [diff] [blame] | 355 | } |
| 356 | |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 357 | while (state_ == STARTING) { |
| 358 | monitor_.wait(); |
Marc Slemko | d466b21 | 2006-07-20 00:04:18 +0000 | [diff] [blame] | 359 | } |
| 360 | } |
| 361 | } |
| 362 | |
Mark Slee | 7c10eaf | 2007-03-01 02:45:10 +0000 | [diff] [blame] | 363 | void ThreadManager::Impl::stopImpl(bool join) { |
Marc Slemko | d466b21 | 2006-07-20 00:04:18 +0000 | [diff] [blame] | 364 | bool doStop = false; |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 365 | if (state_ == ThreadManager::STOPPED) { |
Marc Slemko | fe5ba12e | 2006-07-20 21:16:27 +0000 | [diff] [blame] | 366 | return; |
| 367 | } |
| 368 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 369 | { |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 370 | Synchronized s(monitor_); |
Mark Slee | 7c10eaf | 2007-03-01 02:45:10 +0000 | [diff] [blame] | 371 | if (state_ != ThreadManager::STOPPING && |
| 372 | state_ != ThreadManager::JOINING && |
| 373 | state_ != ThreadManager::STOPPED) { |
Marc Slemko | d466b21 | 2006-07-20 00:04:18 +0000 | [diff] [blame] | 374 | doStop = true; |
Mark Slee | 7c10eaf | 2007-03-01 02:45:10 +0000 | [diff] [blame] | 375 | state_ = join ? ThreadManager::JOINING : ThreadManager::STOPPING; |
Marc Slemko | d466b21 | 2006-07-20 00:04:18 +0000 | [diff] [blame] | 376 | } |
| 377 | } |
| 378 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 379 | if (doStop) { |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 380 | removeWorker(workerCount_); |
Marc Slemko | d466b21 | 2006-07-20 00:04:18 +0000 | [diff] [blame] | 381 | } |
Marc Slemko | fe5ba12e | 2006-07-20 21:16:27 +0000 | [diff] [blame] | 382 | |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 383 | // XXX |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 384 | // should be able to block here for transition to STOPPED since we're no |
| 385 | // using shared_ptrs |
Mark Slee | 7c10eaf | 2007-03-01 02:45:10 +0000 | [diff] [blame] | 386 | |
| 387 | { |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 388 | Synchronized s(monitor_); |
Mark Slee | 7c10eaf | 2007-03-01 02:45:10 +0000 | [diff] [blame] | 389 | state_ = ThreadManager::STOPPED; |
| 390 | } |
| 391 | |
Marc Slemko | d466b21 | 2006-07-20 00:04:18 +0000 | [diff] [blame] | 392 | } |
Mark Slee | 7c10eaf | 2007-03-01 02:45:10 +0000 | [diff] [blame] | 393 | |
Marc Slemko | d466b21 | 2006-07-20 00:04:18 +0000 | [diff] [blame] | 394 | void ThreadManager::Impl::removeWorker(size_t value) { |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 395 | std::set<shared_ptr<Thread> > removedThreads; |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 396 | { |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 397 | Synchronized s(monitor_); |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 398 | if (value > workerMaxCount_) { |
Marc Slemko | fe5ba12e | 2006-07-20 21:16:27 +0000 | [diff] [blame] | 399 | throw InvalidArgumentException(); |
| 400 | } |
| 401 | |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 402 | workerMaxCount_ -= value; |
Marc Slemko | fe5ba12e | 2006-07-20 21:16:27 +0000 | [diff] [blame] | 403 | |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 404 | if (idleCount_ < value) { |
| 405 | for (size_t ix = 0; ix < idleCount_; ix++) { |
David Reiss | 96d2388 | 2007-07-26 21:10:32 +0000 | [diff] [blame] | 406 | monitor_.notify(); |
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 407 | } |
Marc Slemko | fe5ba12e | 2006-07-20 21:16:27 +0000 | [diff] [blame] | 408 | } else { |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 409 | monitor_.notifyAll(); |
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 410 | } |
Marc Slemko | 0e53ccd | 2006-07-17 23:51:05 +0000 | [diff] [blame] | 411 | } |
Marc Slemko | fe5ba12e | 2006-07-20 21:16:27 +0000 | [diff] [blame] | 412 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 413 | { |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 414 | Synchronized s(workerMonitor_); |
Marc Slemko | fe5ba12e | 2006-07-20 21:16:27 +0000 | [diff] [blame] | 415 | |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 416 | while (workerCount_ != workerMaxCount_) { |
| 417 | workerMonitor_.wait(); |
Marc Slemko | fe5ba12e | 2006-07-20 21:16:27 +0000 | [diff] [blame] | 418 | } |
| 419 | |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 420 | for (std::set<shared_ptr<Thread> >::iterator ix = deadWorkers_.begin(); ix != deadWorkers_.end(); ix++) { |
| 421 | workers_.erase(*ix); |
Marc Slemko | a647903 | 2007-06-05 22:20:14 +0000 | [diff] [blame] | 422 | idMap_.erase((*ix)->getId()); |
Marc Slemko | fe5ba12e | 2006-07-20 21:16:27 +0000 | [diff] [blame] | 423 | } |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 424 | |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 425 | deadWorkers_.clear(); |
Marc Slemko | fe5ba12e | 2006-07-20 21:16:27 +0000 | [diff] [blame] | 426 | } |
| 427 | } |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 428 | |
| 429 | bool ThreadManager::Impl::canSleep() { |
Marc Slemko | a647903 | 2007-06-05 22:20:14 +0000 | [diff] [blame] | 430 | const Thread::id_t id = threadFactory_->getCurrentThreadId(); |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 431 | return idMap_.find(id) == idMap_.end(); |
| 432 | } |
| 433 | |
Mark Slee | 9b82d27 | 2007-05-23 05:16:07 +0000 | [diff] [blame] | 434 | void ThreadManager::Impl::add(shared_ptr<Runnable> value, int64_t timeout) { |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 435 | Synchronized s(monitor_); |
Marc Slemko | 0e53ccd | 2006-07-17 23:51:05 +0000 | [diff] [blame] | 436 | |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 437 | if (state_ != ThreadManager::STARTED) { |
Marc Slemko | fe5ba12e | 2006-07-20 21:16:27 +0000 | [diff] [blame] | 438 | throw IllegalStateException(); |
| 439 | } |
Marc Slemko | d466b21 | 2006-07-20 00:04:18 +0000 | [diff] [blame] | 440 | |
Mark Slee | 2782d6d | 2007-05-23 04:55:30 +0000 | [diff] [blame] | 441 | if (pendingTaskCountMax_ > 0 && (tasks_.size() >= pendingTaskCountMax_)) { |
Aditya Agarwal | 4b6ff2d | 2007-12-25 22:58:50 +0000 | [diff] [blame] | 442 | if (canSleep() && timeout >= 0) { |
Mark Slee | 2782d6d | 2007-05-23 04:55:30 +0000 | [diff] [blame] | 443 | while (pendingTaskCountMax_ > 0 && tasks_.size() >= pendingTaskCountMax_) { |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 444 | monitor_.wait(timeout); |
| 445 | } |
| 446 | } else { |
| 447 | throw TooManyPendingTasksException(); |
| 448 | } |
| 449 | } |
| 450 | |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 451 | tasks_.push(shared_ptr<ThreadManager::Task>(new ThreadManager::Task(value))); |
Marc Slemko | 0e53ccd | 2006-07-17 23:51:05 +0000 | [diff] [blame] | 452 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 453 | // If idle thread is available notify it, otherwise all worker threads are |
| 454 | // running and will get around to this task in time. |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 455 | if (idleCount_ > 0) { |
| 456 | monitor_.notify(); |
Marc Slemko | 0e53ccd | 2006-07-17 23:51:05 +0000 | [diff] [blame] | 457 | } |
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 458 | } |
| 459 | |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 460 | void ThreadManager::Impl::remove(shared_ptr<Runnable> task) { |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 461 | Synchronized s(monitor_); |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 462 | if (state_ != ThreadManager::STARTED) { |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 463 | throw IllegalStateException(); |
| 464 | } |
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 465 | } |
| 466 | |
David Reiss | 01fe153 | 2010-03-09 05:19:25 +0000 | [diff] [blame^] | 467 | boost::shared_ptr<Runnable> ThreadManager::Impl::removeNextPending() { |
| 468 | Guard g(mutex_); |
| 469 | if (state_ != ThreadManager::STARTED) { |
| 470 | throw IllegalStateException(); |
| 471 | } |
| 472 | |
| 473 | if (tasks_.empty()) { |
| 474 | return boost::shared_ptr<Runnable>(); |
| 475 | } |
| 476 | |
| 477 | shared_ptr<ThreadManager::Task> task = tasks_.front(); |
| 478 | tasks_.pop(); |
| 479 | |
| 480 | return task->getRunnable(); |
| 481 | } |
| 482 | |
Marc Slemko | d466b21 | 2006-07-20 00:04:18 +0000 | [diff] [blame] | 483 | class SimpleThreadManager : public ThreadManager::Impl { |
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 484 | |
Mark Slee | 2782d6d | 2007-05-23 04:55:30 +0000 | [diff] [blame] | 485 | public: |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 486 | SimpleThreadManager(size_t workerCount=4, size_t pendingTaskCountMax=0) : |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 487 | workerCount_(workerCount), |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 488 | pendingTaskCountMax_(pendingTaskCountMax), |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 489 | firstTime_(true) { |
Marc Slemko | d466b21 | 2006-07-20 00:04:18 +0000 | [diff] [blame] | 490 | } |
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 491 | |
Marc Slemko | fe5ba12e | 2006-07-20 21:16:27 +0000 | [diff] [blame] | 492 | void start() { |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 493 | ThreadManager::Impl::pendingTaskCountMax(pendingTaskCountMax_); |
Marc Slemko | fe5ba12e | 2006-07-20 21:16:27 +0000 | [diff] [blame] | 494 | ThreadManager::Impl::start(); |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 495 | addWorker(workerCount_); |
Marc Slemko | d466b21 | 2006-07-20 00:04:18 +0000 | [diff] [blame] | 496 | } |
| 497 | |
Mark Slee | 2782d6d | 2007-05-23 04:55:30 +0000 | [diff] [blame] | 498 | private: |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 499 | const size_t workerCount_; |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 500 | const size_t pendingTaskCountMax_; |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 501 | bool firstTime_; |
| 502 | Monitor monitor_; |
Marc Slemko | 0e53ccd | 2006-07-17 23:51:05 +0000 | [diff] [blame] | 503 | }; |
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 504 | |
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 505 | |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 506 | shared_ptr<ThreadManager> ThreadManager::newThreadManager() { |
| 507 | return shared_ptr<ThreadManager>(new ThreadManager::Impl()); |
Marc Slemko | d466b21 | 2006-07-20 00:04:18 +0000 | [diff] [blame] | 508 | } |
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 509 | |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 510 | shared_ptr<ThreadManager> ThreadManager::newSimpleThreadManager(size_t count, size_t pendingTaskCountMax) { |
| 511 | return shared_ptr<ThreadManager>(new SimpleThreadManager(count, pendingTaskCountMax)); |
Marc Slemko | d466b21 | 2006-07-20 00:04:18 +0000 | [diff] [blame] | 512 | } |
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 513 | |
T Jake Luciani | b5e6221 | 2009-01-31 22:36:20 +0000 | [diff] [blame] | 514 | }}} // apache::thrift::concurrency |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 515 | |