From 5a42b6dd76b9bc91eb288dbf7af6239b547a9a98 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Thu, 18 Jul 2019 19:48:54 -0600 Subject: [PATCH] Add notify_signal method to WaitCondition to simulate being woken by a signal --- src/sync/wait_condition.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/sync/wait_condition.rs b/src/sync/wait_condition.rs index 7506b68..2b68f9d 100644 --- a/src/sync/wait_condition.rs +++ b/src/sync/wait_condition.rs @@ -16,6 +16,7 @@ impl WaitCondition { } } + // Notify all waiters pub fn notify(&self) -> usize { let mut contexts = self.contexts.lock(); let len = contexts.len(); @@ -25,6 +26,17 @@ impl WaitCondition { len } + // Notify as though a signal woke the waiters + pub unsafe fn notify_signal(&self) -> usize { + let contexts = self.contexts.lock(); + let len = contexts.len(); + for context_lock in contexts.iter() { + context_lock.write().unblock(); + } + len + } + + // Wait until notified. Returns false if resumed by a signal or the notify_signal function pub fn wait(&self) -> bool { let id; { @@ -73,6 +85,6 @@ impl WaitCondition { impl Drop for WaitCondition { fn drop(&mut self){ - self.notify(); + unsafe { self.notify_signal() }; } }