aboutsummaryrefslogtreecommitdiffstats
path: root/yt/cpp/mapreduce/common/wait_proxy.cpp
blob: 3db034a09804f83eb1da3535426c5fabba9a1373 (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include "wait_proxy.h"


#include <library/cpp/threading/future/future.h>

#include <util/system/event.h>
#include <util/system/condvar.h>

namespace NYT {
namespace NDetail {

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

bool TDefaultWaitProxy::WaitFuture(const NThreading::TFuture<void>& future, TDuration timeout)
{
    return future.Wait(timeout);
}

bool TDefaultWaitProxy::WaitEvent(TSystemEvent& event, TDuration timeout)
{
    return event.WaitT(timeout);
}

bool TDefaultWaitProxy::WaitCondVar(TCondVar &condVar, TMutex &mutex, TDuration timeout)
{
    return condVar.WaitT(mutex, timeout);
}

void TDefaultWaitProxy::Sleep(TDuration timeout)
{
    ::Sleep(timeout);
}

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

TWaitProxy::TWaitProxy()
    : Proxy_(::MakeIntrusive<TDefaultWaitProxy>())
{ }

TWaitProxy* TWaitProxy::Get()
{
    return Singleton<TWaitProxy>();
}

void TWaitProxy::SetProxy(::TIntrusivePtr<IWaitProxy> proxy)
{
    Proxy_ = std::move(proxy);
}

bool TWaitProxy::WaitFuture(const NThreading::TFuture<void>& future)
{
    return Proxy_->WaitFuture(future, TDuration::Max());
}

bool TWaitProxy::WaitFuture(const NThreading::TFuture<void>& future, TInstant deadLine)
{
    return Proxy_->WaitFuture(future, deadLine - TInstant::Now());
}

bool TWaitProxy::WaitFuture(const NThreading::TFuture<void>& future, TDuration timeout)
{
    return Proxy_->WaitFuture(future, timeout);
}

bool TWaitProxy::WaitEventD(TSystemEvent& event, TInstant deadLine)
{
    return Proxy_->WaitEvent(event, deadLine - TInstant::Now());
}

bool TWaitProxy::WaitEventT(TSystemEvent& event, TDuration timeout)
{
    return Proxy_->WaitEvent(event, timeout);
}

void TWaitProxy::WaitEventI(TSystemEvent& event)
{
    Proxy_->WaitEvent(event, TDuration::Max());
}

bool TWaitProxy::WaitEvent(TSystemEvent& event)
{
    return Proxy_->WaitEvent(event, TDuration::Max());
}

bool TWaitProxy::WaitCondVarD(TCondVar& condVar, TMutex& m, TInstant deadLine)
{
    return Proxy_->WaitCondVar(condVar, m, deadLine - TInstant::Now());
}

bool TWaitProxy::WaitCondVarT(TCondVar& condVar, TMutex& m, TDuration timeOut)
{
    return Proxy_->WaitCondVar(condVar, m, timeOut);
}

void TWaitProxy::WaitCondVarI(TCondVar& condVar, TMutex& m)
{
    Proxy_->WaitCondVar(condVar, m, TDuration::Max());
}

void TWaitProxy::WaitCondVar(TCondVar& condVar, TMutex& m)
{
    Proxy_->WaitCondVar(condVar, m, TDuration::Max());
}

void TWaitProxy::Sleep(TDuration timeout)
{
    Proxy_->Sleep(timeout);
}

void TWaitProxy::SleepUntil(TInstant instant)
{
    Proxy_->Sleep(instant - TInstant::Now());
}

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

} // namespace NDetail
} // namespace NYT