00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef PSEMAPHORE_H
00016 #define PSEMAPHORE_H
00017
00018 #include "pandabase.h"
00019 #include "pmutex.h"
00020 #include "conditionVar.h"
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 class EXPCL_PANDA_PIPELINE Semaphore {
00034 PUBLISHED:
00035 INLINE Semaphore(int initial_count = 1);
00036 INLINE ~Semaphore();
00037 private:
00038 INLINE Semaphore(const Semaphore ©);
00039 INLINE void operator = (const Semaphore ©);
00040
00041 PUBLISHED:
00042 BLOCKING INLINE void acquire();
00043 BLOCKING INLINE bool try_acquire();
00044 INLINE int release();
00045
00046 INLINE int get_count() const;
00047 void output(ostream &out) const;
00048
00049 private:
00050 Mutex _lock;
00051 ConditionVar _cvar;
00052 int _count;
00053 };
00054
00055 INLINE ostream &
00056 operator << (ostream &out, const Semaphore &sem) {
00057 sem.output(out);
00058 return out;
00059 }
00060
00061 #include "psemaphore.I"
00062
00063 #endif