distortos  v0.7.0
object-oriented C++ RTOS for microcontrollers
distortos::OnceFlag Class Reference

OnceFlag is a helper class for callOnce(). More...

#include "distortos/OnceFlag.hpp"

Collaboration diagram for distortos::OnceFlag:
[legend]

Public Member Functions

constexpr OnceFlag ()
 OnceFlag's constructor. More...
 

Private Attributes

Mutex mutex_
 internal mutex used by callOnce() More...
 
volatile bool done_
 tells whether any function was already called for this object (true) or not (false) More...
 

Friends

template<typename Function , typename... Args>
void callOnce (OnceFlag &onceFlag, Function &&function, Args &&... args)
 Executes the callable object exactly once, even if called from multiple threads. More...
 

Detailed Description

Constructor & Destructor Documentation

◆ OnceFlag()

constexpr distortos::OnceFlag::OnceFlag ( )
inline

OnceFlag's constructor.

Friends And Related Function Documentation

◆ callOnce

template<typename Function , typename... Args>
void callOnce ( OnceFlag onceFlag,
Function &&  function,
Args &&...  args 
)
friend

Executes the callable object exactly once, even if called from multiple threads.

Similar to std::call_once() - http://en.cppreference.com/w/cpp/thread/call_once Similar to POSIX pthread_once() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_once.html#

Warning
This function must not be called from interrupt context!
Template Parameters
Functionis the function object that will be executed
Argsare the arguments for Function
Parameters
[in]onceFlagis a reference to shared OnceFlag object
[in]functionis the function object that will be executed
[in]argsare arguments for function

Member Data Documentation

◆ done_

volatile bool distortos::OnceFlag::done_
private

tells whether any function was already called for this object (true) or not (false)

◆ mutex_

Mutex distortos::OnceFlag::mutex_
private

internal mutex used by callOnce()


The documentation for this class was generated from the following file: