mirror of
https://github.com/isledecomp/isle-portable.git
synced 2024-11-26 09:28:01 -05:00
Merge pull request #11 from foxtacles/isle-mxcriticalsection
lego1: Add MxCriticalSection implementation
This commit is contained in:
commit
dec959f194
4 changed files with 103 additions and 2 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
|
#ifndef MXCRITICALSECTION_H
|
||||||
#define MXCRITICALSECTION_H
|
#define MXCRITICALSECTION_H
|
||||||
|
|
||||||
|
#include <Windows.h>
|
||||||
|
|
||||||
class MxCriticalSection
|
class MxCriticalSection
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
__declspec(dllexport) MxCriticalSection();
|
__declspec(dllexport) MxCriticalSection();
|
||||||
__declspec(dllexport) ~MxCriticalSection();
|
__declspec(dllexport) ~MxCriticalSection();
|
||||||
__declspec(dllexport) static void SetDoMutex();
|
__declspec(dllexport) static void SetDoMutex();
|
||||||
|
void Enter();
|
||||||
|
void Leave();
|
||||||
|
|
||||||
|
private:
|
||||||
|
CRITICAL_SECTION m_criticalSection;
|
||||||
|
HANDLE m_mutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MXCRITICALSECTION_H
|
#endif // MXCRITICALSECTION_H
|
||||||
|
|
24
isle.mak
24
isle.mak
|
@ -57,6 +57,7 @@ CLEAN :
|
||||||
-@erase "$(INTDIR)\dllmain.obj"
|
-@erase "$(INTDIR)\dllmain.obj"
|
||||||
-@erase "$(INTDIR)\legoomni.obj"
|
-@erase "$(INTDIR)\legoomni.obj"
|
||||||
-@erase "$(INTDIR)\mxcore.obj"
|
-@erase "$(INTDIR)\mxcore.obj"
|
||||||
|
-@erase "$(INTDIR)\mxcriticalsection.obj"
|
||||||
-@erase ".\Release\LEGO1.DLL"
|
-@erase ".\Release\LEGO1.DLL"
|
||||||
-@erase ".\Release\LEGO1.EXP"
|
-@erase ".\Release\LEGO1.EXP"
|
||||||
-@erase ".\Release\LEGO1.LIB"
|
-@erase ".\Release\LEGO1.LIB"
|
||||||
|
@ -116,7 +117,8 @@ LINK32_FLAGS=kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib\
|
||||||
LINK32_OBJS= \
|
LINK32_OBJS= \
|
||||||
"$(INTDIR)\dllmain.obj" \
|
"$(INTDIR)\dllmain.obj" \
|
||||||
"$(INTDIR)\legoomni.obj" \
|
"$(INTDIR)\legoomni.obj" \
|
||||||
"$(INTDIR)\mxcore.obj"
|
"$(INTDIR)\mxcore.obj" \
|
||||||
|
"$(INTDIR)\mxcriticalsection.obj"
|
||||||
|
|
||||||
".\Release\LEGO1.DLL" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
|
".\Release\LEGO1.DLL" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
|
||||||
$(LINK32) @<<
|
$(LINK32) @<<
|
||||||
|
@ -144,6 +146,7 @@ CLEAN :
|
||||||
-@erase "$(INTDIR)\dllmain.obj"
|
-@erase "$(INTDIR)\dllmain.obj"
|
||||||
-@erase "$(INTDIR)\legoomni.obj"
|
-@erase "$(INTDIR)\legoomni.obj"
|
||||||
-@erase "$(INTDIR)\mxcore.obj"
|
-@erase "$(INTDIR)\mxcore.obj"
|
||||||
|
-@erase "$(INTDIR)\mxcriticalsection.obj"
|
||||||
-@erase "$(INTDIR)\vc40.idb"
|
-@erase "$(INTDIR)\vc40.idb"
|
||||||
-@erase "$(INTDIR)\vc40.pdb"
|
-@erase "$(INTDIR)\vc40.pdb"
|
||||||
-@erase "$(OUTDIR)\LEGO1.exp"
|
-@erase "$(OUTDIR)\LEGO1.exp"
|
||||||
|
@ -207,7 +210,8 @@ LINK32_FLAGS=kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib\
|
||||||
LINK32_OBJS= \
|
LINK32_OBJS= \
|
||||||
"$(INTDIR)\dllmain.obj" \
|
"$(INTDIR)\dllmain.obj" \
|
||||||
"$(INTDIR)\legoomni.obj" \
|
"$(INTDIR)\legoomni.obj" \
|
||||||
"$(INTDIR)\mxcore.obj"
|
"$(INTDIR)\mxcore.obj" \
|
||||||
|
"$(INTDIR)\mxcriticalsection.obj"
|
||||||
|
|
||||||
".\Debug\LEGO1.DLL" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
|
".\Debug\LEGO1.DLL" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
|
||||||
$(LINK32) @<<
|
$(LINK32) @<<
|
||||||
|
@ -443,6 +447,7 @@ SOURCE=.\LEGO1\legoomni.cpp
|
||||||
DEP_CPP_LEGOO=\
|
DEP_CPP_LEGOO=\
|
||||||
".\LEGO1\legoanimationmanager.h"\
|
".\LEGO1\legoanimationmanager.h"\
|
||||||
".\LEGO1\legobuildingmanager.h"\
|
".\LEGO1\legobuildingmanager.h"\
|
||||||
|
".\LEGO1\legoentity.h"\
|
||||||
".\LEGO1\legogamestate.h"\
|
".\LEGO1\legogamestate.h"\
|
||||||
".\LEGO1\legoinputmanager.h"\
|
".\LEGO1\legoinputmanager.h"\
|
||||||
".\LEGO1\legomodelpresenter.h"\
|
".\LEGO1\legomodelpresenter.h"\
|
||||||
|
@ -456,6 +461,8 @@ DEP_CPP_LEGOO=\
|
||||||
".\LEGO1\mxbool.h"\
|
".\LEGO1\mxbool.h"\
|
||||||
".\LEGO1\mxcore.h"\
|
".\LEGO1\mxcore.h"\
|
||||||
".\LEGO1\mxdsaction.h"\
|
".\LEGO1\mxdsaction.h"\
|
||||||
|
".\LEGO1\mxdsfile.h"\
|
||||||
|
".\LEGO1\mxdsobject.h"\
|
||||||
".\LEGO1\mxomnicreateflags.h"\
|
".\LEGO1\mxomnicreateflags.h"\
|
||||||
".\LEGO1\mxomnicreateparam.h"\
|
".\LEGO1\mxomnicreateparam.h"\
|
||||||
".\LEGO1\mxomnicreateparambase.h"\
|
".\LEGO1\mxomnicreateparambase.h"\
|
||||||
|
@ -477,6 +484,19 @@ DEP_CPP_LEGOO=\
|
||||||
$(CPP) $(CPP_PROJ) $(SOURCE)
|
$(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 Source File
|
||||||
# End Target
|
# End Target
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
BIN
isle.mdp
BIN
isle.mdp
Binary file not shown.
Loading…
Reference in a new issue