EventLoop.h revision 4b7a333e
14b7a333eSShuo Chen// excerpts from http://code.google.com/p/muduo/
24b7a333eSShuo Chen//
34b7a333eSShuo Chen// Use of this source code is governed by a BSD-style license
44b7a333eSShuo Chen// that can be found in the License file.
54b7a333eSShuo Chen//
64b7a333eSShuo Chen// Author: Shuo Chen (chenshuo at chenshuo dot com)
74b7a333eSShuo Chen
8460998e0SShuo Chen#ifndef MUDUO_NET_EVENTLOOP_H
9460998e0SShuo Chen#define MUDUO_NET_EVENTLOOP_H
10460998e0SShuo Chen
11460998e0SShuo Chen#include "thread/Thread.h"
12460998e0SShuo Chen
13460998e0SShuo Chennamespace muduo
14460998e0SShuo Chen{
15460998e0SShuo Chen
16460998e0SShuo Chenclass EventLoop : boost::noncopyable
17460998e0SShuo Chen{
18460998e0SShuo Chen public:
19460998e0SShuo Chen
20460998e0SShuo Chen  EventLoop();
21460998e0SShuo Chen  ~EventLoop();
22460998e0SShuo Chen
23460998e0SShuo Chen  void loop();
24460998e0SShuo Chen
25460998e0SShuo Chen  void assertInLoopThread()
26460998e0SShuo Chen  {
27460998e0SShuo Chen    if (!isInLoopThread())
28460998e0SShuo Chen    {
29460998e0SShuo Chen      abortNotInLoopThread();
30460998e0SShuo Chen    }
31460998e0SShuo Chen  }
32460998e0SShuo Chen
33460998e0SShuo Chen  bool isInLoopThread() const { return threadId_ == CurrentThread::tid(); }
34460998e0SShuo Chen
35460998e0SShuo Chen private:
36460998e0SShuo Chen
37460998e0SShuo Chen  void abortNotInLoopThread();
38460998e0SShuo Chen
39460998e0SShuo Chen  bool looping_; /* atomic */
40460998e0SShuo Chen  const pid_t threadId_;
41460998e0SShuo Chen
42460998e0SShuo Chen};
43460998e0SShuo Chen
44460998e0SShuo Chen}
45460998e0SShuo Chen
46460998e0SShuo Chen#endif  // MUDUO_NET_EVENTLOOP_H
47