EventLoopThreadPool.h revision 40161064
140161064SShuo Chen// excerpts from http://code.google.com/p/muduo/
240161064SShuo Chen//
340161064SShuo Chen// Use of this source code is governed by a BSD-style license
440161064SShuo Chen// that can be found in the License file.
540161064SShuo Chen//
640161064SShuo Chen// Author: Shuo Chen (chenshuo at chenshuo dot com)
740161064SShuo Chen
840161064SShuo Chen#ifndef MUDUO_NET_EVENTLOOPTHREADPOOL_H
940161064SShuo Chen#define MUDUO_NET_EVENTLOOPTHREADPOOL_H
1040161064SShuo Chen
1140161064SShuo Chen#include "thread/Condition.h"
1240161064SShuo Chen#include "thread/Mutex.h"
1340161064SShuo Chen#include "thread/Thread.h"
1440161064SShuo Chen
1540161064SShuo Chen
1640161064SShuo Chen#include <vector>
1740161064SShuo Chen#include <boost/function.hpp>
1840161064SShuo Chen#include <boost/noncopyable.hpp>
1940161064SShuo Chen#include <boost/ptr_container/ptr_vector.hpp>
2040161064SShuo Chen
2140161064SShuo Chennamespace muduo
2240161064SShuo Chen{
2340161064SShuo Chen
2440161064SShuo Chenclass EventLoop;
2540161064SShuo Chenclass EventLoopThread;
2640161064SShuo Chen
2740161064SShuo Chenclass EventLoopThreadPool : boost::noncopyable
2840161064SShuo Chen{
2940161064SShuo Chen public:
3040161064SShuo Chen  EventLoopThreadPool(EventLoop* baseLoop);
3140161064SShuo Chen  ~EventLoopThreadPool();
3240161064SShuo Chen  void setThreadNum(int numThreads) { numThreads_ = numThreads; }
3340161064SShuo Chen  void start();
3440161064SShuo Chen  EventLoop* getNextLoop();
3540161064SShuo Chen
3640161064SShuo Chen private:
3740161064SShuo Chen
3840161064SShuo Chen  EventLoop* baseLoop_;
3940161064SShuo Chen  bool started_;
4040161064SShuo Chen  int numThreads_;
4140161064SShuo Chen  int next_;  // always in loop thread
4240161064SShuo Chen  boost::ptr_vector<EventLoopThread> threads_;
4340161064SShuo Chen  std::vector<EventLoop*> loops_;
4440161064SShuo Chen};
4540161064SShuo Chen
4640161064SShuo Chen}
4740161064SShuo Chen
4840161064SShuo Chen#endif  // MUDUO_NET_EVENTLOOPTHREADPOOL_H
49