core/thread/WinThreads.cpp
changeset 1087 a7ee64117faf
parent 1084 241c1b9b4048
child 1090 5c54e353c019
     1.1 --- a/core/thread/WinThreads.cpp	Mon Jul 09 22:36:59 2007 +0000
     1.2 +++ b/core/thread/WinThreads.cpp	Mon Jul 09 23:42:30 2007 +0000
     1.3 @@ -12,6 +12,7 @@
     1.4   * Version: $Id$
     1.5   */
     1.6  
     1.7 +#define _WIN32_WINNT 0x0400
     1.8  #include "WinThreads.h"
     1.9  #include "ThreadWorker.h"
    1.10  
    1.11 @@ -37,12 +38,7 @@
    1.12  
    1.13  IMutex *WinThreader::MakeMutex()
    1.14  {
    1.15 -	HANDLE mutex = CreateMutexA(NULL, FALSE, NULL);
    1.16 -
    1.17 -	if (mutex == NULL)
    1.18 -		return NULL;
    1.19 -
    1.20 -	WinMutex *pMutex = new WinMutex(mutex);
    1.21 +	WinMutex *pMutex = new WinMutex();
    1.22  
    1.23  	return pMutex;
    1.24  }
    1.25 @@ -141,40 +137,29 @@
    1.26   **** Mutexes ****
    1.27   *****************/
    1.28  
    1.29 +WinThreader::WinMutex::WinMutex()
    1.30 +{
    1.31 +	InitializeCriticalSection(&m_crit);
    1.32 +}
    1.33 +
    1.34  WinThreader::WinMutex::~WinMutex()
    1.35  {
    1.36 -	if (m_mutex)
    1.37 -	{
    1.38 -		CloseHandle(m_mutex);
    1.39 -		m_mutex = NULL;
    1.40 -	}
    1.41 +	DeleteCriticalSection(&m_crit);
    1.42  }
    1.43  
    1.44  bool WinThreader::WinMutex::TryLock()
    1.45  {
    1.46 -	if (!m_mutex)
    1.47 -		return false;
    1.48 -
    1.49 -	if (WaitForSingleObject(m_mutex, 0) != WAIT_FAILED)
    1.50 -		return true;
    1.51 -
    1.52 -	return false;
    1.53 +	return (TryEnterCriticalSection(&m_crit) != FALSE);
    1.54  }
    1.55  
    1.56  void WinThreader::WinMutex::Lock()
    1.57  {
    1.58 -	if (!m_mutex)
    1.59 -		return;
    1.60 -
    1.61 -	WaitForSingleObject(m_mutex, INFINITE);
    1.62 +	EnterCriticalSection(&m_crit);
    1.63  }
    1.64  
    1.65  void WinThreader::WinMutex::Unlock()
    1.66  {
    1.67 -	if (!m_mutex)
    1.68 -		return;
    1.69 -
    1.70 -	ReleaseMutex(m_mutex);
    1.71 +	LeaveCriticalSection(&m_crit);
    1.72  }
    1.73  
    1.74  void WinThreader::WinMutex::DestroyThis()