MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / pthread_once

Function pthread_once

components/libc/posix/pthreads/pthread.c:1038–1055  ·  view source on GitHub ↗

* @brief Executes a routine once in a multithreaded environment. * * The `pthread_once` function ensures that the specified initialization routine is executed exactly once, * even if multiple threads attempt to execute it simultaneously. It is typically used for one-time * initialization tasks in a multithreaded program. * * @param[in] once_control * A pointer to a `pthread_once_t` contro

Source from the content-addressed store, hash-verified

1036 * @see pthread_mutex_lock, pthread_mutex_unlock
1037 */
1038int pthread_once(pthread_once_t *once_control, void (*init_routine)(void))
1039{
1040 RT_ASSERT(once_control != RT_NULL);
1041 RT_ASSERT(init_routine != RT_NULL);
1042
1043 rt_enter_critical();
1044 if (!(*once_control))
1045 {
1046 /* call routine once */
1047 *once_control = 1;
1048 rt_exit_critical();
1049
1050 init_routine();
1051 }
1052 rt_exit_critical();
1053
1054 return 0;
1055}
1056RTM_EXPORT(pthread_once);
1057
1058int pthread_atfork(void (*prepare)(void), void (*parent)(void), void (*child)(void))

Callers 2

emutls_get_indexFunction · 0.85
str_accumulateFunction · 0.85

Calls 2

rt_enter_criticalFunction · 0.50
rt_exit_criticalFunction · 0.50

Tested by

no test coverage detected