20#ifndef RIPPLE_CORE_CLOSURE_COUNTER_H_INCLUDED
21#define RIPPLE_CORE_CLOSURE_COUNTER_H_INCLUDED
23#include <xrpl/basics/Log.h>
53template <
typename Ret_t,
typename... Args_t>
90 template <
typename Closure>
100 "Closure arguments don't match ClosureCounter Ret_t or Args_t");
155 using namespace std::chrono_literals;
173 lock, wait, [
this] { return closureCount_ == 0; }))
175 if (
auto stream = j.
error())
176 stream << name <<
" waiting for ClosureCounter::join().";
190 template <
class Closure>
A generic endpoint for log messages.
Substitute(Substitute const &rhs)
Substitute(Substitute &&rhs) noexcept(std::is_nothrow_move_constructible< Closure >::value)
std::remove_reference_t< Closure > closure_
Substitute & operator=(Substitute const &rhs)=delete
Substitute & operator=(Substitute &&rhs)=delete
Ret_t operator()(Args_t... args)
ClosureCounter & counter_
Substitute(ClosureCounter &counter, Closure &&closure)
The role of a ClosureCounter is to assist in shutdown by letting callers wait for the completion of c...
bool joined() const
Returns true if this has been joined.
std::optional< Substitute< Closure > > wrap(Closure &&closure)
Wrap the passed closure with a reference counter.
ClosureCounter & operator++()
ClosureCounter(ClosureCounter const &)=delete
std::atomic< int > closureCount_
ClosureCounter & operator--()
int count() const
Current number of Closures outstanding.
ClosureCounter & operator=(ClosureCounter const &)=delete
~ClosureCounter()
Destructor verifies all in-flight closures are complete.
std::condition_variable allClosuresDoneCond_
void join(char const *name, std::chrono::milliseconds wait, beast::Journal j)
Returns once all counted in-flight closures are destroyed.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
beast::Journal debugLog()
Returns a debug journal.