首页 > 代码库 > 条件锁类

条件锁类

#include <pthread.h>    class CTestLock    {    public:        CTestLock()        { pthread_mutex_init(&mutex_t_, NULL);  pthread_cond_init(&cond_t_, NULL);      }        ~CTestLock()       { pthread_mutex_destroy(&mutex_t_);     pthread_cond_destroy(&cond_t_);          }        int Lock()          { int nRetCode = pthread_mutex_lock(&mutex_t_);         return (nRetCode == 0); }        int Unlock()      { int nRetCode = pthread_mutex_unlock(&mutex_t_);       return (nRetCode == 0); }        int Wait()           { int nRetCode = pthread_cond_wait(&cond_t_,&mutex_t_); return (nRetCode == 0); }        int Signal()       { int nRetCode = pthread_cond_signal(&cond_t_);          return (nRetCode == 0); }            int Broadcast()   { int nRetCode = pthread_cond_broadcast(&cond_t_);      return (nRetCode == 0); }            private:        pthread_mutex_t mutex_t_;        pthread_cond_t cond_t_;    };