InspIRCd  3.0
threadengine_win32.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  * Copyright (C) 2014 Attila Molnar <[email protected]>
5  * Copyright (C) 2013 Sadie Powell <[email protected]>
6  * Copyright (C) 2012 Robby <[email protected]>
7  * Copyright (C) 2012 ChrisTX <[email protected]>
8  * Copyright (C) 2009 Daniel De Graaf <[email protected]>
9  * Copyright (C) 2008-2010 Craig Edwards <[email protected]>
10  *
11  * This file is part of InspIRCd. InspIRCd is free software: you can
12  * redistribute it and/or modify it under the terms of the GNU General Public
13  * License as published by the Free Software Foundation, version 2.
14  *
15  * This program is distributed in the hope that it will be useful, but WITHOUT
16  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 
25 #pragma once
26 
27 #include "config.h"
28 #include "base.h"
29 
30 class Thread;
31 
42 class CoreExport ThreadEngine
43 {
44  public:
47  struct ThreadState
48  {
49  HANDLE handle;
50  };
51 
52  static DWORD WINAPI Entry(void* parameter);
53 
60  void Start(Thread* thread_to_init);
61 
72  void Stop(Thread* thread);
73 };
74 
83 class CoreExport Mutex
84 {
85  private:
86  CRITICAL_SECTION wutex;
87  public:
88  Mutex()
89  {
90  InitializeCriticalSection(&wutex);
91  }
92  void Lock()
93  {
94  EnterCriticalSection(&wutex);
95  }
96  void Unlock()
97  {
98  LeaveCriticalSection(&wutex);
99  }
100  ~Mutex()
101  {
102  DeleteCriticalSection(&wutex);
103  }
104 };
105 
106 class ThreadQueueData : public Mutex
107 {
108  HANDLE event;
109  public:
111  {
112  event = CreateEvent(NULL, false, false, NULL);
113  if (event == NULL)
114  throw CoreException("CreateEvent() failed in ThreadQueueData::ThreadQueueData()!");
115  }
116 
117  ~ThreadQueueData()
118  {
119  CloseHandle(event);
120  }
121 
122  void Wakeup()
123  {
124  PulseEvent(event);
125  }
126 
127  void Wait()
128  {
129  Unlock();
130  WaitForSingleObject(event, INFINITE);
131  Lock();
132  }
133 };
134 
135 class ThreadSignalData
136 {
137  public:
138  int connFD;
140  {
141  connFD = -1;
142  }
143 };
Mutex::Lock
void Lock()
Definition: threadengine_pthread.h:91
ThreadQueueData
Definition: threadengine_pthread.h:109
Thread
Definition: threadengine.h:36
Mutex::Unlock
void Unlock()
Definition: threadengine_pthread.h:97
ThreadSignalData
Definition: threadengine_pthread.h:135
ThreadEngine
Definition: threadengine_pthread.h:39
Mutex
Definition: threadengine_pthread.h:78
CoreException
Definition: base.h:185