lego1: add MxCriticalSection implementation

This commit is contained in:
Christian Semmler 2023-06-12 20:43:19 +02:00
parent d4f25fcd23
commit fba95658b5
No known key found for this signature in database
GPG key ID: 086DAA1360BEEE5C
4 changed files with 112 additions and 14 deletions

View 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);
}

View file

@ -1,12 +1,20 @@
#ifndef MXCRITICALSECTION_H #ifndef MXCRITICALSECTION_H
#define MXCRITICALSECTION_H #define MXCRITICALSECTION_H
class MxCriticalSection #include <Windows.h>
{
public: class MxCriticalSection
__declspec(dllexport) MxCriticalSection(); {
__declspec(dllexport) ~MxCriticalSection(); public:
__declspec(dllexport) static void SetDoMutex(); __declspec(dllexport) MxCriticalSection();
}; __declspec(dllexport) ~MxCriticalSection();
__declspec(dllexport) static void SetDoMutex();
#endif // MXCRITICALSECTION_H void Enter();
void Leave();
private:
CRITICAL_SECTION m_criticalSection;
HANDLE m_mutex;
};
#endif // MXCRITICALSECTION_H

View file

@ -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) @<<
@ -477,6 +481,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

Binary file not shown.