1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
#ifndef _SEMPAHORE_H_ #define _SEMPAHORE_H_ #include <pthread.h> namespace TNet { class Semaphore { public: Semaphore(int initValue = 0); ~Semaphore(); int TryWait(); void Wait(); void Post(); int GetValue(); private: int mSemValue; pthread_mutex_t mMutex; pthread_cond_t mCond; }; } //namespace #endif