wait_proxy.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #pragma once
  2. ///
  3. /// @file yt/cpp/mapreduce/interface/serialize.h
  4. ///
  5. /// Header containing interface to enable customizable waiting.
  6. #include <yt/cpp/mapreduce/interface/common.h>
  7. #include <util/datetime/base.h>
  8. namespace NThreading {
  9. template <typename T>
  10. class TFuture;
  11. }
  12. class TSystemEvent;
  13. class TCondVar;
  14. class TMutex;
  15. namespace NYT {
  16. ////////////////////////////////////////////////////////////////////////////////
  17. ///
  18. /// @brief Interface to facilitate customizable waiting.
  19. ///
  20. /// All the waiting functions in the library are obliged to use the methods of a wait proxy instead of direct function calls.
  21. class IWaitProxy
  22. : public TThrRefBase
  23. {
  24. public:
  25. virtual ~IWaitProxy() = default;
  26. ///
  27. /// @brief Wait for the future setting with timeout.
  28. virtual bool WaitFuture(const ::NThreading::TFuture<void>& future, TDuration timeout) = 0;
  29. ///
  30. /// @brief Wait for a system event with timeout.
  31. virtual bool WaitEvent(TSystemEvent& event, TDuration timeout) = 0;
  32. ///
  33. /// @brief Wait for the notification on the condition variable with timeout.
  34. virtual bool WaitCondVar(TCondVar& condVar, TMutex& mutex, TDuration timeout) = 0;
  35. ///
  36. /// @brief Sleep in the current thread for (approximately) specified amount of time.
  37. virtual void Sleep(TDuration timeout) = 0;
  38. };
  39. ////////////////////////////////////////////////////////////////////////////////
  40. } // namespace NYT