LibC: Make pthread_once block with a futex instead of yielding
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user