isle-portable/LEGO1/mxcriticalsection.cpp

73 lines
1.2 KiB
C++
Raw Normal View History

2023-06-12 14:46:44 -04:00
#include "mxcriticalsection.h"
#include <stdio.h>
2023-06-18 23:56:55 -04:00
// 0x10101e78
2023-06-12 14:46:44 -04:00
int g_useMutex = 0;
2023-06-18 23:56:55 -04:00
// OFFSET: LEGO1 0x100b6d20
2023-06-12 14:46:44 -04:00
MxCriticalSection::MxCriticalSection()
{
2023-10-24 19:38:27 -04:00
HANDLE mutex;
2023-06-12 14:46:44 -04:00
2023-10-24 19:38:27 -04:00
if (g_useMutex != 0) {
mutex = CreateMutexA(NULL, FALSE, NULL);
this->m_mutex = mutex;
return;
}
2023-06-12 14:46:44 -04:00
2023-10-24 19:38:27 -04:00
InitializeCriticalSection(&this->m_criticalSection);
this->m_mutex = NULL;
2023-06-12 14:46:44 -04:00
}
2023-06-18 23:56:55 -04:00
// OFFSET: LEGO1 0x100b6d60
2023-06-12 14:46:44 -04:00
MxCriticalSection::~MxCriticalSection()
{
2023-10-24 19:38:27 -04:00
if (this->m_mutex != NULL) {
CloseHandle(this->m_mutex);
return;
}
2023-06-12 14:46:44 -04:00
2023-10-24 19:38:27 -04:00
DeleteCriticalSection(&this->m_criticalSection);
2023-06-12 14:46:44 -04:00
}
2023-06-18 23:56:55 -04:00
// OFFSET: LEGO1 0x100b6d80
2023-06-12 14:46:44 -04:00
void MxCriticalSection::Enter()
{
2023-10-24 19:38:27 -04:00
DWORD result;
FILE* file;
2023-06-12 14:46:44 -04:00
2023-10-24 19:38:27 -04:00
if (this->m_mutex != NULL) {
result = WaitForSingleObject(this->m_mutex, 5000);
if (result == WAIT_FAILED) {
file = fopen("C:\\DEADLOCK.TXT", "a");
if (file != NULL) {
fprintf(file, "mutex timeout occurred!\n");
fclose(file);
}
2023-06-12 14:46:44 -04:00
2023-10-24 19:38:27 -04:00
abort();
}
}
else {
EnterCriticalSection(&this->m_criticalSection);
}
2023-06-12 14:46:44 -04:00
}
2023-06-18 23:56:55 -04:00
// OFFSET: LEGO1 0x100b6de0
2023-06-12 14:46:44 -04:00
void MxCriticalSection::Leave()
{
2023-10-24 19:38:27 -04:00
if (this->m_mutex != NULL) {
ReleaseMutex(this->m_mutex);
return;
}
2023-06-12 14:46:44 -04:00
2023-10-24 19:38:27 -04:00
LeaveCriticalSection(&this->m_criticalSection);
2023-06-18 23:56:55 -04:00
}
// OFFSET: LEGO1 0x100b6e00
void MxCriticalSection::SetDoMutex()
{
g_useMutex = 1;
}