From 934eb8b3914980ac5895a9bf1c570c688a2cca35 Mon Sep 17 00:00:00 2001 From: joboet Date: Wed, 12 Apr 2023 00:04:58 +0200 Subject: std: replace pthread `RwLock` with custom implementation inspired by usync --- library/std/src/thread/mod.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'library/std/src/thread') diff --git a/library/std/src/thread/mod.rs b/library/std/src/thread/mod.rs index 8498937809e..53fbada7cae 100644 --- a/library/std/src/thread/mod.rs +++ b/library/std/src/thread/mod.rs @@ -1063,7 +1063,7 @@ pub fn park() { let guard = PanicGuard; // SAFETY: park_timeout is called on the parker owned by this thread. unsafe { - current().inner.as_ref().parker().park(); + current().park(); } // No panic occurred, do not abort. forget(guard); @@ -1290,6 +1290,15 @@ impl Thread { Thread { inner } } + /// Like the public [`park`], but callable on any handle. Used to allow + /// parking in TLS destructors. + /// + /// # Safety + /// May only be called from the thread to which this handle belongs. + pub(crate) unsafe fn park(&self) { + unsafe { self.inner.as_ref().parker().park() } + } + /// Atomically makes the handle's token available if it is not already. /// /// Every thread is equipped with some basic low-level blocking support, via -- cgit 1.4.1-3-g733a5 From 2e652e59f6d778053853e8dd6230082e71829117 Mon Sep 17 00:00:00 2001 From: joboet Date: Wed, 12 Apr 2023 20:27:41 +0200 Subject: adjust code documentation --- library/std/src/sys/pal/unix/locks/queue_rwlock.rs | 4 ++-- library/std/src/thread/mod.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'library/std/src/thread') diff --git a/library/std/src/sys/pal/unix/locks/queue_rwlock.rs b/library/std/src/sys/pal/unix/locks/queue_rwlock.rs index 817d6ef4040..18b414ed490 100644 --- a/library/std/src/sys/pal/unix/locks/queue_rwlock.rs +++ b/library/std/src/sys/pal/unix/locks/queue_rwlock.rs @@ -13,7 +13,7 @@ //! * On some platforms (e.g. macOS), the lock is very slow. //! //! Therefore, we implement our own `RwLock`! Naively, one might reach for a -//! spinlock, but those [are quite problematic] when the lock is contended. +//! spinlock, but those [can be quite problematic] when the lock is contended. //! Instead, this readers-writer lock copies its implementation strategy from //! the Windows [SRWLOCK] and the [usync] library. Spinning is still used for the //! fast path, but it is bounded: after spinning fails, threads will locklessly @@ -429,7 +429,7 @@ impl RwLock { // The next waiter is a writer. Remove it from the queue and wake it. let prev = match unsafe { tail.as_ref().prev.get() } { // If the lock was read-locked, multiple threads have invoked - // `find_tail` above. Therefore, it is possible that one of + // `find_tail` above. Therefore, it is possible that one of // them observed a newer state than this thread did, meaning // there is a set `tail` field in a node before `state`. To // make sure that the queue is valid after the link update diff --git a/library/std/src/thread/mod.rs b/library/std/src/thread/mod.rs index 53fbada7cae..eb837c8f6c6 100644 --- a/library/std/src/thread/mod.rs +++ b/library/std/src/thread/mod.rs @@ -1290,8 +1290,8 @@ impl Thread { Thread { inner } } - /// Like the public [`park`], but callable on any handle. Used to allow - /// parking in TLS destructors. + /// Like the public [`park`], but callable on any handle. This is used to + /// allow parking in TLS destructors. /// /// # Safety /// May only be called from the thread to which this handle belongs. -- cgit 1.4.1-3-g733a5