summaryrefslogtreecommitdiff
path: root/Libraries/LibPthread/pthread.cpp
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-12-07 14:32:48 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-12-07 14:52:27 +0100
commitbabb72621221572f6cf2ae3a1171e924b7bb12f1 (patch)
treea0d3fea53d67b17dc5d6a6b5f80cf306b015511c /Libraries/LibPthread/pthread.cpp
parent594c7f2d83ce3bcc2d5db840be199e8574283504 (diff)
downloadserenity-babb72621221572f6cf2ae3a1171e924b7bb12f1.zip
LibPthread: Implement pthread_mutex_trylock()
Diffstat (limited to 'Libraries/LibPthread/pthread.cpp')
-rw-r--r--Libraries/LibPthread/pthread.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/Libraries/LibPthread/pthread.cpp b/Libraries/LibPthread/pthread.cpp
index 009e7018d7..8c35406dc1 100644
--- a/Libraries/LibPthread/pthread.cpp
+++ b/Libraries/LibPthread/pthread.cpp
@@ -111,6 +111,15 @@ int pthread_mutex_lock(pthread_mutex_t* mutex)
}
}
+int pthread_mutex_trylock(pthread_mutex_t* mutex)
+{
+ auto* atomic = reinterpret_cast<Atomic<u32>*>(mutex);
+ u32 expected = false;
+ if (atomic->compare_exchange_strong(expected, true, AK::memory_order_acq_rel))
+ return 0;
+ return EBUSY;
+}
+
int pthread_mutex_unlock(pthread_mutex_t* mutex)
{
auto* atomic = reinterpret_cast<Atomic<u32>*>(mutex);