Skip to content

Commit

Permalink
Change locking mechanism for waking events.
Browse files Browse the repository at this point in the history
  • Loading branch information
AldaronLau committed Nov 25, 2021
1 parent 43beed1 commit d9718cd
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,14 @@ unsafe fn start_thread(epoll_fd: RawFd) {
// Since event has succeeded we can assume it's initialized.
let pointer: *mut DeviceInternal =
(*event.as_mut_ptr()).data.ptr.cast();
// Only wake if ready is false.
if !(*pointer).ready.load(Ordering::Acquire) {
if let Some(w) = (*pointer).waker.take() {
w.wake();
}
(*pointer).ready.store(true, Ordering::Release);
// Spinlock until ready.
while (*pointer).ready.load(Ordering::Acquire) {
}
// Release the lock & wake the future
let maybe_waker = (*pointer).waker.take();
(*pointer).ready.store(true, Ordering::Release);
if let Some(w) = maybe_waker {
w.wake();
}
});
}

0 comments on commit d9718cd

Please sign in to comment.