about summary refs log tree commit diff
path: root/library/std/src/sync/mpmc/context.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-11-24 23:17:56 +0000
committerbors <bors@rust-lang.org>2024-11-24 23:17:56 +0000
commit28fc2ba7142654fa6e654926f96ff913027b200e (patch)
tree47ce907833aa4d4b770a5bb17ee0ebeac61b1c68 /library/std/src/sync/mpmc/context.rs
parent481b5fadd7994d0f04e9a6fe9ded3f22d6753825 (diff)
parentc50e19b69cf7f26fcd289c32a4f69adda5bc9470 (diff)
downloadrust-28fc2ba7142654fa6e654926f96ff913027b200e.tar.gz
rust-28fc2ba7142654fa6e654926f96ff913027b200e.zip
Auto merge of #133423 - jieyouxu:rollup-m3gyoz6, r=jieyouxu
Rollup of 6 pull requests

Successful merges:

 - #132730 (std: allow after-main use of synchronization primitives)
 - #133105 (only store valid proc macro item for doc link)
 - #133260 (Constify the `Deref`/`DerefMut` traits, too)
 - #133297 (Remove legacy bitcode for iOS)
 - #133298 (Mention that std::fs::remove_dir_all fails on files)
 - #133384 (add a test for target-feature-ABI warnings in closures and when calling extern fn)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'library/std/src/sync/mpmc/context.rs')
-rw-r--r--library/std/src/sync/mpmc/context.rs13
1 files changed, 9 insertions, 4 deletions
diff --git a/library/std/src/sync/mpmc/context.rs b/library/std/src/sync/mpmc/context.rs
index 2371d32d4ea..51aa7e82e78 100644
--- a/library/std/src/sync/mpmc/context.rs
+++ b/library/std/src/sync/mpmc/context.rs
@@ -69,7 +69,7 @@ impl Context {
             inner: Arc::new(Inner {
                 select: AtomicUsize::new(Selected::Waiting.into()),
                 packet: AtomicPtr::new(ptr::null_mut()),
-                thread: thread::current(),
+                thread: thread::current_or_unnamed(),
                 thread_id: current_thread_id(),
             }),
         }
@@ -112,8 +112,11 @@ impl Context {
     /// Waits until an operation is selected and returns it.
     ///
     /// If the deadline is reached, `Selected::Aborted` will be selected.
+    ///
+    /// # Safety
+    /// This may only be called from the thread this `Context` belongs to.
     #[inline]
-    pub fn wait_until(&self, deadline: Option<Instant>) -> Selected {
+    pub unsafe fn wait_until(&self, deadline: Option<Instant>) -> Selected {
         loop {
             // Check whether an operation has been selected.
             let sel = Selected::from(self.inner.select.load(Ordering::Acquire));
@@ -126,7 +129,8 @@ impl Context {
                 let now = Instant::now();
 
                 if now < end {
-                    thread::park_timeout(end - now);
+                    // SAFETY: guaranteed by caller.
+                    unsafe { self.inner.thread.park_timeout(end - now) };
                 } else {
                     // The deadline has been reached. Try aborting select.
                     return match self.try_select(Selected::Aborted) {
@@ -135,7 +139,8 @@ impl Context {
                     };
                 }
             } else {
-                thread::park();
+                // SAFETY: guaranteed by caller.
+                unsafe { self.inner.thread.park() };
             }
         }
     }