Annotation of parser3/src/include/pa_threads.h, revision 1.6
1.1 paf 1: /*
1.5 paf 2: Parser
3: Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
1.6 ! paf 4: Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
1.5 paf 5:
1.6 ! paf 6: $Id: pa_threads.h,v 1.5 2001/03/10 16:34:35 paf Exp $
1.1 paf 7: */
8:
9: #ifndef PA_THREADS_H
10: #define PA_THREADS_H
11:
12: #ifdef HAVE_CONFIG_H
13: # include "pa_config.h"
14: #endif
15:
16: #include "pa_types.h"
17:
18:
19: #ifdef MULTITHREAD
20:
21: class Mutex {
22: uint handle;
23: public:
24: Mutex();
25: ~Mutex();
1.2 paf 26: void acquire();
27: void release();
1.1 paf 28: };
29:
1.2 paf 30: extern Mutex global_mutex;
1.1 paf 31:
1.2 paf 32: class AutoSYNCHRONIZED {
1.3 paf 33: bool thread_safe;
1.2 paf 34: public:
1.3 paf 35: AutoSYNCHRONIZED(bool athread_safe) : thread_safe(athread_safe) {
36: if(thread_safe)
37: global_mutex.acquire();
38: }
39: ~AutoSYNCHRONIZED() {
40: if(thread_safe)
41: global_mutex.release();
42: }
1.2 paf 43: }
44:
1.4 paf 45: #define SYNCHRONIZED(athread_safe) AutoSYNCHRONIZED autoSYNCHRONIZED(athread_safe)
1.2 paf 46:
47:
48: #else // not MULTITHREAD-ed
49:
1.4 paf 50: #define SYNCHRONIZED(athread_safe) /* do nothing */
1.1 paf 51:
52: #endif
1.2 paf 53:
1.1 paf 54:
55: #endif
E-mail: