--- parser3/src/include/pa_threads.h 2001/01/29 11:17:49 1.1 +++ parser3/src/include/pa_threads.h 2001/01/29 12:16:07 1.4 @@ -1,5 +1,5 @@ /* - $Id: pa_threads.h,v 1.1 2001/01/29 11:17:49 paf Exp $ + $Id: pa_threads.h,v 1.4 2001/01/29 12:16:07 paf Exp $ */ #ifndef PA_THREADS_H @@ -19,19 +19,33 @@ class Mutex { public: Mutex(); ~Mutex(); - void lock(); - void unlock(); + void acquire(); + void release(); }; -#else +extern Mutex global_mutex; -class Mutex { - Mutex() {} - ~Mutex() {} - void lock() {} - void unlock() {} -}; +class AutoSYNCHRONIZED { + bool thread_safe; +public: + AutoSYNCHRONIZED(bool athread_safe) : thread_safe(athread_safe) { + if(thread_safe) + global_mutex.acquire(); + } + ~AutoSYNCHRONIZED() { + if(thread_safe) + global_mutex.release(); + } +} + +#define SYNCHRONIZED(athread_safe) AutoSYNCHRONIZED autoSYNCHRONIZED(athread_safe) + + +#else // not MULTITHREAD-ed + +#define SYNCHRONIZED(athread_safe) /* do nothing */ #endif + #endif