mirror of
https://github.com/genodelabs/genode.git
synced 2024-12-23 23:42:32 +00:00
parent
9572ff9413
commit
340a18007c
@ -320,6 +320,57 @@ extern "C" {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int trylock()
|
||||
{
|
||||
if (mutexattr.type == PTHREAD_MUTEX_RECURSIVE) {
|
||||
|
||||
Lock::Guard lock_guard(owner_and_counter_lock);
|
||||
|
||||
if (lock_count == 0) {
|
||||
owner = pthread_self();
|
||||
lock_count++;
|
||||
mutex_lock.lock();
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* the mutex is already locked */
|
||||
if (pthread_self() == owner) {
|
||||
lock_count++;
|
||||
return 0;
|
||||
} else {
|
||||
return EBUSY;
|
||||
}
|
||||
}
|
||||
|
||||
if (mutexattr.type == PTHREAD_MUTEX_ERRORCHECK) {
|
||||
|
||||
Lock::Guard lock_guard(owner_and_counter_lock);
|
||||
|
||||
if (lock_count == 0) {
|
||||
owner = pthread_self();
|
||||
mutex_lock.lock();
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* the mutex is already locked */
|
||||
if (pthread_self() != owner) {
|
||||
return EBUSY;
|
||||
} else
|
||||
return EDEADLK;
|
||||
}
|
||||
|
||||
/* PTHREAD_MUTEX_NORMAL or PTHREAD_MUTEX_DEFAULT */
|
||||
Lock::Guard lock_guard(owner_and_counter_lock);
|
||||
|
||||
if (lock_count == 0) {
|
||||
owner = pthread_self();
|
||||
mutex_lock.lock();
|
||||
return 0;
|
||||
}
|
||||
|
||||
return EBUSY;
|
||||
}
|
||||
|
||||
int unlock()
|
||||
{
|
||||
|
||||
@ -431,6 +482,18 @@ extern "C" {
|
||||
}
|
||||
|
||||
|
||||
int pthread_mutex_trylock(pthread_mutex_t *mutex)
|
||||
{
|
||||
if (!mutex)
|
||||
return EINVAL;
|
||||
|
||||
if (*mutex == PTHREAD_MUTEX_INITIALIZER)
|
||||
pthread_mutex_init(mutex, 0);
|
||||
|
||||
return (*mutex)->trylock();
|
||||
}
|
||||
|
||||
|
||||
int pthread_mutex_unlock(pthread_mutex_t *mutex)
|
||||
{
|
||||
if (!mutex)
|
||||
|
Loading…
Reference in New Issue
Block a user