chsvlib
chsv helper source code

◆ chsv_once_ex()

bool Chusov::ExecutionControl::chsv_once_ex ( chsv_once_t flag,
void(*)(void *)  func,
void *  pParam 
)

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. This is an extension to the C11 standard conforming chsv_once function.

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.
[in]pParamis a pointer to a user-defined parameter passed to the func "as-is".
Returns
The function returns a nonzero value on success and zero on failure setting a corresponding errno code.

The chsv_once_ex 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 extends functionality of chsv_once, which 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.