Annotation of parser3/src/include/pa_threads.h, revision 1.20

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.20    ! paf         5:        Author: Alexander Petrosyan <paf@design.ru> (http://paf.design.ru)
1.5       paf         6: 
1.20    ! paf         7:        $Id: pa_threads.h,v 1.19 2001/10/31 11:23:38 paf 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.19      paf        31: extern const bool parser_multithreaded;
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: