* Added a recursive_lock_trylock() function.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26297 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
589f1a9133
commit
af370c702a
@ -975,6 +975,7 @@
|
||||
#define recursive_lock_init_etc fssh_recursive_lock_init_etc
|
||||
#define recursive_lock_destroy fssh_recursive_lock_destroy
|
||||
#define recursive_lock_lock fssh_recursive_lock_lock
|
||||
#define recursive_lock_trylock fssh_recursive_lock_trylock
|
||||
#define recursive_lock_unlock fssh_recursive_lock_unlock
|
||||
#define recursive_lock_get_recursion fssh_recursive_lock_get_recursion
|
||||
|
||||
|
@ -55,6 +55,7 @@ extern void fssh_recursive_lock_init_etc(fssh_recursive_lock *lock, const char *
|
||||
uint32_t flags);
|
||||
extern void fssh_recursive_lock_destroy(fssh_recursive_lock *lock);
|
||||
extern fssh_status_t fssh_recursive_lock_lock(fssh_recursive_lock *lock);
|
||||
extern fssh_status_t fssh_recursive_lock_trylock(fssh_recursive_lock *lock);
|
||||
extern void fssh_recursive_lock_unlock(fssh_recursive_lock *lock);
|
||||
extern int32_t fssh_recursive_lock_get_recursion(fssh_recursive_lock *lock);
|
||||
|
||||
|
@ -84,6 +84,7 @@ extern void recursive_lock_init_etc(recursive_lock *lock, const char *name,
|
||||
uint32 flags);
|
||||
extern void recursive_lock_destroy(recursive_lock *lock);
|
||||
extern status_t recursive_lock_lock(recursive_lock *lock);
|
||||
extern status_t recursive_lock_trylock(recursive_lock *lock);
|
||||
extern void recursive_lock_unlock(recursive_lock *lock);
|
||||
extern int32 recursive_lock_get_recursion(recursive_lock *lock);
|
||||
|
||||
|
@ -92,12 +92,37 @@ recursive_lock_lock(recursive_lock *lock)
|
||||
{
|
||||
thread_id thread = thread_get_current_thread_id();
|
||||
|
||||
if (!kernel_startup && !are_interrupts_enabled()) {
|
||||
panic("recursive_lock_lock: called with interrupts disabled for lock "
|
||||
"%p (\"%s\")\n", lock, lock->lock.name);
|
||||
}
|
||||
|
||||
if (thread != RECURSIVE_LOCK_HOLDER(lock)) {
|
||||
mutex_lock(&lock->lock);
|
||||
#ifndef KDEBUG
|
||||
lock->holder = thread;
|
||||
#endif
|
||||
}
|
||||
|
||||
lock->recursion++;
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
recursive_lock_trylock(recursive_lock *lock)
|
||||
{
|
||||
thread_id thread = thread_get_current_thread_id();
|
||||
|
||||
if (!kernel_startup && !are_interrupts_enabled())
|
||||
panic("recursive_lock_lock: called with interrupts disabled for lock "
|
||||
"%p (\"%s\")\n", lock, lock->lock.name);
|
||||
|
||||
if (thread != RECURSIVE_LOCK_HOLDER(lock)) {
|
||||
mutex_lock(&lock->lock);
|
||||
status_t status = mutex_trylock(&lock->lock);
|
||||
if (status != B_OK)
|
||||
return status;
|
||||
|
||||
#ifndef KDEBUG
|
||||
lock->holder = thread;
|
||||
#endif
|
||||
|
@ -71,6 +71,24 @@ fssh_recursive_lock_lock(fssh_recursive_lock *lock)
|
||||
}
|
||||
|
||||
|
||||
extern "C" fssh_status_t
|
||||
fssh_recursive_lock_trylock(fssh_recursive_lock *lock)
|
||||
{
|
||||
fssh_thread_id thread = fssh_find_thread(NULL);
|
||||
|
||||
if (thread != lock->holder) {
|
||||
fssh_status_t status = fssh_acquire_sem_etc(lock->sem, 1,
|
||||
FSSH_B_RELATIVE_TIMEOUT, 0);
|
||||
if (status < FSSH_B_OK)
|
||||
return status;
|
||||
|
||||
lock->holder = thread;
|
||||
}
|
||||
lock->recursion++;
|
||||
return FSSH_B_OK;
|
||||
}
|
||||
|
||||
|
||||
extern "C" void
|
||||
fssh_recursive_lock_unlock(fssh_recursive_lock *lock)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user