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 _PSYNC
00036 #define _PSYNC
00037
00038 #ifdef P_USE_PRAGMA
00039 #pragma interface
00040 #endif
00041
00042 #include <ptlib/contain.h>
00043
00044 class PSync : public PObject
00045 {
00046 public:
00051 virtual void Wait() = 0;
00052
00055 virtual void Signal() = 0;
00057
00058 #ifdef P_PTHREADS
00059 PSync()
00060 : lockerId(pthread_t(-1)) { }
00061 protected:
00062 pthread_t lockerId;
00063 #endif
00064 };
00065
00066 class PSyncNULL : public PSync
00067 {
00068 public:
00069 virtual void Wait() { }
00070 virtual void Signal() { }
00071 };
00072
00092 class PWaitAndSignal {
00093 public:
00098 inline PWaitAndSignal(
00099 const PSync & sem,
00100 PBoolean wait = PTrue
00101 ) : sync((PSync &)sem)
00102 { if (wait) sync.Wait(); }
00103
00108 ~PWaitAndSignal()
00109 { sync.Signal(); }
00110
00111 protected:
00112 PSync & sync;
00113 };
00114
00115 #endif // _PSYNC
00116