InspIRCd  3.0
threadengine.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  * Copyright (C) 2009 Daniel De Graaf <[email protected]>
5  * Copyright (C) 2008 Craig Edwards <[email protected]>
6  *
7  * This file is part of InspIRCd. InspIRCd is free software: you can
8  * redistribute it and/or modify it under the terms of the GNU General Public
9  * License as published by the Free Software Foundation, version 2.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 
21 #pragma once
22 
23 #include <vector>
24 #include <string>
25 #include <map>
26 #include "config.h"
27 #include "base.h"
28 
33 class CoreExport Thread
34 {
35  private:
38  bool ExitFlag;
39 
43 
46  friend class ThreadEngine;
47 
48  protected:
52  bool GetExitFlag()
53  {
54  return ExitFlag;
55  }
56  public:
59  Thread() : ExitFlag(false)
60  {
61  }
62 
66  virtual void Run() = 0;
67 
70  virtual void SetExitFlag();
71 
74  void join();
75 };
76 
77 
78 class CoreExport QueuedThread : public Thread
79 {
80  ThreadQueueData queue;
81  protected:
87  void WaitForQueue()
88  {
89  queue.Wait();
90  }
91  public:
94  void LockQueue()
95  {
96  queue.Lock();
97  }
100  void UnlockQueue()
101  {
102  queue.Unlock();
103  }
107  {
108  queue.Wakeup();
109  queue.Unlock();
110  }
111  virtual void SetExitFlag()
112  {
113  queue.Lock();
115  queue.Wakeup();
116  queue.Unlock();
117  }
118 };
119 
120 class CoreExport SocketThread : public Thread
121 {
122  ThreadQueueData queue;
123  ThreadSignalData signal;
124  protected:
131  {
132  queue.Wait();
133  }
134  public:
138  void NotifyParent();
139  SocketThread();
140  virtual ~SocketThread();
143  void LockQueue()
144  {
145  queue.Lock();
146  }
149  void UnlockQueue()
150  {
151  queue.Unlock();
152  }
156  {
157  queue.Wakeup();
158  queue.Unlock();
159  }
160  virtual void SetExitFlag()
161  {
162  queue.Lock();
164  queue.Wakeup();
165  queue.Unlock();
166  }
167 
172  virtual void OnNotify() = 0;
173 };
Definition: threadengine_pthread.h:36
Definition: threadengine.h:120
Definition: threadengine_pthread.h:41
bool GetExitFlag()
Definition: threadengine.h:52
Definition: threadengine.h:78
virtual void SetExitFlag()
Definition: threadengine.cpp:22
virtual void SetExitFlag()
Definition: threadengine.h:111
Definition: threadengine_pthread.h:106
void WaitForQueue()
Definition: threadengine.h:130
Definition: threadengine_pthread.h:132
Definition: threadengine.h:33
void UnlockQueueWakeup()
Definition: threadengine.h:106
void LockQueue()
Definition: threadengine.h:143
void LockQueue()
Definition: threadengine.h:94
void UnlockQueueWakeup()
Definition: threadengine.h:155
void WaitForQueue()
Definition: threadengine.h:87
Thread()
Definition: threadengine.h:59
void UnlockQueue()
Definition: threadengine.h:100
virtual void SetExitFlag()
Definition: threadengine.h:160
void UnlockQueue()
Definition: threadengine.h:149