From 7e8ca571d0b6b1c551b7fe8af499ae7a7d787a6e Mon Sep 17 00:00:00 2001 From: tiif Date: Sun, 25 Aug 2024 02:05:21 +0800 Subject: [PATCH] Remove thread_id from epoll::thread_ids after timeout --- src/tools/miri/src/concurrency/thread.rs | 10 ---------- src/tools/miri/src/shims/unix/linux/epoll.rs | 12 +++++++++--- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/tools/miri/src/concurrency/thread.rs b/src/tools/miri/src/concurrency/thread.rs index 246e480a6f8d..1b119ae71924 100644 --- a/src/tools/miri/src/concurrency/thread.rs +++ b/src/tools/miri/src/concurrency/thread.rs @@ -578,10 +578,6 @@ impl<'tcx> ThreadManager<'tcx> { self.threads[thread_id].state.is_terminated() } - fn has_blocked_on_epoll(&self, thread_id: ThreadId) -> bool { - self.threads[thread_id].state.is_blocked_on(BlockReason::Epoll) - } - /// Have all threads terminated? fn have_all_terminated(&self) -> bool { self.threads.iter().all(|thread| thread.state.is_terminated()) @@ -1141,12 +1137,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { this.machine.threads.enable_thread(thread_id); } - #[inline] - fn has_blocked_on_epoll(&self, thread_id: ThreadId) -> bool { - let this = self.eval_context_ref(); - this.machine.threads.has_blocked_on_epoll(thread_id) - } - #[inline] fn active_thread_stack<'a>(&'a self) -> &'a [Frame<'tcx, Provenance, FrameExtra<'tcx>>] { let this = self.eval_context_ref(); diff --git a/src/tools/miri/src/shims/unix/linux/epoll.rs b/src/tools/miri/src/shims/unix/linux/epoll.rs index 53d89b3917fb..7228665e4b3d 100644 --- a/src/tools/miri/src/shims/unix/linux/epoll.rs +++ b/src/tools/miri/src/shims/unix/linux/epoll.rs @@ -509,6 +509,14 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { } @timeout = |this| { // No notification after blocking timeout. + let Some(epfd) = weak_epfd.upgrade() else { + throw_unsup_format!("epoll FD {epfd_value} got closed while blocking.") + }; + // Remove the current active thread_id from the blocked thread_id list. + epfd.downcast::() + .ok_or_else(|| err_unsup_format!("non-epoll FD passed to `epoll_wait`"))? + .thread_id.borrow_mut() + .retain(|&id| id != this.active_thread()); this.write_int(0, &dest)?; Ok(()) } @@ -605,9 +613,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { waiter.sort(); waiter.dedup(); for thread_id in waiter { - if this.has_blocked_on_epoll(thread_id) { - this.unblock_thread(thread_id, BlockReason::Epoll)?; - } + this.unblock_thread(thread_id, BlockReason::Epoll)?; } Ok(()) }