00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 #ifndef PTLIB_SYNC_H
00036 #define PTLIB_SYNC_H
00037 
00038 #ifdef P_USE_PRAGMA
00039 #pragma interface
00040 #endif
00041 
00042 #include <ptlib/contain.h>
00043 #include <ptlib/object.h>
00044 
00045 class PSync : public PObject
00046 {
00047   public:
00052     virtual void Wait() = 0;
00053 
00056     virtual void Signal() = 0;
00058 
00059 #ifdef P_PTHREADS
00060     PSync()
00061       : lockerId(pthread_t(-1)) { }
00062   protected:
00063     pthread_t lockerId;
00064 #endif
00065 };
00066 
00067 class PSyncNULL : public PSync
00068 {
00069   public:
00070     virtual void Wait() { }
00071     virtual void Signal() { }
00072 };
00073 
00093 class PWaitAndSignal {
00094   public:
00099     inline PWaitAndSignal(
00100       const PSync & sem,   
00101       PBoolean wait = PTrue    
00102     ) : sync((PSync &)sem)
00103     { if (wait) sync.Wait(); }
00104 
00109     ~PWaitAndSignal()
00110     { sync.Signal(); }
00111 
00112   protected:
00113     PSync & sync;
00114 };
00115 
00116 
00117 #endif // PTLIB_SYNC_H
00118 
00119 
00120