From 411f7693c317d46719306bca60159f3dd3f43f30 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Mon, 9 Jul 2007 23:42:30 +0000 Subject: [PATCH] - removed threader from version tracker - replaced mutexes with critical sections for windows --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401093 --- core/thread/WinThreads.cpp | 37 +++++++++++-------------------------- core/thread/WinThreads.h | 6 ++---- modules.versions | 5 ----- 3 files changed, 13 insertions(+), 35 deletions(-) diff --git a/core/thread/WinThreads.cpp b/core/thread/WinThreads.cpp index c67ffd1e..2180ed30 100644 --- a/core/thread/WinThreads.cpp +++ b/core/thread/WinThreads.cpp @@ -12,6 +12,7 @@ * Version: $Id$ */ +#define _WIN32_WINNT 0x0400 #include "WinThreads.h" #include "ThreadWorker.h" @@ -37,12 +38,7 @@ void WinThreader::ThreadSleep(unsigned int ms) IMutex *WinThreader::MakeMutex() { - HANDLE mutex = CreateMutexA(NULL, FALSE, NULL); - - if (mutex == NULL) - return NULL; - - WinMutex *pMutex = new WinMutex(mutex); + WinMutex *pMutex = new WinMutex(); return pMutex; } @@ -141,40 +137,29 @@ IEventSignal *WinThreader::MakeEventSignal() **** Mutexes **** *****************/ +WinThreader::WinMutex::WinMutex() +{ + InitializeCriticalSection(&m_crit); +} + WinThreader::WinMutex::~WinMutex() { - if (m_mutex) - { - CloseHandle(m_mutex); - m_mutex = NULL; - } + DeleteCriticalSection(&m_crit); } bool WinThreader::WinMutex::TryLock() { - if (!m_mutex) - return false; - - if (WaitForSingleObject(m_mutex, 0) != WAIT_FAILED) - return true; - - return false; + return (TryEnterCriticalSection(&m_crit) != FALSE); } void WinThreader::WinMutex::Lock() { - if (!m_mutex) - return; - - WaitForSingleObject(m_mutex, INFINITE); + EnterCriticalSection(&m_crit); } void WinThreader::WinMutex::Unlock() { - if (!m_mutex) - return; - - ReleaseMutex(m_mutex); + LeaveCriticalSection(&m_crit); } void WinThreader::WinMutex::DestroyThis() diff --git a/core/thread/WinThreads.h b/core/thread/WinThreads.h index de693028..956ccf82 100644 --- a/core/thread/WinThreads.h +++ b/core/thread/WinThreads.h @@ -52,9 +52,7 @@ public: class WinMutex : public IMutex { public: - WinMutex(HANDLE mutex) : m_mutex(mutex) - { - }; + WinMutex(); virtual ~WinMutex(); public: virtual bool TryLock(); @@ -62,7 +60,7 @@ public: virtual void Unlock(); virtual void DestroyThis(); protected: - HANDLE m_mutex; + CRITICAL_SECTION m_crit; }; class WinEvent : public IEventSignal { diff --git a/modules.versions b/modules.versions index 99969384..b7fd0acf 100644 --- a/modules.versions +++ b/modules.versions @@ -23,11 +23,6 @@ folder = extensions/geoip in = svn_version.tpl out = svn_version.h -[threader] -folder = extensions/threader -in = svn_version.tpl -out = svn_version.h - [compiler] folder = sourcepawn/compiler in = svn_version.tpl