diff --git a/libs/libc/pthread/pthread_once.c b/libs/libc/pthread/pthread_once.c index 05d3b995a0d91..dd120efe81645 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 /**************************************************************************** @@ -64,6 +64,8 @@ int pthread_once(FAR pthread_once_t *once_control, CODE void (*init_routine)(void)) { + irqstate_t flags; + /* Sanity checks */ if (once_control == NULL || init_routine == NULL) @@ -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(); + flags = enter_critical_section(); if (!*once_control) { @@ -81,7 +83,7 @@ int pthread_once(FAR pthread_once_t *once_control, /* Call the init_routine with pre-emption enabled. */ - sched_unlock(); + leave_critical_section(flags); init_routine(); return OK; } @@ -90,6 +92,6 @@ int pthread_once(FAR pthread_once_t *once_control, * Restore pre-emption and return. */ - sched_unlock(); + leave_critical_section(flags); return OK; }