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