--- parser3/src/include/pa_threads.h 2001/05/17 10:22:24 1.14 +++ parser3/src/include/pa_threads.h 2026/04/25 13:38:46 1.40 @@ -1,29 +1,37 @@ /** @file Parser: mutex & helpers decls. - Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) - - Author: Alexander Petrosyan (http://design.ru/paf) - - $Id: pa_threads.h,v 1.14 2001/05/17 10:22:24 parser Exp $ + Copyright (c) 2001-2026 Art. Lebedev Studio (https://www.artlebedev.com) + Authors: Konstantin Morshnev , Alexandr Petrosian */ #ifndef PA_THREADS_H #define PA_THREADS_H +#define IDENT_PA_THREADS_H "$Id: pa_threads.h,v 1.40 2026/04/25 13:38:46 moko Exp $" + #include "pa_config_includes.h" #include "pa_types.h" +#ifdef _MSC_VER +#include +#endif -#ifdef MULTITHREAD +/// get caller thread ID +uint pa_get_thread_id(); class AutoSYNCHRONIZED; /// simple semaphore object class Mutex { - friend AutoSYNCHRONIZED; -private: - uint handle; + friend class AutoSYNCHRONIZED; + +#ifdef _MSC_VER +HANDLE handle; +#else +pthread_mutex_t handle; +#endif + public: Mutex(); ~Mutex(); @@ -36,9 +44,9 @@ extern Mutex global_mutex; /** Helper to ensure paired Mutex::acquire() and Mutex::release(). - Use it with SYNCHRONIZED macro */ + class AutoSYNCHRONIZED { public: AutoSYNCHRONIZED() { global_mutex.acquire(); } @@ -54,12 +62,8 @@ public: @endverbatim WARNING: don't use THROW or PTHROW with such thread safety mechanizm - - longjump would leave global_mutex acquired, which is wrong! + longjmp would leave global_mutex acquired, which is wrong! */ -# define SYNCHRONIZED AutoSYNCHRONIZED autoSYNCHRONIZED() -#else // not MULTITHREAD-ed -# define SYNCHRONIZED /* do nothing */ -#endif - +#define SYNCHRONIZED AutoSYNCHRONIZED autoSYNCHRONIZED #endif