Resurgence (PY2022)
Codebase for the Husky Robotics 2021-2022 rover Resurgence
Toggle main menu visibility
Loading...
Searching...
No Matches
src
utils
threading.h
1
#pragma once
2
3
#include <
chrono
>
4
#include <
condition_variable
>
5
#include <
mutex
>
6
7
namespace
util
{
8
17
class
latch
{
18
public
:
24
latch
(std::size_t count);
25
26
latch
(
const
latch
&) =
delete
;
27
28
latch
& operator=(
const
latch
&) =
delete
;
29
33
void
wait
()
const
;
34
41
template
<
typename
Rep,
typename
Period>
42
bool
wait_for
(
const
std::chrono::duration<Rep, Period>
& dur)
const
{
43
std::unique_lock
lock
(mutex);
44
return
cv
.wait_for(
lock
, dur, [&]() {
return
count == 0; });
45
}
46
53
template
<
typename
Clock,
typename
Duration>
54
bool
wait_until
(
const
std::chrono::time_point<Clock, Duration>
& tp)
const
{
55
std::unique_lock
lock
(mutex);
56
return
cv
.wait_until(
lock
, tp, [&]() {
return
count == 0; });
57
}
58
66
void
count_down
(std::size_t n = 1);
67
68
private
:
69
std::size_t
count
;
70
mutable
std::mutex
mutex;
71
mutable
std::condition_variable
cv
;
72
};
73
74
}
// namespace util
chrono
condition_variable
mutex
count
iterator_traits< _InputIterator >::difference_type count(_InputIterator __first, _InputIterator __last, const _Tp &__value)
lock
void lock(_L1 &__l1, _L2 &__l2, _L3 &... __l3)
std::chrono::duration
std::chrono::time_point
std::condition_variable
std::mutex
std::unique_lock
util::latch::wait_until
bool wait_until(const std::chrono::time_point< Clock, Duration > &tp) const
Wait until the latch is unlocked until a specific timepoint.
Definition
threading.h:54
util::latch::wait
void wait() const
Wait until the latch is unlocked.
Definition
threading.cpp:7
util::latch::count_down
void count_down(std::size_t n=1)
Counts down the internal counter.
Definition
threading.cpp:12
util::latch::latch
latch(std::size_t count)
Create a new latch.
Definition
threading.cpp:5
util::latch::wait_for
bool wait_for(const std::chrono::duration< Rep, Period > &dur) const
Wait until the latch is unlocked, with a timeout.
Definition
threading.h:42
cv
util
A collection of utility functions and classes with common use-cases.
Definition
SwerveController.cpp:145
Generated by
1.17.0