summaryrefslogtreecommitdiff
path: root/src/threadengines/threadengine_win32.cpp
diff options
context:
space:
mode:
authordanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2009-03-23 18:48:32 +0000
committerdanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2009-03-23 18:48:32 +0000
commit7b6eae36661bc798f69b22393b85a4f06d533cf6 (patch)
tree60ac8fd2eb4f3e09530b3b634fce4ad5ce76e21f /src/threadengines/threadengine_win32.cpp
parent7f318a332523869a1abb7125c9fe9d09cc048409 (diff)
ThreadEngine: remove excessive mutex use on thread creation
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11249 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/threadengines/threadengine_win32.cpp')
-rw-r--r--src/threadengines/threadengine_win32.cpp64
1 files changed, 15 insertions, 49 deletions
diff --git a/src/threadengines/threadengine_win32.cpp b/src/threadengines/threadengine_win32.cpp
index 1a1755f15..b32dd2441 100644
--- a/src/threadengines/threadengine_win32.cpp
+++ b/src/threadengines/threadengine_win32.cpp
@@ -14,75 +14,41 @@
#include "inspircd.h"
#include "threadengines/threadengine_win32.h"
-CRITICAL_SECTION MyMutex;
-
Win32ThreadEngine::Win32ThreadEngine(InspIRCd* Instance) : ThreadEngine(Instance)
{
- InitializeCriticalSection(&MyMutex);
}
-void Win32ThreadEngine::Create(Thread* thread_to_init)
+void Win32ThreadEngine::Create(Thread* thread)
{
- Mutex(true);
- HANDLE* MyThread = new HANDLE;
+ Win32ThreadData* data = new Win32ThreadData;
+ thread->state = data;
+
DWORD ThreadId = 0;
+ data->handle = CreateThread(NULL,0,Win32ThreadEngine::Entry,thread,0,&ThreadId);
- if (NULL == (*MyThread = CreateThread(NULL,0,Win32ThreadEngine::Entry,this,0,&ThreadId)))
+ if (data->handle == NULL)
{
- delete MyThread;
- Mutex(false);
+ thread->state = NULL;
+ delete data;
throw CoreException(std::string("Unable to create new Win32ThreadEngine: ") + dlerror());
}
-
- NewThread = thread_to_init;
- NewThread->Creator = this;
- NewThread->Extend("winthread", MyThread);
- Mutex(false);
-
- while (NewThread)
- SleepEx(100, false);
}
Win32ThreadEngine::~Win32ThreadEngine()
{
- DeleteCriticalSection(&MyMutex);
-}
-
-void Win32ThreadEngine::Run()
-{
- Mutex(true);
- Thread* nt = NewThread;
- NewThread = NULL;
- Mutex(false);
- nt->Run();
-}
-
-bool Win32ThreadEngine::Mutex(bool enable)
-{
- if (enable)
- EnterCriticalSection(&MyMutex);
- else
- LeaveCriticalSection(&MyMutex);
-
- return false;
}
DWORD WINAPI Win32ThreadEngine::Entry(void* parameter)
{
- ThreadEngine * pt = (ThreadEngine*)parameter;
+ Thread* pt = reinterpret_cast<Thread*>(parameter);
pt->Run();
return 0;
}
-void Win32ThreadEngine::FreeThread(Thread* thread)
+void Win32ThreadData::FreeThread(Thread* thread)
{
- HANDLE* winthread = NULL;
- if (thread->GetExt("winthread", winthread))
- {
- thread->SetExitFlag();
- WaitForSingleObject(*winthread,INFINITE);
- delete winthread;
- }
+ thread->SetExitFlag();
+ WaitForSingleObject(handle,INFINITE);
}
@@ -92,10 +58,10 @@ MutexFactory::MutexFactory(InspIRCd* Instance) : ServerInstance(Instance)
Mutex* MutexFactory::CreateMutex()
{
- return new Win32Mutex(this->ServerInstance);
+ return new Win32Mutex();
}
-Win32Mutex::Win32Mutex(InspIRCd* Instance) : Mutex(Instance)
+Win32Mutex::Win32Mutex() : Mutex()
{
InitializeCriticalSection(&wutex);
}
@@ -111,4 +77,4 @@ void Win32Mutex::Enable(bool enable)
EnterCriticalSection(&wutex);
else
LeaveCriticalSection(&wutex);
-} \ No newline at end of file
+}