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

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.15    ! parser      8:        $Id: pa_threads.h,v 1.14 2001/05/17 10:22:24 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: 
                     17: 
                     18: #ifdef MULTITHREAD
                     19: 
1.13      parser     20: class AutoSYNCHRONIZED;
                     21: 
1.7       paf        22: /// simple semaphore object
1.1       paf        23: class Mutex {
1.13      parser     24:        friend AutoSYNCHRONIZED;
                     25: private:
1.1       paf        26:        uint handle;
                     27: public:
                     28:        Mutex();
                     29:        ~Mutex();
1.13      parser     30: private: // for AutoSYNCHRONIZED
1.2       paf        31:        void acquire();
                     32:        void release();
1.1       paf        33: };
                     34: 
1.2       paf        35: extern Mutex global_mutex;
1.1       paf        36: 
1.8       paf        37: /** 
1.7       paf        38:        Helper to ensure paired Mutex::acquire() and Mutex::release().
                     39: 
                     40:        Use it with SYNCHRONIZED macro
                     41: */
1.2       paf        42: class AutoSYNCHRONIZED {
                     43: public:
1.13      parser     44:        AutoSYNCHRONIZED() { global_mutex.acquire(); }
                     45:        ~AutoSYNCHRONIZED() { global_mutex.release(); }
1.7       paf        46: };
                     47: 
1.8       paf        48: /** 
                     49:        put it to first line of a function to ensure thread safety.
1.7       paf        50:        @verbatim
1.13      parser     51:                void someclass::somefunc(...) { SYNCHRONIZED;
1.10      paf        52:                        ...
                     53:                }
1.7       paf        54:        @endverbatim
1.2       paf        55: 
1.13      parser     56:        WARNING: don't use THROW or PTHROW with such thread safety mechanizm -
1.15    ! parser     57:        longjmp would leave global_mutex acquired, which is wrong!
1.7       paf        58: */
1.15    ! parser     59: #      define SYNCHRONIZED AutoSYNCHRONIZED autoSYNCHRONIZED
        !            60: #else
        !            61:        // not MULTITHREAD-ed, do nothing
        !            62: #      define SYNCHRONIZED
1.1       paf        63: #endif
1.2       paf        64: 
1.1       paf        65: 
                     66: #endif

E-mail: