distortos  v0.4.0
object-oriented C++ RTOS for microcontrollers
OnceFlag.hpp
Go to the documentation of this file.
1 
12 #ifndef INCLUDE_DISTORTOS_ONCEFLAG_HPP_
13 #define INCLUDE_DISTORTOS_ONCEFLAG_HPP_
14 
15 #include "distortos/Mutex.hpp"
16 
17 namespace distortos
18 {
19 
29 class OnceFlag
30 {
31  template<typename Function, typename... Args>
32  friend void callOnce(OnceFlag& onceFlag, Function&& function, Args&&... args);
33 
34 public:
35 
40  constexpr OnceFlag() :
41  mutex_{},
42  done_{}
43  {
44 
45  }
46 
47 private:
48 
51 
53  volatile bool done_;
54 };
55 
56 } // namespace distortos
57 
58 #endif // INCLUDE_DISTORTOS_ONCEFLAG_HPP_
constexpr OnceFlag()
OnceFlag&#39;s constructor.
Definition: OnceFlag.hpp:40
friend void callOnce(OnceFlag &onceFlag, Function &&function, Args &&... args)
Executes the callable object exactly once, even if called from multiple threads.
Definition: callOnce.hpp:44
Mutex class header.
Mutex mutex_
internal mutex used by callOnce()
Definition: OnceFlag.hpp:50
Top-level namespace of distortos project.
Mutex is the basic synchronization primitive.
Definition: Mutex.hpp:30
volatile bool done_
tells whether any function was already called for this object (true) or not (false) ...
Definition: OnceFlag.hpp:53
OnceFlag is a helper class for callOnce().
Definition: OnceFlag.hpp:29