mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
style: Print lock address on assert
Note that the crash reason is sanitized so we're not exposing anything sensitive. I think my patch just changed the signature of the stack, as it didn't change anything related to guards or what not. But without knowing why is failing or a repro it's hard to know what's going on. Printing the address at list would give us some indication of what might be going wrong (perhaps we're using a static lock when we don't expect one or such?). Differential Revision: https://phabricator.services.mozilla.com/D125948
This commit is contained in:
parent
75acb72256
commit
2a42be3cc8
1 changed files with 21 additions and 14 deletions
|
@ -94,6 +94,12 @@ impl SharedRwLock {
|
||||||
SharedRwLock { cell: None }
|
SharedRwLock { cell: None }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "gecko")]
|
||||||
|
#[inline]
|
||||||
|
fn ptr(&self) -> *const SomethingZeroSizedButTyped {
|
||||||
|
self.cell.as_ref().map(|cell| cell.as_ptr() as *const _).unwrap_or(ptr::null())
|
||||||
|
}
|
||||||
|
|
||||||
/// Wrap the given data to make its access protected by this lock.
|
/// Wrap the given data to make its access protected by this lock.
|
||||||
pub fn wrap<T>(&self, data: T) -> Locked<T> {
|
pub fn wrap<T>(&self, data: T) -> Locked<T> {
|
||||||
Locked {
|
Locked {
|
||||||
|
@ -144,6 +150,14 @@ impl<'a> Drop for SharedRwLockReadGuard<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a> SharedRwLockReadGuard<'a> {
|
||||||
|
#[inline]
|
||||||
|
#[cfg(feature = "gecko")]
|
||||||
|
fn ptr(&self) -> *const SomethingZeroSizedButTyped {
|
||||||
|
self.0.as_ref().map(|r| &**r as *const _).unwrap_or(ptr::null())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Proof that a shared lock was obtained for writing (servo).
|
/// Proof that a shared lock was obtained for writing (servo).
|
||||||
#[cfg(feature = "servo")]
|
#[cfg(feature = "servo")]
|
||||||
pub struct SharedRwLockWriteGuard<'a>(&'a SharedRwLock);
|
pub struct SharedRwLockWriteGuard<'a>(&'a SharedRwLock);
|
||||||
|
@ -190,25 +204,18 @@ impl<T> Locked<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
fn same_lock_as(&self, derefed_guard: Option<&SomethingZeroSizedButTyped>) -> bool {
|
fn same_lock_as(&self, ptr: *const SomethingZeroSizedButTyped) -> bool {
|
||||||
ptr::eq(
|
ptr::eq(self.shared_lock.ptr(), ptr)
|
||||||
self.shared_lock
|
|
||||||
.cell
|
|
||||||
.as_ref()
|
|
||||||
.map(|cell| cell.as_ptr())
|
|
||||||
.unwrap_or(ptr::null_mut()),
|
|
||||||
derefed_guard
|
|
||||||
.map(|guard| guard as *const _ as *mut _)
|
|
||||||
.unwrap_or(ptr::null_mut()),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Access the data for reading.
|
/// Access the data for reading.
|
||||||
pub fn read_with<'a>(&'a self, guard: &'a SharedRwLockReadGuard) -> &'a T {
|
pub fn read_with<'a>(&'a self, guard: &'a SharedRwLockReadGuard) -> &'a T {
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
assert!(
|
assert!(
|
||||||
self.is_read_only_lock() || self.same_lock_as(guard.0.as_ref().map(|r| &**r)),
|
self.is_read_only_lock() || self.same_lock_as(guard.ptr()),
|
||||||
"Locked::read_with called with a guard from an unrelated SharedRwLock"
|
"Locked::read_with called with a guard from an unrelated SharedRwLock: {:?} vs. {:?}",
|
||||||
|
self.shared_lock.ptr(),
|
||||||
|
guard.ptr(),
|
||||||
);
|
);
|
||||||
#[cfg(not(feature = "gecko"))]
|
#[cfg(not(feature = "gecko"))]
|
||||||
assert!(self.same_lock_as(&guard.0));
|
assert!(self.same_lock_as(&guard.0));
|
||||||
|
@ -235,7 +242,7 @@ impl<T> Locked<T> {
|
||||||
pub fn write_with<'a>(&'a self, guard: &'a mut SharedRwLockWriteGuard) -> &'a mut T {
|
pub fn write_with<'a>(&'a self, guard: &'a mut SharedRwLockWriteGuard) -> &'a mut T {
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
assert!(
|
assert!(
|
||||||
!self.is_read_only_lock() && self.same_lock_as(Some(&guard.0)),
|
!self.is_read_only_lock() && self.same_lock_as(&*guard.0),
|
||||||
"Locked::write_with called with a guard from a read only or unrelated SharedRwLock"
|
"Locked::write_with called with a guard from a read only or unrelated SharedRwLock"
|
||||||
);
|
);
|
||||||
#[cfg(not(feature = "gecko"))]
|
#[cfg(not(feature = "gecko"))]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue