* Added a mutex_trylock() function.
* Replaced release_sem() with release_sem_etc() for future addition of the B_DO_NOT_RESCHEDULE flag. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22308 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -61,6 +61,7 @@ extern int32 recursive_lock_get_recursion(recursive_lock *lock);
|
|||||||
|
|
||||||
extern status_t mutex_init(mutex *m, const char *name);
|
extern status_t mutex_init(mutex *m, const char *name);
|
||||||
extern void mutex_destroy(mutex *m);
|
extern void mutex_destroy(mutex *m);
|
||||||
|
extern status_t mutex_trylock(mutex *mutex);
|
||||||
extern status_t mutex_lock(mutex *m);
|
extern status_t mutex_lock(mutex *m);
|
||||||
extern void mutex_unlock(mutex *m);
|
extern void mutex_unlock(mutex *m);
|
||||||
|
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ recursive_lock_unlock(recursive_lock *lock)
|
|||||||
|
|
||||||
if (--lock->recursion == 0) {
|
if (--lock->recursion == 0) {
|
||||||
lock->holder = -1;
|
lock->holder = -1;
|
||||||
release_sem(lock->sem);
|
release_sem_etc(lock->sem, 1, 0/*B_DO_NOT_RESCHEDULE*/);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,6 +128,29 @@ mutex_destroy(mutex *mutex)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
mutex_trylock(mutex *mutex)
|
||||||
|
{
|
||||||
|
thread_id me = thread_get_current_thread_id();
|
||||||
|
status_t status;
|
||||||
|
|
||||||
|
if (kernel_startup)
|
||||||
|
return B_OK;
|
||||||
|
|
||||||
|
status = acquire_sem_etc(mutex->sem, 1, B_RELATIVE_TIMEOUT, 0);
|
||||||
|
if (status < B_OK)
|
||||||
|
return status;
|
||||||
|
|
||||||
|
if (me == mutex->holder) {
|
||||||
|
panic("mutex_trylock failure: mutex %p (sem = 0x%lx) acquired twice by"
|
||||||
|
" thread 0x%lx\n", mutex, mutex->sem, me);
|
||||||
|
}
|
||||||
|
|
||||||
|
mutex->holder = me;
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
mutex_lock(mutex *mutex)
|
mutex_lock(mutex *mutex)
|
||||||
{
|
{
|
||||||
@@ -165,7 +188,7 @@ mutex_unlock(mutex *mutex)
|
|||||||
}
|
}
|
||||||
|
|
||||||
mutex->holder = -1;
|
mutex->holder = -1;
|
||||||
release_sem(mutex->sem);
|
release_sem_etc(mutex->sem, 1, 0/*B_DO_NOT_RESCHEDULE*/);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -235,7 +258,7 @@ rw_lock_read_lock(rw_lock *lock)
|
|||||||
status_t
|
status_t
|
||||||
rw_lock_read_unlock(rw_lock *lock)
|
rw_lock_read_unlock(rw_lock *lock)
|
||||||
{
|
{
|
||||||
return release_sem(lock->sem);
|
return release_sem_etc(lock->sem, 1, 0/*B_DO_NOT_RESCHEDULE*/);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user