From 5e1cbccebf9a796782402038453833fa33b9917f Mon Sep 17 00:00:00 2001 From: Piotr Caban Date: Fri, 2 Nov 2012 20:06:08 +0100 Subject: [PATCH] msvcp90: Use critical sections in mutex object. --- dlls/msvcp100/misc.c | 18 ++++++++++++++---- dlls/msvcp100/msvcp.h | 2 +- dlls/msvcp60/misc.c | 16 ++++++++++++---- dlls/msvcp71/misc.c | 18 ++++++++++++++---- dlls/msvcp71/msvcp.h | 2 +- dlls/msvcp90/misc.c | 18 ++++++++++++++---- dlls/msvcp90/msvcp90.h | 2 +- 7 files changed, 57 insertions(+), 19 deletions(-) diff --git a/dlls/msvcp100/misc.c b/dlls/msvcp100/misc.c index 40f9fede990..5854c5e94fa 100644 --- a/dlls/msvcp100/misc.c +++ b/dlls/msvcp100/misc.c @@ -33,7 +33,15 @@ WINE_DEFAULT_DEBUG_CHANNEL(msvcp); DEFINE_THISCALL_WRAPPER(mutex_ctor, 4) mutex* __thiscall mutex_ctor(mutex *this) { - this->mutex = CreateMutexW(NULL, FALSE, NULL); + CRITICAL_SECTION *cs = MSVCRT_operator_new(sizeof(*cs)); + if(!cs) { + ERR("Out of memory\n"); + throw_exception(EXCEPTION_BAD_ALLOC, NULL); + } + + InitializeCriticalSection(cs); + cs->DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": _Mutex critical section"); + this->mutex = cs; return this; } @@ -42,7 +50,9 @@ mutex* __thiscall mutex_ctor(mutex *this) DEFINE_THISCALL_WRAPPER(mutex_dtor, 4) void __thiscall mutex_dtor(mutex *this) { - CloseHandle(this->mutex); + ((CRITICAL_SECTION*)this->mutex)->DebugInfo->Spare[0] = 0; + DeleteCriticalSection(this->mutex); + MSVCRT_operator_delete(this->mutex); } /* ?_Lock@_Mutex@std@@QAEXXZ */ @@ -50,7 +60,7 @@ void __thiscall mutex_dtor(mutex *this) DEFINE_THISCALL_WRAPPER(mutex_lock, 4) void __thiscall mutex_lock(mutex *this) { - WaitForSingleObject(this->mutex, INFINITE); + EnterCriticalSection(this->mutex); } /* ?_Unlock@_Mutex@std@@QAEXXZ */ @@ -58,7 +68,7 @@ void __thiscall mutex_lock(mutex *this) DEFINE_THISCALL_WRAPPER(mutex_unlock, 4) void __thiscall mutex_unlock(mutex *this) { - ReleaseMutex(this->mutex); + LeaveCriticalSection(this->mutex); } /* ?_Mutex_Lock@_Mutex@std@@CAXPAV12@@Z */ diff --git a/dlls/msvcp100/msvcp.h b/dlls/msvcp100/msvcp.h index 08c34711e4b..de8d9e313a1 100644 --- a/dlls/msvcp100/msvcp.h +++ b/dlls/msvcp100/msvcp.h @@ -205,7 +205,7 @@ void __thiscall _Lockit_dtor(_Lockit*); /* class mutex */ typedef struct { - void *mutex; + void *mutex; } mutex; mutex* __thiscall mutex_ctor(mutex*); diff --git a/dlls/msvcp60/misc.c b/dlls/msvcp60/misc.c index f0796a4b31b..9c840b71a86 100644 --- a/dlls/msvcp60/misc.c +++ b/dlls/msvcp60/misc.c @@ -31,7 +31,13 @@ /* ??0_Mutex@std@@QEAA@XZ */ mutex* mutex_ctor(mutex *this) { - this->mutex = CreateMutexW(NULL, FALSE, NULL); + CRITICAL_SECTION *cs = MSVCRT_operator_new(sizeof(*cs)); + if(!cs) + throw_exception(EXCEPTION_BAD_ALLOC, NULL); + + InitializeCriticalSection(cs); + cs->DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": _Mutex critical section"); + this->mutex = cs; return this; } @@ -39,21 +45,23 @@ mutex* mutex_ctor(mutex *this) /* ??1_Mutex@std@@QEAA@XZ */ void mutex_dtor(mutex *this) { - CloseHandle(this->mutex); + ((CRITICAL_SECTION*)this->mutex)->DebugInfo->Spare[0] = 0; + DeleteCriticalSection(this->mutex); + MSVCRT_operator_delete(this->mutex); } /* ?_Lock@_Mutex@std@@QAEXXZ */ /* ?_Lock@_Mutex@std@@QEAAXXZ */ void mutex_lock(mutex *this) { - WaitForSingleObject(this->mutex, INFINITE); + EnterCriticalSection(this->mutex); } /* ?_Unlock@_Mutex@std@@QAEXXZ */ /* ?_Unlock@_Mutex@std@@QEAAXXZ */ void mutex_unlock(mutex *this) { - ReleaseMutex(this->mutex); + LeaveCriticalSection(this->mutex); } static CRITICAL_SECTION lockit_cs; diff --git a/dlls/msvcp71/misc.c b/dlls/msvcp71/misc.c index 8615a51aecb..21ca9295ea6 100644 --- a/dlls/msvcp71/misc.c +++ b/dlls/msvcp71/misc.c @@ -33,7 +33,15 @@ WINE_DEFAULT_DEBUG_CHANNEL(msvcp); DEFINE_THISCALL_WRAPPER(mutex_ctor, 4) mutex* __thiscall mutex_ctor(mutex *this) { - this->mutex = CreateMutexW(NULL, FALSE, NULL); + CRITICAL_SECTION *cs = MSVCRT_operator_new(sizeof(*cs)); + if(!cs) { + ERR("Out of memory\n"); + throw_exception(EXCEPTION_BAD_ALLOC, NULL); + } + + InitializeCriticalSection(cs); + cs->DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": _Mutex critical section"); + this->mutex = cs; return this; } @@ -42,7 +50,9 @@ mutex* __thiscall mutex_ctor(mutex *this) DEFINE_THISCALL_WRAPPER(mutex_dtor, 4) void __thiscall mutex_dtor(mutex *this) { - CloseHandle(this->mutex); + ((CRITICAL_SECTION*)this->mutex)->DebugInfo->Spare[0] = 0; + DeleteCriticalSection(this->mutex); + MSVCRT_operator_delete(this->mutex); } /* ?_Lock@_Mutex@std@@QAEXXZ */ @@ -50,7 +60,7 @@ void __thiscall mutex_dtor(mutex *this) DEFINE_THISCALL_WRAPPER(mutex_lock, 4) void __thiscall mutex_lock(mutex *this) { - WaitForSingleObject(this->mutex, INFINITE); + EnterCriticalSection(this->mutex); } /* ?_Unlock@_Mutex@std@@QAEXXZ */ @@ -58,7 +68,7 @@ void __thiscall mutex_lock(mutex *this) DEFINE_THISCALL_WRAPPER(mutex_unlock, 4) void __thiscall mutex_unlock(mutex *this) { - ReleaseMutex(this->mutex); + LeaveCriticalSection(this->mutex); } static CRITICAL_SECTION lockit_cs[_MAX_LOCK]; diff --git a/dlls/msvcp71/msvcp.h b/dlls/msvcp71/msvcp.h index aea85cc1a2d..6f9e266f4f2 100644 --- a/dlls/msvcp71/msvcp.h +++ b/dlls/msvcp71/msvcp.h @@ -201,7 +201,7 @@ void __thiscall _Lockit_dtor(_Lockit*); /* class mutex */ typedef struct { - void *mutex; + void *mutex; } mutex; mutex* __thiscall mutex_ctor(mutex*); diff --git a/dlls/msvcp90/misc.c b/dlls/msvcp90/misc.c index c8c41226e34..8b3df210026 100644 --- a/dlls/msvcp90/misc.c +++ b/dlls/msvcp90/misc.c @@ -33,7 +33,15 @@ WINE_DEFAULT_DEBUG_CHANNEL(msvcp); DEFINE_THISCALL_WRAPPER(mutex_ctor, 4) mutex* __thiscall mutex_ctor(mutex *this) { - this->mutex = CreateMutexW(NULL, FALSE, NULL); + CRITICAL_SECTION *cs = MSVCRT_operator_new(sizeof(*cs)); + if(!cs) { + ERR("Out of memory\n"); + throw_exception(EXCEPTION_BAD_ALLOC, NULL); + } + + InitializeCriticalSection(cs); + cs->DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": _Mutex critical section"); + this->mutex = cs; return this; } @@ -42,7 +50,9 @@ mutex* __thiscall mutex_ctor(mutex *this) DEFINE_THISCALL_WRAPPER(mutex_dtor, 4) void __thiscall mutex_dtor(mutex *this) { - CloseHandle(this->mutex); + ((CRITICAL_SECTION*)this->mutex)->DebugInfo->Spare[0] = 0; + DeleteCriticalSection(this->mutex); + MSVCRT_operator_delete(this->mutex); } /* ?_Lock@_Mutex@std@@QAEXXZ */ @@ -50,7 +60,7 @@ void __thiscall mutex_dtor(mutex *this) DEFINE_THISCALL_WRAPPER(mutex_lock, 4) void __thiscall mutex_lock(mutex *this) { - WaitForSingleObject(this->mutex, INFINITE); + EnterCriticalSection(this->mutex); } /* ?_Unlock@_Mutex@std@@QAEXXZ */ @@ -58,7 +68,7 @@ void __thiscall mutex_lock(mutex *this) DEFINE_THISCALL_WRAPPER(mutex_unlock, 4) void __thiscall mutex_unlock(mutex *this) { - ReleaseMutex(this->mutex); + LeaveCriticalSection(this->mutex); } /* ?_Mutex_Lock@_Mutex@std@@CAXPAV12@@Z */ diff --git a/dlls/msvcp90/msvcp90.h b/dlls/msvcp90/msvcp90.h index 1108591b8a0..2496ebcd83a 100644 --- a/dlls/msvcp90/msvcp90.h +++ b/dlls/msvcp90/msvcp90.h @@ -201,7 +201,7 @@ void __thiscall _Lockit_dtor(_Lockit*); /* class mutex */ typedef struct { - void *mutex; + void *mutex; } mutex; mutex* __thiscall mutex_ctor(mutex*);