Annotation of parser3/src/include/pa_threads.h, revision 1.30
1.7 paf 1: /** @file
1.9 paf 2: Parser: mutex & helpers decls.
3:
1.30 ! paf 4: Copyright (c) 2001-2005 ArtLebedev Group (http://www.artlebedev.com)
1.23 paf 5: Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.1 paf 6: */
7:
8: #ifndef PA_THREADS_H
9: #define PA_THREADS_H
1.24 paf 10:
1.30 ! paf 11: static const char * const IDENT_THREADS_H="$Date: 2004/02/11 15:33:14 $";
1.1 paf 12:
1.11 paf 13: #include "pa_config_includes.h"
1.1 paf 14: #include "pa_types.h"
1.21 paf 15:
16: /// thread ID type
17: typedef unsigned int pa_thread_t;
18:
19: /// get caller thread ID
20: pa_thread_t pa_get_thread_id();
1.1 paf 21:
1.13 parser 22: class AutoSYNCHRONIZED;
23:
1.7 paf 24: /// simple semaphore object
1.1 paf 25: class Mutex {
1.18 paf 26: friend class AutoSYNCHRONIZED;
1.13 parser 27: private:
1.1 paf 28: uint handle;
29: public:
30: Mutex();
31: ~Mutex();
1.13 parser 32: private: // for AutoSYNCHRONIZED
1.2 paf 33: void acquire();
34: void release();
1.1 paf 35: };
36:
1.19 paf 37: extern const bool parser_multithreaded;
1.2 paf 38: extern Mutex global_mutex;
1.1 paf 39:
1.8 paf 40: /**
1.7 paf 41: Helper to ensure paired Mutex::acquire() and Mutex::release().
42:
43: Use it with SYNCHRONIZED macro
44: */
1.2 paf 45: class AutoSYNCHRONIZED {
46: public:
1.13 parser 47: AutoSYNCHRONIZED() { global_mutex.acquire(); }
48: ~AutoSYNCHRONIZED() { global_mutex.release(); }
1.7 paf 49: };
50:
1.8 paf 51: /**
52: put it to first line of a function to ensure thread safety.
1.7 paf 53: @verbatim
1.13 parser 54: void someclass::somefunc(...) { SYNCHRONIZED;
1.10 paf 55: ...
56: }
1.7 paf 57: @endverbatim
1.2 paf 58:
1.13 parser 59: WARNING: don't use THROW or PTHROW with such thread safety mechanizm -
1.15 parser 60: longjmp would leave global_mutex acquired, which is wrong!
1.7 paf 61: */
1.16 parser 62: #define SYNCHRONIZED AutoSYNCHRONIZED autoSYNCHRONIZED
1.1 paf 63:
64: #endif
E-mail: