diff --git a/libs/libc/pthread/pthread_once.c b/libs/libc/pthread/pthread_once.c index 05d3b995a0d91..56afb8fe71357 100644 --- a/libs/libc/pthread/pthread_once.c +++ b/libs/libc/pthread/pthread_once.c @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include /**************************************************************************** @@ -61,6 +61,8 @@ * ****************************************************************************/ +static mutex_t g_lock = NXMUTEX_INITIALIZER; + int pthread_once(FAR pthread_once_t *once_control, CODE void (*init_routine)(void)) { @@ -73,7 +75,7 @@ int pthread_once(FAR pthread_once_t *once_control, /* Prohibit pre-emption while we test and set the once_control. */ - sched_lock(); + nxmutex_lock(&g_lock); if (!*once_control) { @@ -81,8 +83,8 @@ int pthread_once(FAR pthread_once_t *once_control, /* Call the init_routine with pre-emption enabled. */ - sched_unlock(); init_routine(); + nxmutex_unlock(&g_lock); return OK; } @@ -90,6 +92,6 @@ int pthread_once(FAR pthread_once_t *once_control, * Restore pre-emption and return. */ - sched_unlock(); + nxmutex_unlock(&g_lock); return OK; }