about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJonas Platte <jplatte+git@posteo.de>2025-05-21 08:06:04 +0200
committerJonas Platte <jplatte+git@posteo.de>2025-05-21 08:07:43 +0200
commit20589bd6050ff9596348c751231ac84b7538adb4 (patch)
tree67a761d990d652cc26e06d51f3d3148616ad99fd
parent9d6c5a88a18405eb53e91645d35371ab089f0a37 (diff)
downloadrust-20589bd6050ff9596348c751231ac84b7538adb4.tar.gz
rust-20589bd6050ff9596348c751231ac84b7538adb4.zip
Add ReentrantLock::data_ptr
-rw-r--r--library/std/src/sync/reentrant_lock.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/library/std/src/sync/reentrant_lock.rs b/library/std/src/sync/reentrant_lock.rs
index 96a4cf12659..727252f03a2 100644
--- a/library/std/src/sync/reentrant_lock.rs
+++ b/library/std/src/sync/reentrant_lock.rs
@@ -349,6 +349,17 @@ impl<T: ?Sized> ReentrantLock<T> {
         }
     }
 
+    /// Returns a raw pointer to the underlying data.
+    ///
+    /// The returned pointer is always non-null and properly aligned, but it is
+    /// the user's responsibility to ensure that any reads through it are
+    /// properly synchronized to avoid data races, and that it is not read
+    /// through after the lock is dropped.
+    #[unstable(feature = "reentrant_lock_data_ptr", issue = "140368")]
+    pub fn data_ptr(&self) -> *const T {
+        &raw const self.data
+    }
+
     unsafe fn increment_lock_count(&self) -> Option<()> {
         unsafe {
             *self.lock_count.get() = (*self.lock_count.get()).checked_add(1)?;