LibC: Implement pthread_once

This commit is contained in:
2025-04-21 14:01:38 +03:00
parent 2cbfe70a28
commit 5d8dd090a9
2 changed files with 18 additions and 1 deletions

View File

@@ -312,6 +312,22 @@ pthread_t pthread_self(void)
#endif
}
int pthread_once(pthread_once_t* once_control, void (*init_routine)(void))
{
static_assert(PTHREAD_ONCE_INIT == 0);
pthread_once_t expected = 0;
if (BAN::atomic_compare_exchange(*once_control, expected, 1))
{
init_routine();
BAN::atomic_store(*once_control, 2);
}
while (BAN::atomic_load(*once_control) != 2)
sched_yield();
return 0;
}
int pthread_spin_destroy(pthread_spinlock_t* lock)
{
(void)lock;