summaryrefslogtreecommitdiff
path: root/Libraries/LibPthread/pthread.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Libraries/LibPthread/pthread.cpp')
-rw-r--r--Libraries/LibPthread/pthread.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/Libraries/LibPthread/pthread.cpp b/Libraries/LibPthread/pthread.cpp
index b659d376d1..b1e17b1f61 100644
--- a/Libraries/LibPthread/pthread.cpp
+++ b/Libraries/LibPthread/pthread.cpp
@@ -1,7 +1,9 @@
+#include <AK/Atomic.h>
#include <AK/StdLibExtras.h>
#include <Kernel/Syscall.h>
#include <pthread.h>
#include <unistd.h>
+#include <stdio.h>
extern "C" {
@@ -27,4 +29,31 @@ int pthread_join(pthread_t thread, void** exit_value_ptr)
int rc = syscall(SC_join_thread, thread, exit_value_ptr);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
+
+int pthread_mutex_init(pthread_mutex_t* mutex, const pthread_mutexattr_t* attributes)
+{
+ // FIXME: Implement mutex attributes
+ UNUSED_PARAM(attributes);
+ *mutex = 0;
+ return 0;
+}
+
+int pthread_mutex_lock(pthread_mutex_t* mutex)
+{
+ auto* atomic = reinterpret_cast<Atomic<u32>*>(mutex);
+ for (;;) {
+ u32 expected = false;
+ if (atomic->compare_exchange_strong(expected, true, AK::memory_order_acq_rel))
+ return 0;
+ sched_yield();
+ }
+}
+
+int pthread_mutex_unlock(pthread_mutex_t* mutex)
+{
+ auto* atomic = reinterpret_cast<Atomic<u32>*>(mutex);
+ atomic->store(false, AK::memory_order_release);
+ return 0;
+}
+
}