libc: pthread: implement mutexes

This commit is contained in:
2026-07-19 13:31:22 +01:00
parent 6317060138
commit 810f741442
4 changed files with 57 additions and 1 deletions
@@ -0,0 +1,24 @@
#include <errno.h>
#include <magenta/futex.h>
#include <pthread.h>
int pthread_mutex_lock(pthread_mutex_t *mut)
{
kern_futex_t expected = 0;
while (1) {
expected = 0;
if (__atomic_compare_exchange_n(
&mut->__v,
&expected,
1,
0,
__ATOMIC_ACQUIRE,
__ATOMIC_ACQUIRE)) {
return 0;
}
futex_wait(&mut->__v, 1, FUTEX_PRIVATE);
}
return __set_errno(EAGAIN);
}