summaryrefslogtreecommitdiff
path: root/src/threadengines/threadengine_win32.cpp
blob: b32dd244133b3ee0f8cab925c075a8888682b217 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*       +------------------------------------+
 *       | Inspire Internet Relay Chat Daemon |
 *       +------------------------------------+
 *
 *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
 * See: http://wiki.inspircd.org/Credits
 *
 * This program is free but copyrighted software; see
 *	    the file COPYING for details.
 *
 * ---------------------------------------------------
 */

#include "inspircd.h"
#include "threadengines/threadengine_win32.h"

Win32ThreadEngine::Win32ThreadEngine(InspIRCd* Instance) : ThreadEngine(Instance)
{
}

void Win32ThreadEngine::Create(Thread* thread)
{
	Win32ThreadData* data = new Win32ThreadData;
	thread->state = data;

	DWORD ThreadId = 0;
	data->handle = CreateThread(NULL,0,Win32ThreadEngine::Entry,thread,0,&ThreadId);

	if (data->handle == NULL)
	{
		thread->state = NULL;
		delete data;
		throw CoreException(std::string("Unable to create new Win32ThreadEngine: ") + dlerror());
	}
}

Win32ThreadEngine::~Win32ThreadEngine()
{
}

DWORD WINAPI Win32ThreadEngine::Entry(void* parameter)
{
	Thread* pt = reinterpret_cast<Thread*>(parameter);
	pt->Run();
	return 0;
}

void Win32ThreadData::FreeThread(Thread* thread)
{
	thread->SetExitFlag();
	WaitForSingleObject(handle,INFINITE);
}


MutexFactory::MutexFactory(InspIRCd* Instance) : ServerInstance(Instance)
{
}

Mutex* MutexFactory::CreateMutex()
{
	return new Win32Mutex();
}

Win32Mutex::Win32Mutex() : Mutex()
{
	InitializeCriticalSection(&wutex);
}

Win32Mutex::~Win32Mutex()
{
	DeleteCriticalSection(&wutex);
}

void Win32Mutex::Enable(bool enable)
{
	if (enable)
		EnterCriticalSection(&wutex);
	else
		LeaveCriticalSection(&wutex);
}