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 "base.h"
28 
29 class Thread;
30 
41 class CoreExport ThreadEngine
42 {
43  public:
46  struct ThreadState
47  {
48  HANDLE handle;
49  };
50 
51  static DWORD WINAPI Entry(void* parameter);
52 
59  void Start(Thread* thread_to_init);
60 
71  void Stop(Thread* thread);
72 };
73 
82 class CoreExport Mutex
83 {
84  private:
85  CRITICAL_SECTION wutex;
86  public:
87  Mutex()
88  {
89  InitializeCriticalSection(&wutex);
90  }
91  void Lock()
92  {
93  EnterCriticalSection(&wutex);
94  }
95  void Unlock()
96  {
97  LeaveCriticalSection(&wutex);
98  }
99  ~Mutex()
100  {
101  DeleteCriticalSection(&wutex);
102  }
103 };
104 
105 class ThreadQueueData : public Mutex
106 {
107  HANDLE event;
108  public:
110  {
111  event = CreateEvent(NULL, false, false, NULL);
112  if (event == NULL)
113  throw CoreException("CreateEvent() failed in ThreadQueueData::ThreadQueueData()!");
114  }
115 
116  ~ThreadQueueData()
117  {
118  CloseHandle(event);
119  }
120 
121  void Wakeup()
122  {
123  PulseEvent(event);
124  }
125 
126  void Wait()
127  {
128  Unlock();
129  WaitForSingleObject(event, INFINITE);
130  Lock();
131  }
132 };
133 
134 class ThreadSignalData
135 {
136  public:
137  int connFD;
139  {
140  connFD = -1;
141  }
142 };
Definition: base.h:185
Definition: threadengine_pthread.h:80
void Unlock()
Definition: threadengine_pthread.h:98
void Lock()
Definition: threadengine_pthread.h:92
Definition: threadengine_pthread.h:41
void Start(Thread *thread_to_init)
void Stop(Thread *thread)
Definition: threadengine.h:33
Definition: threadengine_pthread.h:111
Definition: threadengine_pthread.h:137