LibC: Make pthread_once block with a futex instead of yielding

This commit is contained in:
2026-07-20 04:07:23 +03:00
parent 0242a4f968
commit 46e2d665e9
2 changed files with 7 additions and 3 deletions
@@ -13,7 +13,7 @@ __BEGIN_DECLS
#include <stdint.h>
typedef int pthread_once_t;
typedef uint32_t pthread_once_t;
typedef pthread_t pthread_spinlock_t;
+6 -2
View File
@@ -591,10 +591,14 @@ int pthread_once(pthread_once_t* once_control, void (*init_routine)(void))
{
init_routine();
BAN::atomic_store(*once_control, 2);
futex(FUTEX_WAKE_PRIVATE, once_control, -1, nullptr);
}
else
{
while (BAN::atomic_load(*once_control) == 1)
futex(FUTEX_WAIT_PRIVATE, once_control, 1, nullptr);
}
while (BAN::atomic_load(*once_control) != 2)
sched_yield();
return 0;
}