From a37c1ee8ea85860fdaa963ee3f50b86b3585b01d Mon Sep 17 00:00:00 2001 From: Stjepan Glavina Date: Mon, 25 May 2020 23:31:11 +0200 Subject: [PATCH] Drop locks before waking tasks --- src/reactor.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/reactor.rs b/src/reactor.rs index 9c6089f..a9ceef4 100644 --- a/src/reactor.rs +++ b/src/reactor.rs @@ -224,6 +224,9 @@ impl Reactor { Some(Duration::from_secs(0)) }; + // Drop the lock before waking. + drop(timers); + // Wake up tasks waiting on timers. for (_, waker) in ready { waker.wake(); @@ -273,6 +276,7 @@ impl ReactorLock<'_> { Ok(_) => { // Iterate over sources in the event list. let sources = self.reactor.sources.lock(); + let mut ready = Vec::new(); for ev in self.events.iter() { // Check if there is a source in the table with this key. @@ -281,20 +285,24 @@ impl ReactorLock<'_> { // Wake readers if a readability event was emitted. if ev.readable { - for w in wakers.readers.drain(..) { - w.wake(); - } + ready.append(&mut wakers.readers); } // Wake writers if a writability event was emitted. if ev.writable { - for w in wakers.writers.drain(..) { - w.wake(); - } + ready.append(&mut wakers.writers); } } } + // Drop the lock before waking. + drop(sources); + + // Wake up tasks waiting on I/O. + for waker in ready { + waker.wake(); + } + return Ok(()); }