chsvlib
chsv helper source code

◆ chsv_once()

void Chusov::ExecutionControl::chsv_once ( chsv_once_t flag,
void(*)(void)  func 
)

The function uses a specified once flag to ensure that a specified function is called exactly once, the first time the function is called with that value of the flag.

Parameters
[in]flagis a pointer to a once flag initialized assigning a value that the CHSV_ONCE_INIT macro returns.
[in]funcis a pointer to a protected function.
Returns
The function returns nothing.

The chsv_once function uses the chsv_once_t pointed to by flag to ensure that func is called exactly once, the first time the chsv_once function is called with that value of the flag. Completion of an effective call to the chsv_once function synchronizes with all subsequent calls to the chsv_once function with the same value of flag.

The function implements a behaviour of the call_once function defined in the ISO/IEC 9899:2011 (aka C11) standard. chsv_once_t is an equivalent of once_flag and CHSV_ONCE_INIT is equivalent to ONCE_FLAG_INIT macro.

The chsvlib provides an extension: the chsv_once_ex function which allows to pass a pointer to the called function and returns a flag which allows error control.