EventLoopThreadPool.h revision 354280cf
1354280cfSShuo Chen// excerpts from http://code.google.com/p/muduo/
2354280cfSShuo Chen//
3354280cfSShuo Chen// Use of this source code is governed by a BSD-style license
4354280cfSShuo Chen// that can be found in the License file.
5354280cfSShuo Chen//
6354280cfSShuo Chen// Author: Shuo Chen (chenshuo at chenshuo dot com)
7354280cfSShuo Chen
8354280cfSShuo Chen#ifndef MUDUO_NET_EVENTLOOPTHREADPOOL_H
9354280cfSShuo Chen#define MUDUO_NET_EVENTLOOPTHREADPOOL_H
10354280cfSShuo Chen
11354280cfSShuo Chen#include "thread/Condition.h"
12354280cfSShuo Chen#include "thread/Mutex.h"
13354280cfSShuo Chen#include "thread/Thread.h"
14354280cfSShuo Chen
15354280cfSShuo Chen
16354280cfSShuo Chen#include <vector>
17354280cfSShuo Chen#include <boost/function.hpp>
18354280cfSShuo Chen#include <boost/noncopyable.hpp>
19354280cfSShuo Chen#include <boost/ptr_container/ptr_vector.hpp>
20354280cfSShuo Chen
21354280cfSShuo Chennamespace muduo
22354280cfSShuo Chen{
23354280cfSShuo Chen
24354280cfSShuo Chenclass EventLoop;
25354280cfSShuo Chenclass EventLoopThread;
26354280cfSShuo Chen
27354280cfSShuo Chenclass EventLoopThreadPool : boost::noncopyable
28354280cfSShuo Chen{
29354280cfSShuo Chen public:
30354280cfSShuo Chen  EventLoopThreadPool(EventLoop* baseLoop);
31354280cfSShuo Chen  ~EventLoopThreadPool();
32354280cfSShuo Chen  void setThreadNum(int numThreads) { numThreads_ = numThreads; }
33354280cfSShuo Chen  void start();
34354280cfSShuo Chen  EventLoop* getNextLoop();
35354280cfSShuo Chen
36354280cfSShuo Chen private:
37354280cfSShuo Chen  EventLoop* baseLoop_;
38354280cfSShuo Chen  bool started_;
39354280cfSShuo Chen  int numThreads_;
40354280cfSShuo Chen  int next_;  // always in loop thread
41354280cfSShuo Chen  boost::ptr_vector<EventLoopThread> threads_;
42354280cfSShuo Chen  std::vector<EventLoop*> loops_;
43354280cfSShuo Chen};
44354280cfSShuo Chen
45354280cfSShuo Chen}
46354280cfSShuo Chen
47354280cfSShuo Chen#endif  // MUDUO_NET_EVENTLOOPTHREADPOOL_H
48