Commit 5e1cbcce authored by Piotr Caban's avatar Piotr Caban Committed by Alexandre Julliard

msvcp90: Use critical sections in mutex object.

parent 0280c5fb
...@@ -33,7 +33,15 @@ WINE_DEFAULT_DEBUG_CHANNEL(msvcp); ...@@ -33,7 +33,15 @@ WINE_DEFAULT_DEBUG_CHANNEL(msvcp);
DEFINE_THISCALL_WRAPPER(mutex_ctor, 4) DEFINE_THISCALL_WRAPPER(mutex_ctor, 4)
mutex* __thiscall mutex_ctor(mutex *this) 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; return this;
} }
...@@ -42,7 +50,9 @@ mutex* __thiscall mutex_ctor(mutex *this) ...@@ -42,7 +50,9 @@ mutex* __thiscall mutex_ctor(mutex *this)
DEFINE_THISCALL_WRAPPER(mutex_dtor, 4) DEFINE_THISCALL_WRAPPER(mutex_dtor, 4)
void __thiscall mutex_dtor(mutex *this) 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 */ /* ?_Lock@_Mutex@std@@QAEXXZ */
...@@ -50,7 +60,7 @@ void __thiscall mutex_dtor(mutex *this) ...@@ -50,7 +60,7 @@ void __thiscall mutex_dtor(mutex *this)
DEFINE_THISCALL_WRAPPER(mutex_lock, 4) DEFINE_THISCALL_WRAPPER(mutex_lock, 4)
void __thiscall mutex_lock(mutex *this) void __thiscall mutex_lock(mutex *this)
{ {
WaitForSingleObject(this->mutex, INFINITE); EnterCriticalSection(this->mutex);
} }
/* ?_Unlock@_Mutex@std@@QAEXXZ */ /* ?_Unlock@_Mutex@std@@QAEXXZ */
...@@ -58,7 +68,7 @@ void __thiscall mutex_lock(mutex *this) ...@@ -58,7 +68,7 @@ void __thiscall mutex_lock(mutex *this)
DEFINE_THISCALL_WRAPPER(mutex_unlock, 4) DEFINE_THISCALL_WRAPPER(mutex_unlock, 4)
void __thiscall mutex_unlock(mutex *this) void __thiscall mutex_unlock(mutex *this)
{ {
ReleaseMutex(this->mutex); LeaveCriticalSection(this->mutex);
} }
/* ?_Mutex_Lock@_Mutex@std@@CAXPAV12@@Z */ /* ?_Mutex_Lock@_Mutex@std@@CAXPAV12@@Z */
......
...@@ -205,7 +205,7 @@ void __thiscall _Lockit_dtor(_Lockit*); ...@@ -205,7 +205,7 @@ void __thiscall _Lockit_dtor(_Lockit*);
/* class mutex */ /* class mutex */
typedef struct { typedef struct {
void *mutex; void *mutex;
} mutex; } mutex;
mutex* __thiscall mutex_ctor(mutex*); mutex* __thiscall mutex_ctor(mutex*);
......
...@@ -31,7 +31,13 @@ ...@@ -31,7 +31,13 @@
/* ??0_Mutex@std@@QEAA@XZ */ /* ??0_Mutex@std@@QEAA@XZ */
mutex* mutex_ctor(mutex *this) 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; return this;
} }
...@@ -39,21 +45,23 @@ mutex* mutex_ctor(mutex *this) ...@@ -39,21 +45,23 @@ mutex* mutex_ctor(mutex *this)
/* ??1_Mutex@std@@QEAA@XZ */ /* ??1_Mutex@std@@QEAA@XZ */
void mutex_dtor(mutex *this) 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@@QAEXXZ */
/* ?_Lock@_Mutex@std@@QEAAXXZ */ /* ?_Lock@_Mutex@std@@QEAAXXZ */
void mutex_lock(mutex *this) void mutex_lock(mutex *this)
{ {
WaitForSingleObject(this->mutex, INFINITE); EnterCriticalSection(this->mutex);
} }
/* ?_Unlock@_Mutex@std@@QAEXXZ */ /* ?_Unlock@_Mutex@std@@QAEXXZ */
/* ?_Unlock@_Mutex@std@@QEAAXXZ */ /* ?_Unlock@_Mutex@std@@QEAAXXZ */
void mutex_unlock(mutex *this) void mutex_unlock(mutex *this)
{ {
ReleaseMutex(this->mutex); LeaveCriticalSection(this->mutex);
} }
static CRITICAL_SECTION lockit_cs; static CRITICAL_SECTION lockit_cs;
......
...@@ -33,7 +33,15 @@ WINE_DEFAULT_DEBUG_CHANNEL(msvcp); ...@@ -33,7 +33,15 @@ WINE_DEFAULT_DEBUG_CHANNEL(msvcp);
DEFINE_THISCALL_WRAPPER(mutex_ctor, 4) DEFINE_THISCALL_WRAPPER(mutex_ctor, 4)
mutex* __thiscall mutex_ctor(mutex *this) 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; return this;
} }
...@@ -42,7 +50,9 @@ mutex* __thiscall mutex_ctor(mutex *this) ...@@ -42,7 +50,9 @@ mutex* __thiscall mutex_ctor(mutex *this)
DEFINE_THISCALL_WRAPPER(mutex_dtor, 4) DEFINE_THISCALL_WRAPPER(mutex_dtor, 4)
void __thiscall mutex_dtor(mutex *this) 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 */ /* ?_Lock@_Mutex@std@@QAEXXZ */
...@@ -50,7 +60,7 @@ void __thiscall mutex_dtor(mutex *this) ...@@ -50,7 +60,7 @@ void __thiscall mutex_dtor(mutex *this)
DEFINE_THISCALL_WRAPPER(mutex_lock, 4) DEFINE_THISCALL_WRAPPER(mutex_lock, 4)
void __thiscall mutex_lock(mutex *this) void __thiscall mutex_lock(mutex *this)
{ {
WaitForSingleObject(this->mutex, INFINITE); EnterCriticalSection(this->mutex);
} }
/* ?_Unlock@_Mutex@std@@QAEXXZ */ /* ?_Unlock@_Mutex@std@@QAEXXZ */
...@@ -58,7 +68,7 @@ void __thiscall mutex_lock(mutex *this) ...@@ -58,7 +68,7 @@ void __thiscall mutex_lock(mutex *this)
DEFINE_THISCALL_WRAPPER(mutex_unlock, 4) DEFINE_THISCALL_WRAPPER(mutex_unlock, 4)
void __thiscall mutex_unlock(mutex *this) void __thiscall mutex_unlock(mutex *this)
{ {
ReleaseMutex(this->mutex); LeaveCriticalSection(this->mutex);
} }
static CRITICAL_SECTION lockit_cs[_MAX_LOCK]; static CRITICAL_SECTION lockit_cs[_MAX_LOCK];
......
...@@ -201,7 +201,7 @@ void __thiscall _Lockit_dtor(_Lockit*); ...@@ -201,7 +201,7 @@ void __thiscall _Lockit_dtor(_Lockit*);
/* class mutex */ /* class mutex */
typedef struct { typedef struct {
void *mutex; void *mutex;
} mutex; } mutex;
mutex* __thiscall mutex_ctor(mutex*); mutex* __thiscall mutex_ctor(mutex*);
......
...@@ -33,7 +33,15 @@ WINE_DEFAULT_DEBUG_CHANNEL(msvcp); ...@@ -33,7 +33,15 @@ WINE_DEFAULT_DEBUG_CHANNEL(msvcp);
DEFINE_THISCALL_WRAPPER(mutex_ctor, 4) DEFINE_THISCALL_WRAPPER(mutex_ctor, 4)
mutex* __thiscall mutex_ctor(mutex *this) 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; return this;
} }
...@@ -42,7 +50,9 @@ mutex* __thiscall mutex_ctor(mutex *this) ...@@ -42,7 +50,9 @@ mutex* __thiscall mutex_ctor(mutex *this)
DEFINE_THISCALL_WRAPPER(mutex_dtor, 4) DEFINE_THISCALL_WRAPPER(mutex_dtor, 4)
void __thiscall mutex_dtor(mutex *this) 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 */ /* ?_Lock@_Mutex@std@@QAEXXZ */
...@@ -50,7 +60,7 @@ void __thiscall mutex_dtor(mutex *this) ...@@ -50,7 +60,7 @@ void __thiscall mutex_dtor(mutex *this)
DEFINE_THISCALL_WRAPPER(mutex_lock, 4) DEFINE_THISCALL_WRAPPER(mutex_lock, 4)
void __thiscall mutex_lock(mutex *this) void __thiscall mutex_lock(mutex *this)
{ {
WaitForSingleObject(this->mutex, INFINITE); EnterCriticalSection(this->mutex);
} }
/* ?_Unlock@_Mutex@std@@QAEXXZ */ /* ?_Unlock@_Mutex@std@@QAEXXZ */
...@@ -58,7 +68,7 @@ void __thiscall mutex_lock(mutex *this) ...@@ -58,7 +68,7 @@ void __thiscall mutex_lock(mutex *this)
DEFINE_THISCALL_WRAPPER(mutex_unlock, 4) DEFINE_THISCALL_WRAPPER(mutex_unlock, 4)
void __thiscall mutex_unlock(mutex *this) void __thiscall mutex_unlock(mutex *this)
{ {
ReleaseMutex(this->mutex); LeaveCriticalSection(this->mutex);
} }
/* ?_Mutex_Lock@_Mutex@std@@CAXPAV12@@Z */ /* ?_Mutex_Lock@_Mutex@std@@CAXPAV12@@Z */
......
...@@ -201,7 +201,7 @@ void __thiscall _Lockit_dtor(_Lockit*); ...@@ -201,7 +201,7 @@ void __thiscall _Lockit_dtor(_Lockit*);
/* class mutex */ /* class mutex */
typedef struct { typedef struct {
void *mutex; void *mutex;
} mutex; } mutex;
mutex* __thiscall mutex_ctor(mutex*); mutex* __thiscall mutex_ctor(mutex*);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment