Skip to content
Snippets Groups Projects
Commit a3f4d939 authored by John Hodge's avatar John Hodge
Browse files

Kernel - Detect recursive mutex locks

parent c83f5c70
Branches
No related merge requests found
...@@ -18,6 +18,7 @@ pub struct Mutex<T: Send> ...@@ -18,6 +18,7 @@ pub struct Mutex<T: Send>
pub struct MutexInner pub struct MutexInner
{ {
held: bool, held: bool,
holder: ::threads::ThreadID,
queue: ::threads::WaitQueue, queue: ::threads::WaitQueue,
} }
...@@ -44,6 +45,7 @@ impl<T: Send> Mutex<T> ...@@ -44,6 +45,7 @@ impl<T: Send> Mutex<T>
Mutex { Mutex {
inner: ::sync::Spinlock::new(MutexInner { inner: ::sync::Spinlock::new(MutexInner {
held: false, held: false,
holder: 0,
queue: ::threads::WaitQueue::new(), queue: ::threads::WaitQueue::new(),
}), }),
val: ::core::cell::UnsafeCell::new(val), val: ::core::cell::UnsafeCell::new(val),
...@@ -59,14 +61,17 @@ impl<T: Send> Mutex<T> ...@@ -59,14 +61,17 @@ impl<T: Send> Mutex<T>
let mut lh = self.inner.lock(); let mut lh = self.inner.lock();
if lh.held != false if lh.held != false
{ {
assert!(lh.holder != ::threads::get_thread_id(), "Recursive lock of {}", type_name!(Self));
// If mutex is locked, then wait for it to be unlocked // If mutex is locked, then wait for it to be unlocked
// - ThreadList::wait will release the passed spinlock // - ThreadList::wait will release the passed spinlock
waitqueue_wait_ext!(lh, .queue); waitqueue_wait_ext!(lh, .queue);
// lh.queue.wait(lh); // << Trips borrowck // lh.queue.wait(lh); // << Trips borrowck
self.inner.lock().holder = ::threads::get_thread_id();
} }
else else
{ {
lh.held = true; lh.held = true;
lh.holder = ::threads::get_thread_id();
} }
} }
::core::sync::atomic::fence(::core::sync::atomic::Ordering::Acquire); ::core::sync::atomic::fence(::core::sync::atomic::Ordering::Acquire);
......
...@@ -13,7 +13,7 @@ mod worker_thread; ...@@ -13,7 +13,7 @@ mod worker_thread;
mod sleep_object; mod sleep_object;
pub use self::thread::{Thread,ThreadPtr}; pub use self::thread::{Thread,ThreadPtr,ThreadID};
pub use self::thread::{ThreadHandle,ProcessHandle}; pub use self::thread::{ThreadHandle,ProcessHandle};
pub use self::thread::new_idle_thread; pub use self::thread::new_idle_thread;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment