InspIRCd  3.0
threadengine_win32.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 "config.h"
24 #include "base.h"
25 
26 class Thread;
27 
38 class CoreExport ThreadEngine
39 {
40  public:
43  struct ThreadState
44  {
45  HANDLE handle;
46  };
47 
48  static DWORD WINAPI Entry(void* parameter);
49 
56  void Start(Thread* thread_to_init);
57 
68  void Stop(Thread* thread);
69 };
70 
79 class CoreExport Mutex
80 {
81  private:
82  CRITICAL_SECTION wutex;
83  public:
84  Mutex()
85  {
86  InitializeCriticalSection(&wutex);
87  }
88  void Lock()
89  {
90  EnterCriticalSection(&wutex);
91  }
92  void Unlock()
93  {
94  LeaveCriticalSection(&wutex);
95  }
96  ~Mutex()
97  {
98  DeleteCriticalSection(&wutex);
99  }
100 };
101 
102 class ThreadQueueData : public Mutex
103 {
104  HANDLE event;
105  public:
107  {
108  event = CreateEvent(NULL, false, false, NULL);
109  if (event == NULL)
110  throw CoreException("CreateEvent() failed in ThreadQueueData::ThreadQueueData()!");
111  }
112 
113  ~ThreadQueueData()
114  {
115  CloseHandle(event);
116  }
117 
118  void Wakeup()
119  {
120  PulseEvent(event);
121  }
122 
123  void Wait()
124  {
125  Unlock();
126  WaitForSingleObject(event, INFINITE);
127  Lock();
128  }
129 };
130 
131 class ThreadSignalData
132 {
133  public:
134  int connFD;
136  {
137  connFD = -1;
138  }
139 };
Definition: threadengine_pthread.h:36
Definition: threadengine_pthread.h:106
Definition: threadengine_pthread.h:75
Definition: threadengine_pthread.h:132
Definition: threadengine.h:33
Definition: base.h:180