EventLoop.h revision c903e3e8
1c903e3e8SShuo Chen#ifndef MUDUO_NET_EVENTLOOP_H 2c903e3e8SShuo Chen#define MUDUO_NET_EVENTLOOP_H 3c903e3e8SShuo Chen 4c903e3e8SShuo Chen//#include "../base/Types.h" 5c903e3e8SShuo Chen#include "thread/Thread.h" 6c903e3e8SShuo Chen 7c903e3e8SShuo Chennamespace muduo 8c903e3e8SShuo Chen{ 9c903e3e8SShuo Chen 10c903e3e8SShuo Chenclass EventLoop : boost::noncopyable 11c903e3e8SShuo Chen{ 12c903e3e8SShuo Chen public: 13c903e3e8SShuo Chen 14c903e3e8SShuo Chen EventLoop(); 15c903e3e8SShuo Chen ~EventLoop(); 16c903e3e8SShuo Chen 17c903e3e8SShuo Chen void loop(); 18c903e3e8SShuo Chen 19c903e3e8SShuo Chen void assertInLoopThread() 20c903e3e8SShuo Chen { 21c903e3e8SShuo Chen if (!isInLoopThread()) 22c903e3e8SShuo Chen { 23c903e3e8SShuo Chen abortNotInLoopThread(); 24c903e3e8SShuo Chen } 25c903e3e8SShuo Chen } 26c903e3e8SShuo Chen 27c903e3e8SShuo Chen bool isInLoopThread() const { return threadId_ == CurrentThread::tid(); } 28c903e3e8SShuo Chen 29c903e3e8SShuo Chen private: 30c903e3e8SShuo Chen 31c903e3e8SShuo Chen void abortNotInLoopThread(); 32c903e3e8SShuo Chen 33c903e3e8SShuo Chen bool looping_; /* atomic */ 34c903e3e8SShuo Chen const pid_t threadId_; 35c903e3e8SShuo Chen 36c903e3e8SShuo Chen}; 37c903e3e8SShuo Chen 38c903e3e8SShuo Chen} 39c903e3e8SShuo Chen 40c903e3e8SShuo Chen#endif // MUDUO_NET_EVENTLOOP_H 41