InspIRCd  2.0
 All Classes Namespaces Functions Variables Typedefs Enumerations
threadengine_win32.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5  * Copyright (C) 2008 Craig Edwards <craigedwards@brainbox.cc>
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 #ifndef THREADENGINE_WIN32_H
22 #define THREADENGINE_WIN32_H
23 
24 #include "inspircd_config.h"
25 #include "base.h"
26 
27 class Thread;
28 
39 class CoreExport ThreadEngine
40 {
41  public:
42 
43  ThreadEngine();
44 
45  virtual ~ThreadEngine();
46 
47  static DWORD WINAPI Entry(void* parameter);
48 
55  void Start(Thread* thread_to_init);
56 
60  const std::string GetName()
61  {
62  return "windows-thread";
63  }
64 };
65 
66 class CoreExport ThreadData
67 {
68  public:
69  HANDLE handle;
70  void FreeThread(Thread* toFree);
71 };
72 
81 class CoreExport Mutex
82 {
83  private:
84  CRITICAL_SECTION wutex;
85  public:
86  Mutex()
87  {
88  InitializeCriticalSection(&wutex);
89  }
90  void Lock()
91  {
92  EnterCriticalSection(&wutex);
93  }
94  void Unlock()
95  {
96  LeaveCriticalSection(&wutex);
97  }
98  ~Mutex()
99  {
100  DeleteCriticalSection(&wutex);
101  }
102 };
103 
104 class ThreadQueueData
105 {
106  CRITICAL_SECTION mutex;
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  InitializeCriticalSection(&mutex);
115  }
116 
117  ~ThreadQueueData()
118  {
119  CloseHandle(event);
120  DeleteCriticalSection(&mutex);
121  }
122 
123  void Lock()
124  {
125  EnterCriticalSection(&mutex);
126  }
127 
128  void Unlock()
129  {
130  LeaveCriticalSection(&mutex);
131  }
132 
133  void Wakeup()
134  {
135  PulseEvent(event);
136  }
137 
138  void Wait()
139  {
140  LeaveCriticalSection(&mutex);
141  WaitForSingleObject(event, INFINITE);
142  EnterCriticalSection(&mutex);
143  }
144 };
145 
146 class ThreadSignalData
147 {
148  public:
149  int connFD;
151  {
152  connFD = -1;
153  }
154 };
155 
156 #endif
157 
Definition: threadengine_pthread.h:37
Definition: threadengine_pthread.h:112
Definition: threadengine_pthread.h:81
Definition: threadengine_pthread.h:151
Definition: threadengine.h:36
Definition: base.h:181
Definition: threadengine_pthread.h:66
const std::string GetName()
Definition: threadengine_win32.h:60