aboutsummaryrefslogtreecommitdiffstats
path: root/yt/cpp/mapreduce/common/wait_proxy.h
blob: e7c944cf24e22683234f8000c7c1325ff2cd3e8b (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
#pragma once

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

namespace NYT {
namespace NDetail {

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

class TDefaultWaitProxy
    : public IWaitProxy
{
public:
    bool WaitFuture(const ::NThreading::TFuture<void>& future, TDuration timeout) override;
    bool WaitEvent(TSystemEvent& event, TDuration timeout) override;
    bool WaitCondVar(TCondVar& condVar, TMutex& mutex, TDuration timeout) override;
    void Sleep(TDuration timeout) override;
};

class TWaitProxy {
public:
    TWaitProxy();

    static TWaitProxy* Get();

    // NB: Non thread-safe, should be called only in initialization code.
    void SetProxy(::TIntrusivePtr<IWaitProxy> proxy);

    bool WaitFuture(const ::NThreading::TFuture<void>& future);
    bool WaitFuture(const ::NThreading::TFuture<void>& future, TInstant deadLine);
    bool WaitFuture(const ::NThreading::TFuture<void>& future, TDuration timeout);

    bool WaitEventD(TSystemEvent& event, TInstant deadLine);
    bool WaitEventT(TSystemEvent& event, TDuration timeout);
    void WaitEventI(TSystemEvent& event);
    bool WaitEvent(TSystemEvent& event);

    bool WaitCondVarD(TCondVar& condVar, TMutex& m, TInstant deadLine);
    bool WaitCondVarT(TCondVar& condVar, TMutex& m, TDuration timeOut);
    void WaitCondVarI(TCondVar& condVar, TMutex& m);
    void WaitCondVar(TCondVar& condVar, TMutex& m);

    void Sleep(TDuration timeout);
    void SleepUntil(TInstant instant);

private:
    ::TIntrusivePtr<IWaitProxy> Proxy_;
};

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

} // namespace NDetail
} // namespace NYT