condvar.h 791 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #pragma once
  2. #include "events.h"
  3. #include "mutex.h"
  4. class TContCondVar {
  5. public:
  6. int WaitD(TCont* current, TContMutex* mutex, TInstant deadline) {
  7. mutex->UnLock();
  8. const int ret = WaitQueue_.WaitD(current, deadline);
  9. if (ret != EWAKEDUP) {
  10. return ret;
  11. }
  12. return mutex->LockD(current, deadline);
  13. }
  14. int WaitT(TCont* current, TContMutex* mutex, TDuration timeout) {
  15. return WaitD(current, mutex, timeout.ToDeadLine());
  16. }
  17. int WaitI(TCont* current, TContMutex* mutex) {
  18. return WaitD(current, mutex, TInstant::Max());
  19. }
  20. void Signal() noexcept {
  21. WaitQueue_.Signal();
  22. }
  23. void BroadCast() noexcept {
  24. WaitQueue_.BroadCast();
  25. }
  26. private:
  27. TContWaitQueue WaitQueue_;
  28. };