Skip to content

Commit 20589bd

Browse files
committed
Add ReentrantLock::data_ptr
1 parent 9d6c5a8 commit 20589bd

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

library/std/src/sync/reentrant_lock.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,17 @@ impl<T: ?Sized> ReentrantLock<T> {
349349
}
350350
}
351351

352+
/// Returns a raw pointer to the underlying data.
353+
///
354+
/// The returned pointer is always non-null and properly aligned, but it is
355+
/// the user's responsibility to ensure that any reads through it are
356+
/// properly synchronized to avoid data races, and that it is not read
357+
/// through after the lock is dropped.
358+
#[unstable(feature = "reentrant_lock_data_ptr", issue = "140368")]
359+
pub fn data_ptr(&self) -> *const T {
360+
&raw const self.data
361+
}
362+
352363
unsafe fn increment_lock_count(&self) -> Option<()> {
353364
unsafe {
354365
*self.lock_count.get() = (*self.lock_count.get()).checked_add(1)?;

0 commit comments

Comments
 (0)