Condition.h 673 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * Condition.h
  3. *
  4. * Created on: Sep 5, 2017
  5. * Author: guoxs
  6. */
  7. #ifndef _SYSTEM_CONDITION_H_
  8. #define _SYSTEM_CONDITION_H_
  9. #include "Mutex.h"
  10. class Condition {
  11. public:
  12. enum {
  13. E_PRIVATE = 0,
  14. E_SHARED = 1
  15. };
  16. typedef enum {
  17. E_WAKE_UP_TYPE_ONE = 0,
  18. E_WAKE_UP_TYPE_ALL = 1
  19. } EWakeUpType;
  20. Condition();
  21. Condition(int type);
  22. virtual ~Condition();
  23. void wait(Mutex &mutex);
  24. void waitRelative(Mutex &mutex, long long reltime);
  25. void signal();
  26. void broadcast();
  27. void signal(EWakeUpType type) {
  28. if (type == E_WAKE_UP_TYPE_ONE) {
  29. signal();
  30. } else {
  31. broadcast();
  32. }
  33. }
  34. private:
  35. pthread_cond_t mCond;
  36. };
  37. #endif /* _SYSTEM_CONDITION_H_ */