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>
74 template <
typename Closure>
83 closure_(std::declval<Args_t>()...)), Ret_t>::value,
84 "Closure arguments don't match ClosureCounter Ret_t or Args_t");
124 return closure_ (std::forward<Args_t>(args)...);
138 using namespace std::chrono_literals;
156 lock, wait, [
this] { return closureCount_ == 0; }))
158 if (
auto stream = j.
error())
160 <<
" waiting for ClosureCounter::join().";
174 template <
class Closure>
175 boost::optional<Wrapper<Closure>>
178 boost::optional<Wrapper<Closure>> ret;
182 ret.emplace (*
this, std::forward<Closure> (closure));
208 #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.