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

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

E-mail: