Skip to content

Commit e9bc1d1

Browse files
committed
Add ReentrantLock::data_ptr
1 parent 523b3d5 commit e9bc1d1

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
@@ -344,6 +344,17 @@ impl<T: ?Sized> ReentrantLock<T> {
344344
}
345345
}
346346

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

0 commit comments

Comments
 (0)