CppCommon
1.0.5.0
C++ Common Library
Loading...
Searching...
No Matches
include
threads
latch.inl
Go to the documentation of this file.
1
9
namespace
CppCommon
{
10
11
inline
Latch::Latch
(
int
threads) noexcept : _generation(0), _threads(threads)
12
{
13
assert((threads > 0) &&
"Latch threads counter must be greater than zero!"
);
14
}
15
16
inline
bool
Latch::TryWaitFor
(
const
Timespan
& timespan)
noexcept
17
{
18
std::unique_lock<std::mutex> lock(_mutex);
19
20
// Check the latch threads counter value
21
if
(_threads == 0)
22
return
true
;
23
24
// Remember the current latch generation
25
int
generation = _generation;
26
27
// Wait for the next latch generation
28
return
_cond.wait_for(lock, timespan.chrono(), [&,
this
]() { return generation != _generation; });
29
}
30
31
inline
bool
Latch::TryWaitUntil
(
const
Timestamp
& timestamp)
noexcept
32
{
33
std::unique_lock<std::mutex> lock(_mutex);
34
35
// Check the latch threads counter value
36
if
(_threads == 0)
37
return
true
;
38
39
// Remember the current latch generation
40
int
generation = _generation;
41
42
// Wait for the next latch generation
43
return
_cond.wait_until(lock, timestamp.chrono(), [&,
this
]() { return generation != _generation; });
44
}
45
46
}
// namespace CppCommon
CppCommon::Latch::TryWaitUntil
bool TryWaitUntil(const Timestamp ×tamp) noexcept
Try to wait for the latch until the given timestamp.
Definition
latch.inl:31
CppCommon::Latch::Latch
Latch(int threads) noexcept
Default class constructor.
Definition
latch.inl:11
CppCommon::Latch::TryWaitFor
bool TryWaitFor(const Timespan ×pan) noexcept
Try to wait for the latch for the given timespan.
Definition
latch.inl:16
CppCommon::Timespan
Timespan.
Definition
timespan.h:27
CppCommon::Timestamp
Timestamp.
Definition
timestamp.h:30
CppCommon
C++ Common project definitions.
Definition
token_bucket.h:15
Generated by
1.9.8