1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
15 #include "threadengines/threadengine_win32.h"
17 CRITICAL_SECTION MyMutex;
19 Win32ThreadEngine::Win32ThreadEngine(InspIRCd* Instance) : ThreadEngine(Instance)
21 InitializeCriticalSection(&MyMutex);
24 void Win32ThreadEngine::Create(Thread* thread_to_init)
27 HANDLE* MyThread = new HANDLE;
30 if (NULL == (*MyThread = CreateThread(NULL,0,Win32ThreadEngine::Entry,this,0,&ThreadId)))
34 throw CoreException(std::string("Unable to create new Win32ThreadEngine: ") + dlerror());
37 NewThread = thread_to_init;
38 NewThread->Creator = this;
39 NewThread->Extend("winthread", MyThread);
46 Win32ThreadEngine::~Win32ThreadEngine()
48 DeleteCriticalSection(&MyMutex);
51 void Win32ThreadEngine::Run()
54 Thread* nt = NewThread;
60 bool Win32ThreadEngine::Mutex(bool enable)
63 EnterCriticalSection(&MyMutex);
65 LeaveCriticalSection(&MyMutex);
70 DWORD WINAPI Win32ThreadEngine::Entry(void* parameter)
72 ThreadEngine * pt = (ThreadEngine*)parameter;
77 void Win32ThreadEngine::FreeThread(Thread* thread)
79 HANDLE* winthread = NULL;
80 if (thread->GetExt("winthread", winthread))
82 thread->SetExitFlag();
83 WaitForSingleObject(*winthread,INFINITE);
89 MutexFactory::MutexFactory(InspIRCd* Instance) : ServerInstance(Instance)
93 Mutex* MutexFactory::CreateMutex()
95 return new Win32Mutex(this->ServerInstance);
98 Win32Mutex::Win32Mutex(InspIRCd* Instance) : Mutex(Instance)
100 InitializeCriticalSection(&wutex);
103 Win32Mutex::~Win32Mutex()
105 DeleteCriticalSection(&wutex);
108 void Win32Mutex::Enable(bool enable)
111 EnterCriticalSection(&wutex);
113 LeaveCriticalSection(&wutex);