diff --git a/LEGO1/mxcriticalsection.cpp b/LEGO1/mxcriticalsection.cpp new file mode 100644 index 00000000..b94c021c --- /dev/null +++ b/LEGO1/mxcriticalsection.cpp @@ -0,0 +1,73 @@ +#include "mxcriticalsection.h" + +#include + +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); +} \ No newline at end of file diff --git a/LEGO1/mxcriticalsection.h b/LEGO1/mxcriticalsection.h index 3e9e411c..bd84babb 100644 --- a/LEGO1/mxcriticalsection.h +++ b/LEGO1/mxcriticalsection.h @@ -1,12 +1,20 @@ #ifndef MXCRITICALSECTION_H #define MXCRITICALSECTION_H +#include + 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 diff --git a/isle.mak b/isle.mak index 405f6f5b..c81ebe25 100644 --- a/isle.mak +++ b/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) @<< @@ -443,6 +447,7 @@ SOURCE=.\LEGO1\legoomni.cpp DEP_CPP_LEGOO=\ ".\LEGO1\legoanimationmanager.h"\ ".\LEGO1\legobuildingmanager.h"\ + ".\LEGO1\legoentity.h"\ ".\LEGO1\legogamestate.h"\ ".\LEGO1\legoinputmanager.h"\ ".\LEGO1\legomodelpresenter.h"\ @@ -456,6 +461,8 @@ DEP_CPP_LEGOO=\ ".\LEGO1\mxbool.h"\ ".\LEGO1\mxcore.h"\ ".\LEGO1\mxdsaction.h"\ + ".\LEGO1\mxdsfile.h"\ + ".\LEGO1\mxdsobject.h"\ ".\LEGO1\mxomnicreateflags.h"\ ".\LEGO1\mxomnicreateparam.h"\ ".\LEGO1\mxomnicreateparambase.h"\ @@ -477,6 +484,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 ################################################################################ diff --git a/isle.mdp b/isle.mdp index 3cbe9164..1d92bce9 100644 Binary files a/isle.mdp and b/isle.mdp differ