游雁
2024-02-19 94de39dde2e616a01683c518023d0fab72b4e103
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
27
28
29
30
31
32
33
34
35
36
37
38
#ifndef LIMONP_CONDITION_HPP
#define LIMONP_CONDITION_HPP
 
#include "MutexLock.hpp"
 
namespace limonp {
 
class Condition : NonCopyable {
 public:
  explicit Condition(MutexLock& mutex)
    : mutex_(mutex) {
    XCHECK(!pthread_cond_init(&pcond_, NULL));
  }
 
  ~Condition() {
    XCHECK(!pthread_cond_destroy(&pcond_));
  }
 
  void Wait() {
    XCHECK(!pthread_cond_wait(&pcond_, mutex_.GetPthreadMutex()));
  }
 
  void Notify() {
    XCHECK(!pthread_cond_signal(&pcond_));
  }
 
  void NotifyAll() {
    XCHECK(!pthread_cond_broadcast(&pcond_));
  }
 
 private:
  MutexLock& mutex_;
  pthread_cond_t pcond_;
}; // class Condition
 
} // namespace limonp
 
#endif // LIMONP_CONDITION_HPP