kernel/locks: Implement lock switching for recursive_lock.

This allows switching from another recursive_lock, mutex or read-locked
rw_lock analogous to the switching possibilities already in mutex.

With this, recursive_locks can be used in more complex situations where
previously only mutexes would work.

Also add debugger command to dump a recursive_lock.

Change-Id: Ibeeae1b42c543d925dec61a3b257e1f3df7f8934
Reviewed-on: https://review.haiku-os.org/c/haiku/+/2834
Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
Michael Lotz
2020-05-30 01:47:40 +00:00
committed by waddlesplash
parent 38963e7596
commit 57656b93b6
2 changed files with 168 additions and 4 deletions
+13
View File
@@ -126,6 +126,19 @@ 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 status_t recursive_lock_switch_lock(recursive_lock* from,
recursive_lock* to);
// Unlocks "from" and locks "to" such that unlocking and starting to wait
// for the lock is atomic. I.e. if "from" guards the object "to" belongs
// to, the operation is safe as long as "from" is held while destroying
// "to".
extern status_t recursive_lock_switch_from_mutex(mutex* from,
recursive_lock* to);
// Like recursive_lock_switch_lock(), just for switching from a mutex.
extern status_t recursive_lock_switch_from_read_lock(rw_lock* from,
recursive_lock* to);
// Like recursive_lock_switch_lock(), just for switching from a read-locked
// rw_lock.
extern int32 recursive_lock_get_recursion(recursive_lock *lock);
extern void rw_lock_init(rw_lock* lock, const char* name);