Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions library/std/src/sync/poison/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,17 @@ impl<T: ?Sized> Mutex<T> {
let data = self.data.get_mut();
poison::map_result(self.poison.borrow(), |()| data)
}

/// 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 and writes through it
/// are properly synchronized to avoid data races, and that it is not read
/// or written through after the mutex is dropped.
#[unstable(feature = "mutex_data_ptr", issue = "140368")]
pub fn data_ptr(&self) -> *mut T {
self.data.get()
}
}

#[stable(feature = "mutex_from", since = "1.24.0")]
Expand Down
11 changes: 11 additions & 0 deletions library/std/src/sync/poison/rwlock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,17 @@ impl<T: ?Sized> RwLock<T> {
let data = self.data.get_mut();
poison::map_result(self.poison.borrow(), |()| data)
}

/// 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 and writes through it
/// are properly synchronized to avoid data races, and that it is not read
/// or written through after the lock is dropped.
#[unstable(feature = "rwlock_data_ptr", issue = "140368")]
pub fn data_ptr(&self) -> *mut T {
self.data.get()
}
}

#[stable(feature = "rust1", since = "1.0.0")]
Expand Down
11 changes: 11 additions & 0 deletions library/std/src/sync/reentrant_lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down
Loading