1// excerpts from http://code.google.com/p/muduo/ 2// 3// Use of this source code is governed by a BSD-style license 4// that can be found in the License file. 5// 6// Author: Shuo Chen (chenshuo at chenshuo dot com) 7 8#ifndef MUDUO_NET_EVENTLOOPTHREADPOOL_H 9#define MUDUO_NET_EVENTLOOPTHREADPOOL_H 10 11#include "thread/Condition.h" 12#include "thread/Mutex.h" 13#include "thread/Thread.h" 14 15 16#include <vector> 17#include <boost/function.hpp> 18#include <boost/noncopyable.hpp> 19#include <boost/ptr_container/ptr_vector.hpp> 20 21namespace muduo 22{ 23 24class EventLoop; 25class EventLoopThread; 26 27class EventLoopThreadPool : boost::noncopyable 28{ 29 public: 30 EventLoopThreadPool(EventLoop* baseLoop); 31 ~EventLoopThreadPool(); 32 void setThreadNum(int numThreads) { numThreads_ = numThreads; } 33 void start(); 34 EventLoop* getNextLoop(); 35 36 private: 37 EventLoop* baseLoop_; 38 bool started_; 39 int numThreads_; 40 int next_; // always in loop thread 41 boost::ptr_vector<EventLoopThread> threads_; 42 std::vector<EventLoop*> loops_; 43}; 44 45} 46 47#endif // MUDUO_NET_EVENTLOOPTHREADPOOL_H 48