Resurgence (PY2022)
Codebase for the Husky Robotics 2021-2022 rover Resurgence
Loading...
Searching...
No Matches
util::latch Class Reference

Implementation of a countdown latch for threading synchronization. More...

#include <threading.h>

Public Member Functions

 latch (std::size_t count)
 Create a new latch.
 
 latch (const latch &)=delete
 
latchoperator= (const latch &)=delete
 
void wait () const
 Wait until the latch is unlocked.
 
template<typename Rep, typename Period>
bool wait_for (const std::chrono::duration< Rep, Period > &dur) const
 Wait until the latch is unlocked, with a timeout.
 
template<typename Clock, typename Duration>
bool wait_until (const std::chrono::time_point< Clock, Duration > &tp) const
 Wait until the latch is unlocked until a specific timepoint.
 
void count_down (std::size_t n=1)
 Counts down the internal counter.
 

Detailed Description

Implementation of a countdown latch for threading synchronization.

This has roughly the same interface as std::latch, but that requires C++20, which we do not support.

See also
https://en.cppreference.com/w/cpp/thread/latch

Constructor & Destructor Documentation

◆ latch()

util::latch::latch ( std::size_t count)

Create a new latch.

Parameters
countThis is the number of countdowns before the latch is unlocked.

Member Function Documentation

◆ count_down()

void util::latch::count_down ( std::size_t n = 1)

Counts down the internal counter.

When the counter reaches 0 the latch is unlocked.

Parameters
nThe amount to decrement by.

◆ wait_for()

template<typename Rep, typename Period>
bool util::latch::wait_for ( const std::chrono::duration< Rep, Period > & dur) const
inline

Wait until the latch is unlocked, with a timeout.

Parameters
durThe timeout duration.
Returns
bool True if the latch was unlocked, false if timed out.

◆ wait_until()

template<typename Clock, typename Duration>
bool util::latch::wait_until ( const std::chrono::time_point< Clock, Duration > & tp) const
inline

Wait until the latch is unlocked until a specific timepoint.

Parameters
tpThe timepoint to wait until.
Returns
bool True iff the latch was unlocked before the given time.

The documentation for this class was generated from the following files: