/* Starshatter: The Open Source Project Copyright (c) 2021-2022, Starshatter: The Open Source Project Contributors Copyright (c) 2011-2012, Starshatter OpenSource Distribution Contributors Copyright (c) 1997-2006, Destroyer Studios LLC. AUTHOR: John DiCamillo OVERVIEW ======== Declaration of the ThreadSync class */ #ifndef ThreadSync_h #define ThreadSync_h #include // +-------------------------------------------------------------------+ class ThreadSync { #if defined(_MT) // MULTITHREADED: WITH SYNC ------------ CRITICAL_SECTION sync; public: ThreadSync() { ::InitializeCriticalSection(&sync); } ~ThreadSync() { ::DeleteCriticalSection(&sync); } void acquire() { ::EnterCriticalSection(&sync); } void release() { ::LeaveCriticalSection(&sync); } #else // SINGLE THREADED: NO SYNC ------------ public: ThreadSync() { } ~ThreadSync() { } void acquire() { } void release() { } #endif }; // +-------------------------------------------------------------------+ class AutoThreadSync { public: AutoThreadSync(ThreadSync& s) : sync(s) { sync.acquire(); } ~AutoThreadSync() { sync.release(); } private: ThreadSync& sync; }; #endif // ThreadSync_h