Prevent data races.
This commit is contained in:
32
src/any.rs
32
src/any.rs
@@ -282,6 +282,11 @@ impl Dynamic {
|
||||
}
|
||||
|
||||
/// Get the TypeId of the value held by this `Dynamic`.
|
||||
///
|
||||
/// # Panics and Deadlocks When Value is Shared
|
||||
///
|
||||
/// Under the `sync` feature, this call may deadlock.
|
||||
/// Otherwise, this call panics if the data is currently borrowed for write.
|
||||
pub fn type_id(&self) -> TypeId {
|
||||
match &self.0 {
|
||||
Union::Unit(_) => TypeId::of::<()>(),
|
||||
@@ -307,6 +312,11 @@ impl Dynamic {
|
||||
}
|
||||
|
||||
/// Get the name of the type of the value held by this `Dynamic`.
|
||||
///
|
||||
/// # Panics and Deadlocks When Value is Shared
|
||||
///
|
||||
/// Under the `sync` feature, this call may deadlock.
|
||||
/// Otherwise, this call panics if the data is currently borrowed for write.
|
||||
pub fn type_name(&self) -> &'static str {
|
||||
match &self.0 {
|
||||
Union::Unit(_) => "()",
|
||||
@@ -752,6 +762,28 @@ impl Dynamic {
|
||||
}
|
||||
}
|
||||
|
||||
/// Is the `Dynamic` a shared value that is locked?
|
||||
///
|
||||
/// ## Note
|
||||
///
|
||||
/// Under the `sync` feature, shared values use `RwLock` and they are never locked.
|
||||
/// Access just waits until the `RwLock` is released.
|
||||
/// So this method always returns `false` under `sync`.
|
||||
#[inline(always)]
|
||||
pub fn is_locked(&self) -> bool {
|
||||
match self.0 {
|
||||
#[cfg(not(feature = "no_shared"))]
|
||||
Union::Shared(ref _cell) => {
|
||||
#[cfg(not(feature = "sync"))]
|
||||
return _cell.try_borrow().is_err();
|
||||
|
||||
#[cfg(feature = "sync")]
|
||||
return false;
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Get a reference of a specific type to the `Dynamic`.
|
||||
/// Casting to `Dynamic` just returns a reference to it.
|
||||
///
|
||||
|
Reference in New Issue
Block a user