From fba95658b570b3a7095dfbcbfee368ad64c82d1f Mon Sep 17 00:00:00 2001 From: Christian Semmler Date: Mon, 12 Jun 2023 20:43:19 +0200 Subject: [PATCH 1/2] lego1: add MxCriticalSection implementation --- LEGO1/mxcriticalsection.cpp | 73 ++++++++++++++++++++++++++++++++++++ LEGO1/mxcriticalsection.h | 32 ++++++++++------ isle.mak | 21 ++++++++++- isle.mdp | Bin 44544 -> 45568 bytes 4 files changed, 112 insertions(+), 14 deletions(-) create mode 100644 LEGO1/mxcriticalsection.cpp diff --git a/LEGO1/mxcriticalsection.cpp b/LEGO1/mxcriticalsection.cpp new file mode 100644 index 00000000..9b25c8f9 --- /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..4c8d43d0 100644 --- a/LEGO1/mxcriticalsection.h +++ b/LEGO1/mxcriticalsection.h @@ -1,12 +1,20 @@ -#ifndef MXCRITICALSECTION_H -#define MXCRITICALSECTION_H - -class MxCriticalSection -{ -public: - __declspec(dllexport) MxCriticalSection(); - __declspec(dllexport) ~MxCriticalSection(); - __declspec(dllexport) static void SetDoMutex(); -}; - -#endif // MXCRITICALSECTION_H +#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 d98109dc..0dd74a84 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) @<< @@ -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 ################################################################################ diff --git a/isle.mdp b/isle.mdp index 61c43766da99a1aa1dd70d85787907e084aba1ca..9b671ec0537ac37ada2e3bbd2a435bdb872c75cc 100644 GIT binary patch literal 45568 zcmeI5OK{sn7{@<1O^B1yyi@v4ODT`GZj+S0AGA(e5>i@{mcWb|s#vNmqK8LT8u!*C zWu|9_Gu$|HhBI8a@_|k0VIF~kN^@u0!RP}AOR$R1dsp{Kmz|g0nGo&KZ91!|Lul7uow2h zemDRJVGIt*G2qsgB#?%I?^?2B*eN7{1dsp{Kmter2_OL^fCP{L5*9yUWX&_1{{Sq;VpO@-hpFs47jx=2~_ic^viz3)AO@8#!iean9k(H*qmV*TG{9X zGA+~|SBDs^rBpxGO@?u_T`ifcP&-ZM1cC~2N%FA^-(im${i!!io4 z=9sqTo33MPj#eJX5@wq(1W5_*``{25VHE=aSkIfq7)=hPyE^E3RkhTuWnv zu`8PI+NPc4n^BV!)VgSrAyCQ`PbH|;b*)4JdDkOj^Gy62 zbkj5PzV2x&nd0dLVP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u2C3(44*(ZcY~tayvLYcfL84sKmj=|0Yz&TB?5SI32e@Y0aAbOuO z8xg%Hyb4sEj&rYnJW;I3rKl1;rie_*?)plHkkfeDU?&FD%9^g-Spc0QZM+deryX@YnmcSMOP z;)U0_YzO)O(!G8{Qva(j+V}s3O8}#Li3BK%6l8Z0w2qK#(xZeU`)T(o&a|hQ3S#Ff zaA~SQnz5tFW$NZcd!iWh2mjdNv?L=%cfz-4j;r6NZ|MO&r0-~jR_PIaZweXV^B!Vg Gg#HBzT} Date: Mon, 12 Jun 2023 20:46:44 +0200 Subject: [PATCH 2/2] use LF line ending --- LEGO1/mxcriticalsection.cpp | 144 ++++++++++++++++++------------------ LEGO1/mxcriticalsection.h | 40 +++++----- 2 files changed, 92 insertions(+), 92 deletions(-) diff --git a/LEGO1/mxcriticalsection.cpp b/LEGO1/mxcriticalsection.cpp index 9b25c8f9..b94c021c 100644 --- a/LEGO1/mxcriticalsection.cpp +++ b/LEGO1/mxcriticalsection.cpp @@ -1,73 +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); +#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 4c8d43d0..bd84babb 100644 --- a/LEGO1/mxcriticalsection.h +++ b/LEGO1/mxcriticalsection.h @@ -1,20 +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 +#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