20 #ifndef RIPPLE_CORE_CLOSURE_COUNTER_H_INCLUDED
21 #define RIPPLE_CORE_CLOSURE_COUNTER_H_INCLUDED
23 #include <ripple/basics/Log.h>
24 #include <boost/optional.hpp>
39 template <
typename Ret_t,
typename... Args_t>
76 template <
typename Closure>
86 "Closure arguments don't match ClosureCounter Ret_t or Args_t");
126 return closure_(std::forward<Args_t>(args)...);
141 using namespace std::chrono_literals;
159 lock, wait, [
this] { return closureCount_ == 0; }))
161 if (
auto stream = j.
error())
162 stream << name <<
" waiting for ClosureCounter::join().";
176 template <
class Closure>
177 boost::optional<Wrapper<Closure>>
180 boost::optional<Wrapper<Closure>> ret;
184 ret.emplace(*
this, std::forward<Closure>(closure));
212 #endif // RIPPLE_CORE_CLOSURE_COUNTER_H_INCLUDED
Ret_t operator()(Args_t... args)
beast::Journal debugLog()
Returns a debug journal.
ClosureCounter & operator--()
~ClosureCounter()
Destructor verifies all in-flight closures are complete.
std::condition_variable allClosuresDoneCond_
ClosureCounter & operator++()
std::remove_reference_t< Closure > closure_
ClosureCounter & counter_
A generic endpoint for log messages.
boost::optional< Wrapper< Closure > > wrap(Closure &&closure)
Wrap the passed closure with a reference counter.
ClosureCounter & operator=(ClosureCounter const &)=delete
Wrapper & operator=(Wrapper const &rhs)=delete
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Wrapper(Wrapper const &rhs)
void join(char const *name, std::chrono::milliseconds wait, beast::Journal j)
Returns once all counted in-flight closures are destroyed.
int count() const
Current number of Closures outstanding.
std::atomic< int > closureCount_
Wrapper(Wrapper &&rhs) noexcept(std::is_nothrow_move_constructible< Closure >::value)
Wrapper(ClosureCounter &counter, Closure &&closure)
bool joined() const
Returns true if this has been joined.