Anope IRC Services  Version 2.0
threadengine.h
Go to the documentation of this file.
1 /*
2  *
3  * (C) 2003-2014 Anope Team
4  * Contact us at team@anope.org
5  *
6  * Please read COPYING and README for further details.
7  *
8  * Based on the original code of Epona by Lara.
9  * Based on the original code of Services by Andy Church.
10  *
11  */
12 
13 #ifndef THREADENGINE_H
14 #define THREADENGINE_H
15 
16 #include "sockets.h"
17 #include "extensible.h"
18 
19 class CoreExport Thread : public Pipe, public Extensible
20 {
21  private:
22  /* Set to true to tell the thread to finish and we are waiting for it */
23  bool exit;
24 
25  public:
26  /* Handle for this thread */
28 
31  Thread();
32 
35  virtual ~Thread();
36 
39  void Join();
40 
43  void SetExitState();
44 
47  void Exit();
48 
51  void Start();
52 
56  bool GetExitState() const;
57 
60  void OnNotify();
61 
64  virtual void Run() = 0;
65 };
66 
68 {
69  protected:
70  /* A mutex, used to keep threads in sync */
72 
73  public:
76  Mutex();
77 
80  ~Mutex();
81 
84  void Lock();
85 
88  void Unlock();
89 
94  bool TryLock();
95 };
96 
97 class CoreExport Condition : public Mutex
98 {
99  private:
100  /* A condition */
102 
103  public:
106  Condition();
107 
110  ~Condition();
111 
114  void Wakeup();
115 
118  void Wait();
119 };
120 
121 #endif // THREADENGINE_H
CRITICAL_SECTION pthread_mutex_t
Definition: pthread.h:11
Definition: sockets.h:454
pthread_mutex_t mutex
Definition: threadengine.h:71
pthread_cond_t cond
Definition: threadengine.h:101
pthread_t handle
Definition: threadengine.h:27
#define CoreExport
Definition: services.h:62
HANDLE pthread_cond_t
Definition: pthread.h:12
bool exit
Definition: threadengine.h:23
HANDLE pthread_t
Definition: pthread.h:10
virtual void OnNotify()=0