12 #ifndef INCLUDE_DISTORTOS_CALLONCE_HPP_ 13 #define INCLUDE_DISTORTOS_CALLONCE_HPP_ 44 template<
typename Function,
typename... Args>
49 if (onceFlag.
done_ ==
true)
52 const std::lock_guard<Mutex> lockGuard {onceFlag.
mutex_};
54 if (onceFlag.
done_ ==
true)
57 estd::invoke(std::forward<Function>(
function), std::forward<Args>(args)...);
58 onceFlag.
done_ =
true;
63 #endif // INCLUDE_DISTORTOS_CALLONCE_HPP_ CHECK_FUNCTION_CONTEXT() macro.
Mutex mutex_
internal mutex used by callOnce()
Definition: OnceFlag.hpp:50
void callOnce(OnceFlag &onceFlag, Function &&function, Args &&... args)
Executes the callable object exactly once, even if called from multiple threads.
Definition: callOnce.hpp:45
Top-level namespace of distortos project.
Definition: buttons.hpp:33
#define CHECK_FUNCTION_CONTEXT()
Macro used to check whether the function is executed from thread context.
Definition: CHECK_FUNCTION_CONTEXT.hpp:29
volatile bool done_
tells whether any function was already called for this object (true) or not (false)
Definition: OnceFlag.hpp:53
auto invoke(Function &&function, Args &&... args) -> decltype(internal::invoke(std::forward< Function >(function), std::forward< Args >(args)...))
Invokes callable object in an appropriate way.
Definition: invoke.hpp:139
OnceFlag is a helper class for callOnce().
Definition: OnceFlag.hpp:29