From 3cb491273caa21876711e9b67d01aac33fee61c9 Mon Sep 17 00:00:00 2001 From: Avi Kivity <avi.kivity@gmail.com> Date: Mon, 7 Jan 2013 16:33:54 +0200 Subject: [PATCH] pthread: implement mutex_lock, unlock, trylock() --- libc/pthread.cc | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/libc/pthread.cc b/libc/pthread.cc index 3f215e3ab..9df4259d5 100644 --- a/libc/pthread.cc +++ b/libc/pthread.cc @@ -54,3 +54,26 @@ int pthread_mutex_init(pthread_mutex_t* __restrict m, new (m) mutex; return 0; } + +int pthread_mutex_lock(pthread_mutex_t *m) +{ + mutex* mm = reinterpret_cast<mutex*>(m); + mm->lock(); + return 0; +} + +int pthread_mutex_trylock(pthread_mutex_t *m) +{ + mutex* mm = reinterpret_cast<mutex*>(m); + if (!mm->try_lock()) { + return -EBUSY; + } + return 0; +} + +int pthread_mutex_unlock(pthread_mutex_t *m) +{ + mutex* mm = reinterpret_cast<mutex*>(m); + mm->unlock(); + return 0; +} -- GitLab