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