EventLoop.h revision 460998e0
1460998e0SShuo Chen#ifndef MUDUO_NET_EVENTLOOP_H 2460998e0SShuo Chen#define MUDUO_NET_EVENTLOOP_H 3460998e0SShuo Chen 4460998e0SShuo Chen//#include "../base/Types.h" 5460998e0SShuo Chen#include "thread/Thread.h" 6460998e0SShuo Chen 7460998e0SShuo Chennamespace muduo 8460998e0SShuo Chen{ 9460998e0SShuo Chen 10460998e0SShuo Chenclass EventLoop : boost::noncopyable 11460998e0SShuo Chen{ 12460998e0SShuo Chen public: 13460998e0SShuo Chen 14460998e0SShuo Chen EventLoop(); 15460998e0SShuo Chen ~EventLoop(); 16460998e0SShuo Chen 17460998e0SShuo Chen void loop(); 18460998e0SShuo Chen 19460998e0SShuo Chen void assertInLoopThread() 20460998e0SShuo Chen { 21460998e0SShuo Chen if (!isInLoopThread()) 22460998e0SShuo Chen { 23460998e0SShuo Chen abortNotInLoopThread(); 24460998e0SShuo Chen } 25460998e0SShuo Chen } 26460998e0SShuo Chen 27460998e0SShuo Chen bool isInLoopThread() const { return threadId_ == CurrentThread::tid(); } 28460998e0SShuo Chen 29460998e0SShuo Chen private: 30460998e0SShuo Chen 31460998e0SShuo Chen void abortNotInLoopThread(); 32460998e0SShuo Chen 33460998e0SShuo Chen bool looping_; /* atomic */ 34460998e0SShuo Chen const pid_t threadId_; 35460998e0SShuo Chen 36460998e0SShuo Chen}; 37460998e0SShuo Chen 38460998e0SShuo Chen} 39460998e0SShuo Chen 40460998e0SShuo Chen#endif // MUDUO_NET_EVENTLOOP_H 41