2012-01-04 15:44:07 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2010 Piotr Caban for CodeWeavers
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <limits.h>
|
|
|
|
|
|
|
|
#include "msvcp.h"
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
2012-06-29 08:32:07 +02:00
|
|
|
|
2012-01-04 15:44:07 +01:00
|
|
|
|
|
|
|
/* ??0_Mutex@std@@QAE@XZ */
|
|
|
|
/* ??0_Mutex@std@@QEAA@XZ */
|
|
|
|
DEFINE_THISCALL_WRAPPER(mutex_ctor, 4)
|
|
|
|
mutex* __thiscall mutex_ctor(mutex *this)
|
|
|
|
{
|
|
|
|
this->mutex = CreateMutexW(NULL, FALSE, NULL);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ??1_Mutex@std@@QAE@XZ */
|
|
|
|
/* ??1_Mutex@std@@QEAA@XZ */
|
|
|
|
DEFINE_THISCALL_WRAPPER(mutex_dtor, 4)
|
|
|
|
void __thiscall mutex_dtor(mutex *this)
|
|
|
|
{
|
|
|
|
CloseHandle(this->mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ?_Lock@_Mutex@std@@QAEXXZ */
|
|
|
|
/* ?_Lock@_Mutex@std@@QEAAXXZ */
|
|
|
|
DEFINE_THISCALL_WRAPPER(mutex_lock, 4)
|
|
|
|
void __thiscall mutex_lock(mutex *this)
|
|
|
|
{
|
|
|
|
WaitForSingleObject(this->mutex, INFINITE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ?_Unlock@_Mutex@std@@QAEXXZ */
|
|
|
|
/* ?_Unlock@_Mutex@std@@QEAAXXZ */
|
|
|
|
DEFINE_THISCALL_WRAPPER(mutex_unlock, 4)
|
|
|
|
void __thiscall mutex_unlock(mutex *this)
|
|
|
|
{
|
|
|
|
ReleaseMutex(this->mutex);
|
|
|
|
}
|
|
|
|
|
2012-01-30 17:47:36 +01:00
|
|
|
static CRITICAL_SECTION lockit_cs;
|
2012-01-04 15:44:07 +01:00
|
|
|
|
|
|
|
void init_lockit(void) {
|
2012-01-30 17:47:36 +01:00
|
|
|
InitializeCriticalSection(&lockit_cs);
|
|
|
|
lockit_cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": _Lockit critical section");
|
2012-01-04 15:44:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void free_lockit(void) {
|
2012-01-30 17:47:36 +01:00
|
|
|
lockit_cs.DebugInfo->Spare[0] = 0;
|
|
|
|
DeleteCriticalSection(&lockit_cs);
|
2012-01-04 15:44:07 +01:00
|
|
|
}
|
|
|
|
|
2012-06-28 17:01:04 +02:00
|
|
|
static _Lockit* __thiscall _Lockit_ctor_locktype(_Lockit *this, int locktype)
|
2012-01-04 15:44:07 +01:00
|
|
|
{
|
2012-01-30 17:47:36 +01:00
|
|
|
EnterCriticalSection(&lockit_cs);
|
2012-01-04 15:44:07 +01:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ??0_Lockit@std@@QAE@XZ */
|
|
|
|
/* ??0_Lockit@std@@QEAA@XZ */
|
|
|
|
DEFINE_THISCALL_WRAPPER(_Lockit_ctor, 4)
|
|
|
|
_Lockit* __thiscall _Lockit_ctor(_Lockit *this)
|
|
|
|
{
|
2012-01-30 17:47:36 +01:00
|
|
|
return _Lockit_ctor_locktype(this, 0);
|
2012-01-04 15:44:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ??1_Lockit@std@@QAE@XZ */
|
|
|
|
/* ??1_Lockit@std@@QEAA@XZ */
|
|
|
|
DEFINE_THISCALL_WRAPPER(_Lockit_dtor, 4)
|
|
|
|
void __thiscall _Lockit_dtor(_Lockit *this)
|
|
|
|
{
|
2012-01-30 17:47:36 +01:00
|
|
|
LeaveCriticalSection(&lockit_cs);
|
2012-01-04 15:44:07 +01:00
|
|
|
}
|