aboutsummaryrefslogtreecommitdiffstats
path: root/yt/cpp/mapreduce/interface/wait_proxy.h
blob: f7d8e0638e9f5f54e5e63f3cc5088cf10832a654 (plain) (blame)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#pragma once

///
/// @file yt/cpp/mapreduce/interface/serialize.h
///
/// Header containing interface to enable customizable waiting.

#include <yt/cpp/mapreduce/interface/common.h>

#include <util/datetime/base.h>

namespace NThreading {
template <typename T>
class TFuture;
}

class TSystemEvent;
class TCondVar;
class TMutex;

namespace NYT {

////////////////////////////////////////////////////////////////////////////////

///
/// @brief Interface to facilitate customizable waiting.
///
/// All the waiting functions in the library are obliged to use the methods of a wait proxy instead of direct function calls.
class IWaitProxy
    : public TThrRefBase
{
public:
    virtual ~IWaitProxy() = default;

    ///
    /// @brief Wait for the future setting with timeout.
    virtual bool WaitFuture(const ::NThreading::TFuture<void>& future, TDuration timeout) = 0;

    ///
    /// @brief Wait for a system event with timeout.
    virtual bool WaitEvent(TSystemEvent& event, TDuration timeout) = 0;

    ///
    /// @brief Wait for the notification on the condition variable with timeout.
    virtual bool WaitCondVar(TCondVar& condVar, TMutex& mutex, TDuration timeout) = 0;

    ///
    /// @brief Sleep in the current thread for (approximately) specified amount of time.
    virtual void Sleep(TDuration timeout) = 0;
};

////////////////////////////////////////////////////////////////////////////////

} // namespace NYT