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