Diff for /parser3/src/include/pa_threads.h between versions 1.8 and 1.22

version 1.8, 2001/03/19 16:44:00 version 1.22, 2002/02/08 07:27:45
Line 1 Line 1
 /** @file  /** @file
         Parser          Parser: mutex & helpers decls.
         Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)  
         Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)          Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com)
           Author: Alexander Petrosyan <paf@design.ru> (http://paf.design.ru)
   
         $Id$          $Id$
 */  */
Line 9 Line 10
 #ifndef PA_THREADS_H  #ifndef PA_THREADS_H
 #define PA_THREADS_H  #define PA_THREADS_H
   
 #ifdef HAVE_CONFIG_H  #include "pa_config_includes.h"
 #       include "pa_config.h"  
 #endif  
   
 #include "pa_types.h"  #include "pa_types.h"
   
   /// thread ID type
   typedef unsigned int pa_thread_t;
   
 #ifdef MULTITHREAD  /// get caller thread ID
   pa_thread_t pa_get_thread_id();
   
   class AutoSYNCHRONIZED;
   
 /// simple semaphore object  /// simple semaphore object
 class Mutex {  class Mutex {
           friend class AutoSYNCHRONIZED;
   private:
         uint handle;          uint handle;
 public:  public:
         Mutex();          Mutex();
         ~Mutex();          ~Mutex();
   private: // for AutoSYNCHRONIZED
         void acquire();          void acquire();
         void release();          void release();
 };  };
   
   extern const bool parser_multithreaded;
 extern Mutex global_mutex;  extern Mutex global_mutex;
   
 /**   /** 
Line 36  extern Mutex global_mutex; Line 43  extern Mutex global_mutex;
         Use it with SYNCHRONIZED macro          Use it with SYNCHRONIZED macro
 */  */
 class AutoSYNCHRONIZED {  class AutoSYNCHRONIZED {
         bool thread_safe;  
 public:  public:
         AutoSYNCHRONIZED(bool athread_safe) : thread_safe(athread_safe) {           AutoSYNCHRONIZED() { global_mutex.acquire(); }
                 if(thread_safe)          ~AutoSYNCHRONIZED() { global_mutex.release(); }
                         global_mutex.acquire();   
         }  
         ~AutoSYNCHRONIZED() {   
                 if(thread_safe)  
                         global_mutex.release();   
         }  
 };  };
   
 /**   /** 
         put it to first line of a function to ensure thread safety.          put it to first line of a function to ensure thread safety.
   
         @verbatim          @verbatim
         void someclass::somefunc(...) { SYNCHRONIZED(thread_safe);                  void someclass::somefunc(...) { SYNCHRONIZED;
                 ...                          ...
         }                  }
         @endverbatim          @endverbatim
   
         considering \a thread_safe to be the object field to flag           WARNING: don't use THROW or PTHROW with such thread safety mechanizm -
         whether safety is really needed in this particular object instance          longjmp would leave global_mutex acquired, which is wrong!
 */  */
 #define SYNCHRONIZED(athread_safe) AutoSYNCHRONIZED autoSYNCHRONIZED(athread_safe)  #define SYNCHRONIZED AutoSYNCHRONIZED autoSYNCHRONIZED
   
 #else // not MULTITHREAD-ed  
   
 #define SYNCHRONIZED(athread_safe) /* do nothing */  
   
 #endif  
   
   
 #endif  #endif

Removed from v.1.8  
changed lines
  Added in v.1.22


E-mail: