// excerpts from http://code.google.com/p/muduo/ // // Use of this source code is governed by a BSD-style license // that can be found in the License file. // // Author: Shuo Chen (giantchen at gmail dot com) #ifndef MUDUO_BASE_THREADPOOL_H #define MUDUO_BASE_THREADPOOL_H #include "Condition.h" #include "Mutex.h" #include "Thread.h" #include #include #include #include namespace muduo { class ThreadPool : boost::noncopyable { public: typedef boost::function Task; explicit ThreadPool(const std::string& name = std::string()); ~ThreadPool(); void start(int numThreads); void stop(); void run(const Task& f); private: void runInThread(); Task take(); MutexLock mutex_; Condition cond_; std::string name_; boost::ptr_vector threads_; std::deque queue_; bool running_; }; } #endif