* @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
| 1036 | * @see pthread_mutex_lock, pthread_mutex_unlock |
| 1037 | */ |
| 1038 | int 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 | } |
| 1056 | RTM_EXPORT(pthread_once); |
| 1057 | |
| 1058 | int pthread_atfork(void (*prepare)(void), void (*parent)(void), void (*child)(void)) |
no test coverage detected