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