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