mirror of
https://github.com/isledecomp/isle-portable.git
synced 2024-11-26 01:17:55 -05:00
lego1: add MxCriticalSection implementation
This commit is contained in:
parent
d4f25fcd23
commit
fba95658b5
4 changed files with 112 additions and 14 deletions
73
LEGO1/mxcriticalsection.cpp
Normal file
73
LEGO1/mxcriticalsection.cpp
Normal file
|
@ -0,0 +1,73 @@
|
|||
#include "mxcriticalsection.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int g_useMutex = 0;
|
||||
|
||||
MxCriticalSection::MxCriticalSection()
|
||||
{
|
||||
HANDLE mutex;
|
||||
|
||||
if (g_useMutex != 0)
|
||||
{
|
||||
mutex = CreateMutexA(NULL, FALSE, NULL);
|
||||
this->m_mutex = mutex;
|
||||
return;
|
||||
}
|
||||
|
||||
InitializeCriticalSection(&this->m_criticalSection);
|
||||
this->m_mutex = NULL;
|
||||
}
|
||||
|
||||
MxCriticalSection::~MxCriticalSection()
|
||||
{
|
||||
if (this->m_mutex != NULL)
|
||||
{
|
||||
CloseHandle(this->m_mutex);
|
||||
return;
|
||||
}
|
||||
|
||||
DeleteCriticalSection(&this->m_criticalSection);
|
||||
}
|
||||
|
||||
void MxCriticalSection::SetDoMutex()
|
||||
{
|
||||
g_useMutex = 1;
|
||||
}
|
||||
|
||||
void MxCriticalSection::Enter()
|
||||
{
|
||||
DWORD result;
|
||||
FILE *file;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
abort();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
EnterCriticalSection(&this->m_criticalSection);
|
||||
}
|
||||
}
|
||||
|
||||
void MxCriticalSection::Leave()
|
||||
{
|
||||
if (this->m_mutex != NULL)
|
||||
{
|
||||
ReleaseMutex(this->m_mutex);
|
||||
return;
|
||||
}
|
||||
|
||||
LeaveCriticalSection(&this->m_criticalSection);
|
||||
}
|
|
@ -1,12 +1,20 @@
|
|||
#ifndef MXCRITICALSECTION_H
|
||||
#define MXCRITICALSECTION_H
|
||||
|
||||
#include <Windows.h>
|
||||
|
||||
class MxCriticalSection
|
||||
{
|
||||
public:
|
||||
__declspec(dllexport) MxCriticalSection();
|
||||
__declspec(dllexport) ~MxCriticalSection();
|
||||
__declspec(dllexport) static void SetDoMutex();
|
||||
void Enter();
|
||||
void Leave();
|
||||
|
||||
private:
|
||||
CRITICAL_SECTION m_criticalSection;
|
||||
HANDLE m_mutex;
|
||||
};
|
||||
|
||||
#endif // MXCRITICALSECTION_H
|
||||
|
|
21
isle.mak
21
isle.mak
|
@ -57,6 +57,7 @@ CLEAN :
|
|||
-@erase "$(INTDIR)\dllmain.obj"
|
||||
-@erase "$(INTDIR)\legoomni.obj"
|
||||
-@erase "$(INTDIR)\mxcore.obj"
|
||||
-@erase "$(INTDIR)\mxcriticalsection.obj"
|
||||
-@erase ".\Release\LEGO1.DLL"
|
||||
-@erase ".\Release\LEGO1.EXP"
|
||||
-@erase ".\Release\LEGO1.LIB"
|
||||
|
@ -116,7 +117,8 @@ LINK32_FLAGS=kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib\
|
|||
LINK32_OBJS= \
|
||||
"$(INTDIR)\dllmain.obj" \
|
||||
"$(INTDIR)\legoomni.obj" \
|
||||
"$(INTDIR)\mxcore.obj"
|
||||
"$(INTDIR)\mxcore.obj" \
|
||||
"$(INTDIR)\mxcriticalsection.obj"
|
||||
|
||||
".\Release\LEGO1.DLL" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
|
||||
$(LINK32) @<<
|
||||
|
@ -144,6 +146,7 @@ CLEAN :
|
|||
-@erase "$(INTDIR)\dllmain.obj"
|
||||
-@erase "$(INTDIR)\legoomni.obj"
|
||||
-@erase "$(INTDIR)\mxcore.obj"
|
||||
-@erase "$(INTDIR)\mxcriticalsection.obj"
|
||||
-@erase "$(INTDIR)\vc40.idb"
|
||||
-@erase "$(INTDIR)\vc40.pdb"
|
||||
-@erase "$(OUTDIR)\LEGO1.exp"
|
||||
|
@ -207,7 +210,8 @@ LINK32_FLAGS=kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib\
|
|||
LINK32_OBJS= \
|
||||
"$(INTDIR)\dllmain.obj" \
|
||||
"$(INTDIR)\legoomni.obj" \
|
||||
"$(INTDIR)\mxcore.obj"
|
||||
"$(INTDIR)\mxcore.obj" \
|
||||
"$(INTDIR)\mxcriticalsection.obj"
|
||||
|
||||
".\Debug\LEGO1.DLL" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
|
||||
$(LINK32) @<<
|
||||
|
@ -477,6 +481,19 @@ DEP_CPP_LEGOO=\
|
|||
$(CPP) $(CPP_PROJ) $(SOURCE)
|
||||
|
||||
|
||||
# End Source File
|
||||
################################################################################
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\LEGO1\mxcriticalsection.cpp
|
||||
DEP_CPP_MXCRI=\
|
||||
".\LEGO1\mxcriticalsection.h"\
|
||||
|
||||
|
||||
"$(INTDIR)\mxcriticalsection.obj" : $(SOURCE) $(DEP_CPP_MXCRI) "$(INTDIR)"
|
||||
$(CPP) $(CPP_PROJ) $(SOURCE)
|
||||
|
||||
|
||||
# End Source File
|
||||
# End Target
|
||||
################################################################################
|
||||
|
|
BIN
isle.mdp
BIN
isle.mdp
Binary file not shown.
Loading…
Reference in a new issue