id stringlengths 22 133 | text stringlengths 40 40.2k | arch stringclasses 1
value | syntax stringclasses 1
value | kind stringclasses 4
values | repo stringclasses 27
values | path stringlengths 5 116 | license stringclasses 6
values | commit stringlengths 40 40 | source_host stringclasses 1
value | category stringclasses 16
values | source_url stringlengths 85 196 | line_start int64 1 4.28k | line_end int64 4 4.31k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
tokio-rs/tokio:tokio/src/sync/mutex.rs:7 | }
impl Error for TryLockError {}
#[test]
#[cfg(not(loom))]
fn bounds() {
fn check_send<T: Send>() {}
fn check_unpin<T: Unpin>() {}
// This has to take a value, since the async fn's return type is unnameable.
fn check_send_sync_val<T: Send + Sync>(_t: T) {}
fn check_send_sync<T: Send + Sync>() {}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 24aac0add3547803b571e9d5c6d6c3ecbd09bb5b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/24aac0add3547803b571e9d5c6d6c3ecbd09bb5b/tokio/src/sync/mutex.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:8 | where
T: Sized,
{
#[cfg(all(tokio_unstable, feature = "tracing"))]
let resource_span = {
let location = std::panic::Location::caller();
tracing::trace_span!(
"runtime.resource",
concrete_type = "Mutex",
kind = "Sync",
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 24aac0add3547803b571e9d5c6d6c3ecbd09bb5b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/24aac0add3547803b571e9d5c6d6c3ecbd09bb5b/tokio/src/sync/mutex.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:9 | ///
/// ```
/// use tokio::sync::Mutex;
///
/// static LOCK: Mutex<i32> = Mutex::const_new(5);
/// ```
#[cfg(all(feature = "parking_lot", not(all(loom, test)),))]
#[cfg_attr(docsrs, doc(cfg(feature = "parking_lot")))]
pub const fn const_new(t: T) -> Self
where
T: Sized,
{... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 24aac0add3547803b571e9d5c6d6c3ecbd09bb5b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/24aac0add3547803b571e9d5c6d6c3ecbd09bb5b/tokio/src/sync/mutex.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:10 | /// *n = 2;
/// }
/// ```
pub async fn lock(&self) -> MutexGuard<'_, T> {
let acquire_fut = async {
self.acquire().await;
MutexGuard {
lock: self,
#[cfg(all(tokio_unstable, feature = "tracing"))]
resource_span: self.resourc... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 24aac0add3547803b571e9d5c6d6c3ecbd09bb5b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/24aac0add3547803b571e9d5c6d6c3ecbd09bb5b/tokio/src/sync/mutex.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:14 | /// were requested. Cancelling a call to `lock_owned` makes you lose your
/// place in the queue.
///
/// # Examples
///
/// ```
/// use tokio::sync::Mutex;
/// use std::sync::Arc;
///
/// #[tokio::main]
/// async fn main() {
/// let mutex = Arc::new(Mutex::new(1));
/... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 24aac0add3547803b571e9d5c6d6c3ecbd09bb5b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/24aac0add3547803b571e9d5c6d6c3ecbd09bb5b/tokio/src/sync/mutex.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:15 | );
#[allow(clippy::let_and_return)] // this lint triggers when disabling tracing
let guard = acquire_fut.await;
#[cfg(all(tokio_unstable, feature = "tracing"))]
guard.resource_span.in_scope(|| {
tracing::trace!(
target: "runtime::resource::state_update",
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 24aac0add3547803b571e9d5c6d6c3ecbd09bb5b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/24aac0add3547803b571e9d5c6d6c3ecbd09bb5b/tokio/src/sync/mutex.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:16 | /// ```
pub fn try_lock(&self) -> Result<MutexGuard<'_, T>, TryLockError> {
match self.s.try_acquire(1) {
Ok(_) => {
let guard = MutexGuard {
lock: self,
#[cfg(all(tokio_unstable, feature = "tracing"))]
resource_span: se... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 24aac0add3547803b571e9d5c6d6c3ecbd09bb5b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/24aac0add3547803b571e9d5c6d6c3ecbd09bb5b/tokio/src/sync/mutex.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:17 | /// ```
pub fn get_mut(&mut self) -> &mut T {
unsafe {
// Safety: This is https://github.com/rust-lang/rust/pull/76936
&mut *self.c.get()
}
}
/// Attempts to acquire the lock, and returns [`TryLockError`] if the lock
/// is currently held somewhere else.
///
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 24aac0add3547803b571e9d5c6d6c3ecbd09bb5b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/24aac0add3547803b571e9d5c6d6c3ecbd09bb5b/tokio/src/sync/mutex.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:18 | #[cfg(all(tokio_unstable, feature = "tracing"))]
guard.resource_span.in_scope(|| {
tracing::trace!(
target: "runtime::resource::state_update",
locked = true,
);
});
Ok(guard)
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 24aac0add3547803b571e9d5c6d6c3ecbd09bb5b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/24aac0add3547803b571e9d5c6d6c3ecbd09bb5b/tokio/src/sync/mutex.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:19 | }
}
impl<T> Default for Mutex<T>
where
T: Default,
{
fn default() -> Self {
Self::new(T::default())
}
}
impl<T: ?Sized> std::fmt::Debug for Mutex<T>
where
T: std::fmt::Debug,
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut d = f.debug_struct("Mutex");... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 24aac0add3547803b571e9d5c6d6c3ecbd09bb5b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/24aac0add3547803b571e9d5c6d6c3ecbd09bb5b/tokio/src/sync/mutex.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:21 | marker: PhantomData,
}
}
/// Attempts to make a new [`MappedMutexGuard`] for a component of the locked data. The
/// original guard is returned if the closure returns `None`.
///
/// This operation cannot fail as the [`MutexGuard`] passed in already locked the mutex.
///
/// This is... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 24aac0add3547803b571e9d5c6d6c3ecbd09bb5b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/24aac0add3547803b571e9d5c6d6c3ecbd09bb5b/tokio/src/sync/mutex.rs | 801 | 860 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:22 | {
let data = match f(&mut *this) {
Some(data) => data as *mut U,
None => return Err(this),
};
let inner = this.skip_drop();
Ok(MappedMutexGuard {
s: &inner.lock.s,
data,
marker: PhantomData,
})
}
/// Returns a r... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 24aac0add3547803b571e9d5c6d6c3ecbd09bb5b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/24aac0add3547803b571e9d5c6d6c3ecbd09bb5b/tokio/src/sync/mutex.rs | 841 | 900 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:23 | impl<T: ?Sized> Drop for MutexGuard<'_, T> {
fn drop(&mut self) {
#[cfg(all(tokio_unstable, feature = "tracing"))]
self.resource_span.in_scope(|| {
tracing::trace!(
target: "runtime::resource::state_update",
locked = false,
);
});
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 24aac0add3547803b571e9d5c6d6c3ecbd09bb5b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/24aac0add3547803b571e9d5c6d6c3ecbd09bb5b/tokio/src/sync/mutex.rs | 881 | 940 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:24 | impl<T: ?Sized> OwnedMutexGuard<T> {
/// Returns a reference to the original `Arc<Mutex>`.
///
/// ```
/// use std::sync::Arc;
/// use tokio::sync::{Mutex, OwnedMutexGuard};
///
/// async fn unlock_and_relock(guard: OwnedMutexGuard<u32>) -> OwnedMutexGuard<u32> {
/// println!("1. con... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 24aac0add3547803b571e9d5c6d6c3ecbd09bb5b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/24aac0add3547803b571e9d5c6d6c3ecbd09bb5b/tokio/src/sync/mutex.rs | 921 | 980 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:25 | }
impl<T: ?Sized> Deref for OwnedMutexGuard<T> {
type Target = T;
fn deref(&self) -> &Self::Target {
unsafe { &*self.lock.c.get() }
}
}
impl<T: ?Sized> DerefMut for OwnedMutexGuard<T> {
fn deref_mut(&mut self) -> &mut Self::Target {
unsafe { &mut *self.lock.c.get() }
}
}
impl<T: ?... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 24aac0add3547803b571e9d5c6d6c3ecbd09bb5b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/24aac0add3547803b571e9d5c6d6c3ecbd09bb5b/tokio/src/sync/mutex.rs | 961 | 1,020 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:26 | /// This operation cannot fail as the [`MappedMutexGuard`] passed in already locked the mutex.
///
/// This is an associated function that needs to be used as `MappedMutexGuard::map(...)`. A
/// method would interfere with methods of the same name on the contents of the locked data.
///
/// [`Mapped... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 24aac0add3547803b571e9d5c6d6c3ecbd09bb5b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/24aac0add3547803b571e9d5c6d6c3ecbd09bb5b/tokio/src/sync/mutex.rs | 1,001 | 1,060 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:27 | s: inner.s,
data,
marker: PhantomData,
})
}
}
impl<'a, T: ?Sized> Drop for MappedMutexGuard<'a, T> {
fn drop(&mut self) {
self.s.release(1)
}
}
impl<'a, T: ?Sized> Deref for MappedMutexGuard<'a, T> {
type Target = T;
fn deref(&self) -> &Self::Target {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 24aac0add3547803b571e9d5c6d6c3ecbd09bb5b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/24aac0add3547803b571e9d5c6d6c3ecbd09bb5b/tokio/src/sync/mutex.rs | 1,041 | 1,077 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:4 | ///
/// [`Mutex`]: struct@Mutex
/// [`MutexGuard`]: struct@MutexGuard
/// [`Arc`]: struct@std::sync::Arc
/// [`std::sync::Mutex`]: struct@std::sync::Mutex
/// [`Send`]: trait@std::marker::Send
/// [`lock`]: method@Mutex::lock
pub struct Mutex<T: ?Sized> {
#[cfg(all(tokio_unstable, feature = "tracing"))]
resourc... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | d19f2f2d395a4d6befb5f66ff87a19172aede2ee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d19f2f2d395a4d6befb5f66ff87a19172aede2ee/tokio/src/sync/mutex.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:5 | /// `Mutex`, so even if the lock goes away, the guard remains valid.
///
/// The lock is automatically released whenever the guard is dropped, at which
/// point `lock` will succeed yet again.
///
/// [`Arc`]: std::sync::Arc
#[clippy::has_significant_drop]
pub struct OwnedMutexGuard<T: ?Sized> {
#[cfg(all(tokio_uns... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | d19f2f2d395a4d6befb5f66ff87a19172aede2ee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d19f2f2d395a4d6befb5f66ff87a19172aede2ee/tokio/src/sync/mutex.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:7 | check_send_sync_val(mutex.lock());
let arc_mutex = Arc::new(Mutex::new(1));
check_send_sync_val(arc_mutex.clone().lock_owned());
check_static_val(arc_mutex.lock_owned());
}
impl<T: ?Sized> Mutex<T> {
/// Creates a new lock in an unlocked state ready for use.
///
/// # Examples
///
/// `... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | d19f2f2d395a4d6befb5f66ff87a19172aede2ee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d19f2f2d395a4d6befb5f66ff87a19172aede2ee/tokio/src/sync/mutex.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:8 | );
semaphore::Semaphore::new(1)
});
#[cfg(any(not(tokio_unstable), not(feature = "tracing")))]
let s = semaphore::Semaphore::new(1);
Self {
c: UnsafeCell::new(t),
s,
#[cfg(all(tokio_unstable, feature = "tracing"))]
resource_sp... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | d19f2f2d395a4d6befb5f66ff87a19172aede2ee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d19f2f2d395a4d6befb5f66ff87a19172aede2ee/tokio/src/sync/mutex.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:9 | /// [`MutexGuard`].
///
/// # Cancel safety
///
/// This method uses a queue to fairly distribute locks in the order they
/// were requested. Cancelling a call to `lock` makes you lose your place in
/// the queue.
///
/// # Examples
///
/// ```
/// use tokio::sync::Mutex;
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | d19f2f2d395a4d6befb5f66ff87a19172aede2ee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d19f2f2d395a4d6befb5f66ff87a19172aede2ee/tokio/src/sync/mutex.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:13 | /// Locks this mutex, causing the current task to yield until the lock has
/// been acquired. When the lock has been acquired, this returns an
/// [`OwnedMutexGuard`].
///
/// This method is identical to [`Mutex::lock`], except that the returned
/// guard references the `Mutex` with an [`Arc`] rathe... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | d19f2f2d395a4d6befb5f66ff87a19172aede2ee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d19f2f2d395a4d6befb5f66ff87a19172aede2ee/tokio/src/sync/mutex.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:14 | )
.await;
#[cfg(all(tokio_unstable, feature = "tracing"))]
self.resource_span.in_scope(|| {
tracing::trace!(
target: "runtime::resource::state_update",
locked = true,
);
});
#[cfg(all(tokio_unstable, feature = "tracing"))]... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | d19f2f2d395a4d6befb5f66ff87a19172aede2ee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d19f2f2d395a4d6befb5f66ff87a19172aede2ee/tokio/src/sync/mutex.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:15 | /// # async fn dox() -> Result<(), tokio::sync::TryLockError> {
///
/// let mutex = Mutex::new(1);
///
/// let n = mutex.try_lock()?;
/// assert_eq!(*n, 1);
/// # Ok(())
/// # }
/// ```
pub fn try_lock(&self) -> Result<MutexGuard<'_, T>, TryLockError> {
match self.s.try_acqui... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | d19f2f2d395a4d6befb5f66ff87a19172aede2ee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d19f2f2d395a4d6befb5f66ff87a19172aede2ee/tokio/src/sync/mutex.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:16 | /// fn main() {
/// let mut mutex = Mutex::new(1);
///
/// let n = mutex.get_mut();
/// *n = 2;
/// }
/// ```
pub fn get_mut(&mut self) -> &mut T {
unsafe {
// Safety: This is https://github.com/rust-lang/rust/pull/76936
&mut *self.c.get()
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | d19f2f2d395a4d6befb5f66ff87a19172aede2ee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d19f2f2d395a4d6befb5f66ff87a19172aede2ee/tokio/src/sync/mutex.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:17 | Ok(_) => {
#[cfg(all(tokio_unstable, feature = "tracing"))]
self.resource_span.in_scope(|| {
tracing::trace!(
target: "runtime::resource::state_update",
locked = true,
);
});
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | d19f2f2d395a4d6befb5f66ff87a19172aede2ee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d19f2f2d395a4d6befb5f66ff87a19172aede2ee/tokio/src/sync/mutex.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:18 | self.c.into_inner()
}
}
impl<T> From<T> for Mutex<T> {
fn from(s: T) -> Self {
Self::new(s)
}
}
impl<T> Default for Mutex<T>
where
T: Default,
{
fn default() -> Self {
Self::new(T::default())
}
}
impl<T: ?Sized> std::fmt::Debug for Mutex<T>
where
T: std::fmt::Debug,
{
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | d19f2f2d395a4d6befb5f66ff87a19172aede2ee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d19f2f2d395a4d6befb5f66ff87a19172aede2ee/tokio/src/sync/mutex.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:19 | /// This is an associated function that needs to be used as `MutexGuard::map(...)`. A method
/// would interfere with methods of the same name on the contents of the locked data.
///
/// # Examples
///
/// ```
/// use tokio::sync::{Mutex, MutexGuard};
///
/// #[derive(Debug, Clone, Copy,... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | d19f2f2d395a4d6befb5f66ff87a19172aede2ee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d19f2f2d395a4d6befb5f66ff87a19172aede2ee/tokio/src/sync/mutex.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:20 | /// Attempts to make a new [`MappedMutexGuard`] for a component of the locked data. The
/// original guard is returned if the closure returns `None`.
///
/// This operation cannot fail as the [`MutexGuard`] passed in already locked the mutex.
///
/// This is an associated function that needs to be u... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | d19f2f2d395a4d6befb5f66ff87a19172aede2ee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d19f2f2d395a4d6befb5f66ff87a19172aede2ee/tokio/src/sync/mutex.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:21 | None => return Err(this),
};
let s = &this.lock.s;
mem::forget(this);
Ok(MappedMutexGuard {
s,
data,
marker: marker::PhantomData,
})
}
/// Returns a reference to the original `Mutex`.
///
/// ```
/// use tokio::sync::{Mutex... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | d19f2f2d395a4d6befb5f66ff87a19172aede2ee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d19f2f2d395a4d6befb5f66ff87a19172aede2ee/tokio/src/sync/mutex.rs | 801 | 860 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:22 | #[cfg(all(tokio_unstable, feature = "tracing"))]
self.resource_span.in_scope(|| {
tracing::trace!(
target: "runtime::resource::state_update",
locked = false,
);
});
self.lock.s.release(1);
}
}
impl<T: ?Sized> Deref for MutexGuard<'_, T... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | d19f2f2d395a4d6befb5f66ff87a19172aede2ee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d19f2f2d395a4d6befb5f66ff87a19172aede2ee/tokio/src/sync/mutex.rs | 841 | 900 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:23 | ///
/// ```
/// use std::sync::Arc;
/// use tokio::sync::{Mutex, OwnedMutexGuard};
///
/// async fn unlock_and_relock(guard: OwnedMutexGuard<u32>) -> OwnedMutexGuard<u32> {
/// println!("1. contains: {:?}", *guard);
/// let mutex: Arc<Mutex<u32>> = OwnedMutexGuard::mutex(&guard).clon... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | d19f2f2d395a4d6befb5f66ff87a19172aede2ee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d19f2f2d395a4d6befb5f66ff87a19172aede2ee/tokio/src/sync/mutex.rs | 881 | 940 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:24 | impl<T: ?Sized> Deref for OwnedMutexGuard<T> {
type Target = T;
fn deref(&self) -> &Self::Target {
unsafe { &*self.lock.c.get() }
}
}
impl<T: ?Sized> DerefMut for OwnedMutexGuard<T> {
fn deref_mut(&mut self) -> &mut Self::Target {
unsafe { &mut *self.lock.c.get() }
}
}
impl<T: ?Siz... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | d19f2f2d395a4d6befb5f66ff87a19172aede2ee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d19f2f2d395a4d6befb5f66ff87a19172aede2ee/tokio/src/sync/mutex.rs | 921 | 980 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:25 | {
let data = f(&mut *this) as *mut U;
let s = this.s;
mem::forget(this);
MappedMutexGuard {
s,
data,
marker: marker::PhantomData,
}
}
/// Attempts to make a new [`MappedMutexGuard`] for a component of the locked data. The
/// origi... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | d19f2f2d395a4d6befb5f66ff87a19172aede2ee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d19f2f2d395a4d6befb5f66ff87a19172aede2ee/tokio/src/sync/mutex.rs | 961 | 1,020 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:26 | fn drop(&mut self) {
self.s.release(1)
}
}
impl<'a, T: ?Sized> Deref for MappedMutexGuard<'a, T> {
type Target = T;
fn deref(&self) -> &Self::Target {
unsafe { &*self.data }
}
}
impl<'a, T: ?Sized> DerefMut for MappedMutexGuard<'a, T> {
fn deref_mut(&mut self) -> &mut Self::Target ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | d19f2f2d395a4d6befb5f66ff87a19172aede2ee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d19f2f2d395a4d6befb5f66ff87a19172aede2ee/tokio/src/sync/mutex.rs | 1,001 | 1,029 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:13 | /// been acquired. When the lock has been acquired, this returns an
/// [`OwnedMutexGuard`].
///
/// This method is identical to [`Mutex::lock`], except that the returned
/// guard references the `Mutex` with an [`Arc`] rather than by borrowing
/// it. Therefore, the `Mutex` must be wrapped in an `A... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | d6dbefcdc043da552615bf2c8ad1f3a9580a1735 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d6dbefcdc043da552615bf2c8ad1f3a9580a1735/tokio/src/sync/mutex.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:14 | .await;
#[cfg(all(tokio_unstable, feature = "tracing"))]
self.resource_span.in_scope(|| {
tracing::trace!(
target: "runtime::resource::state_update",
locked = true,
);
});
#[cfg(all(tokio_unstable, feature = "tracing"))]
l... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | d6dbefcdc043da552615bf2c8ad1f3a9580a1735 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d6dbefcdc043da552615bf2c8ad1f3a9580a1735/tokio/src/sync/mutex.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:15 | ///
/// let mutex = Mutex::new(1);
///
/// let n = mutex.try_lock()?;
/// assert_eq!(*n, 1);
/// # Ok(())
/// # }
/// ```
pub fn try_lock(&self) -> Result<MutexGuard<'_, T>, TryLockError> {
match self.s.try_acquire(1) {
Ok(_) => {
#[cfg(all(tokio_unsta... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | d6dbefcdc043da552615bf2c8ad1f3a9580a1735 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d6dbefcdc043da552615bf2c8ad1f3a9580a1735/tokio/src/sync/mutex.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:16 | /// let mut mutex = Mutex::new(1);
///
/// let n = mutex.get_mut();
/// *n = 2;
/// }
/// ```
pub fn get_mut(&mut self) -> &mut T {
unsafe {
// Safety: This is https://github.com/rust-lang/rust/pull/76936
&mut *self.c.get()
}
}
/// Att... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | d6dbefcdc043da552615bf2c8ad1f3a9580a1735 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d6dbefcdc043da552615bf2c8ad1f3a9580a1735/tokio/src/sync/mutex.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:17 | #[cfg(all(tokio_unstable, feature = "tracing"))]
self.resource_span.in_scope(|| {
tracing::trace!(
target: "runtime::resource::state_update",
locked = true,
);
});
#[cfg(all(tokio_uns... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | d6dbefcdc043da552615bf2c8ad1f3a9580a1735 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d6dbefcdc043da552615bf2c8ad1f3a9580a1735/tokio/src/sync/mutex.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:18 | }
}
impl<T> From<T> for Mutex<T> {
fn from(s: T) -> Self {
Self::new(s)
}
}
impl<T> Default for Mutex<T>
where
T: Default,
{
fn default() -> Self {
Self::new(T::default())
}
}
impl<T: ?Sized> std::fmt::Debug for Mutex<T>
where
T: std::fmt::Debug,
{
fn fmt(&self, f: &mut st... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | d6dbefcdc043da552615bf2c8ad1f3a9580a1735 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d6dbefcdc043da552615bf2c8ad1f3a9580a1735/tokio/src/sync/mutex.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:19 | /// would interfere with methods of the same name on the contents of the locked data.
///
/// # Examples
///
/// ```
/// use tokio::sync::{Mutex, MutexGuard};
///
/// #[derive(Debug, Clone, Copy, PartialEq, Eq)]
/// struct Foo(u32);
///
/// # #[tokio::main]
/// # async fn mai... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | d6dbefcdc043da552615bf2c8ad1f3a9580a1735 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d6dbefcdc043da552615bf2c8ad1f3a9580a1735/tokio/src/sync/mutex.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:20 | /// Attempts to make a new [`MappedMutexGuard`] for a component of the locked data. The
/// original guard is returned if the closure returns `None`.
///
/// This operation cannot fail as the [`MutexGuard`] passed in already locked the mutex.
///
/// This is an associated function that needs to be u... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | d6dbefcdc043da552615bf2c8ad1f3a9580a1735 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d6dbefcdc043da552615bf2c8ad1f3a9580a1735/tokio/src/sync/mutex.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:21 | };
let s = &this.lock.s;
mem::forget(this);
Ok(MappedMutexGuard {
s,
data,
marker: marker::PhantomData,
})
}
/// Returns a reference to the original `Mutex`.
///
/// ```
/// use tokio::sync::{Mutex, MutexGuard};
///
/// asy... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | d6dbefcdc043da552615bf2c8ad1f3a9580a1735 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d6dbefcdc043da552615bf2c8ad1f3a9580a1735/tokio/src/sync/mutex.rs | 801 | 860 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:22 | self.resource_span.in_scope(|| {
tracing::trace!(
target: "runtime::resource::state_update",
locked = false,
);
});
self.lock.s.release(1);
}
}
impl<T: ?Sized> Deref for MutexGuard<'_, T> {
type Target = T;
fn deref(&self) -> &Self::Ta... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | d6dbefcdc043da552615bf2c8ad1f3a9580a1735 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d6dbefcdc043da552615bf2c8ad1f3a9580a1735/tokio/src/sync/mutex.rs | 841 | 900 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:23 | /// ```
/// use std::sync::Arc;
/// use tokio::sync::{Mutex, OwnedMutexGuard};
///
/// async fn unlock_and_relock(guard: OwnedMutexGuard<u32>) -> OwnedMutexGuard<u32> {
/// println!("1. contains: {:?}", *guard);
/// let mutex: Arc<Mutex<u32>> = OwnedMutexGuard::mutex(&guard).clone();
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | d6dbefcdc043da552615bf2c8ad1f3a9580a1735 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d6dbefcdc043da552615bf2c8ad1f3a9580a1735/tokio/src/sync/mutex.rs | 881 | 940 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:24 | type Target = T;
fn deref(&self) -> &Self::Target {
unsafe { &*self.lock.c.get() }
}
}
impl<T: ?Sized> DerefMut for OwnedMutexGuard<T> {
fn deref_mut(&mut self) -> &mut Self::Target {
unsafe { &mut *self.lock.c.get() }
}
}
impl<T: ?Sized + fmt::Debug> fmt::Debug for OwnedMutexGuard<T> ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | d6dbefcdc043da552615bf2c8ad1f3a9580a1735 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d6dbefcdc043da552615bf2c8ad1f3a9580a1735/tokio/src/sync/mutex.rs | 921 | 980 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:25 | let data = f(&mut *this) as *mut U;
let s = this.s;
mem::forget(this);
MappedMutexGuard {
s,
data,
marker: marker::PhantomData,
}
}
/// Attempts to make a new [`MappedMutexGuard`] for a component of the locked data. The
/// original guard ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | d6dbefcdc043da552615bf2c8ad1f3a9580a1735 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d6dbefcdc043da552615bf2c8ad1f3a9580a1735/tokio/src/sync/mutex.rs | 961 | 1,020 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:26 | self.s.release(1)
}
}
impl<'a, T: ?Sized> Deref for MappedMutexGuard<'a, T> {
type Target = T;
fn deref(&self) -> &Self::Target {
unsafe { &*self.data }
}
}
impl<'a, T: ?Sized> DerefMut for MappedMutexGuard<'a, T> {
fn deref_mut(&mut self) -> &mut Self::Target {
unsafe { &mut *self... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | d6dbefcdc043da552615bf2c8ad1f3a9580a1735 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d6dbefcdc043da552615bf2c8ad1f3a9580a1735/tokio/src/sync/mutex.rs | 1,001 | 1,028 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:4 | ///
/// [`Mutex`]: struct@Mutex
/// [`MutexGuard`]: struct@MutexGuard
/// [`Arc`]: struct@std::sync::Arc
/// [`std::sync::Mutex`]: struct@std::sync::Mutex
/// [`Send`]: trait@std::marker::Send
/// [`lock`]: method@Mutex::lock
pub struct Mutex<T: ?Sized> {
#[cfg(all(tokio_unstable, feature = "tracing"))]
resourc... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 74a29be6077f4093373c647a2e3834bb5e2e9cd7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/74a29be6077f4093373c647a2e3834bb5e2e9cd7/tokio/src/sync/mutex.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:5 | ///
/// The lock is automatically released whenever the guard is dropped, at which
/// point `lock` will succeed yet again.
///
/// [`Arc`]: std::sync::Arc
pub struct OwnedMutexGuard<T: ?Sized> {
#[cfg(all(tokio_unstable, feature = "tracing"))]
resource_span: tracing::Span,
lock: Arc<Mutex<T>>,
}
/// A han... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 74a29be6077f4093373c647a2e3834bb5e2e9cd7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/74a29be6077f4093373c647a2e3834bb5e2e9cd7/tokio/src/sync/mutex.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:6 | /// by an exclusive writer.
///
/// `RwLock::try_write` operation will only fail if the lock is currently held
/// by any reader or by an exclusive writer.
///
/// [`Mutex::try_lock`]: Mutex::try_lock
/// [`RwLock::try_read`]: fn@super::RwLock::try_read
/// [`RwLock::try_write`]: fn@super::RwLock::try_write
#[derive(De... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 74a29be6077f4093373c647a2e3834bb5e2e9cd7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/74a29be6077f4093373c647a2e3834bb5e2e9cd7/tokio/src/sync/mutex.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:7 | check_static_val(arc_mutex.lock_owned());
}
impl<T: ?Sized> Mutex<T> {
/// Creates a new lock in an unlocked state ready for use.
///
/// # Examples
///
/// ```
/// use tokio::sync::Mutex;
///
/// let lock = Mutex::new(5);
/// ```
#[track_caller]
pub fn new(t: T) -> Self
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 74a29be6077f4093373c647a2e3834bb5e2e9cd7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/74a29be6077f4093373c647a2e3834bb5e2e9cd7/tokio/src/sync/mutex.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:8 | #[cfg(any(not(tokio_unstable), not(feature = "tracing")))]
let s = semaphore::Semaphore::new(1);
Self {
c: UnsafeCell::new(t),
s,
#[cfg(all(tokio_unstable, feature = "tracing"))]
resource_span,
}
}
/// Creates a new lock in an unlocked st... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 74a29be6077f4093373c647a2e3834bb5e2e9cd7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/74a29be6077f4093373c647a2e3834bb5e2e9cd7/tokio/src/sync/mutex.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:9 | ///
/// This method uses a queue to fairly distribute locks in the order they
/// were requested. Cancelling a call to `lock` makes you lose your place in
/// the queue.
///
/// # Examples
///
/// ```
/// use tokio::sync::Mutex;
///
/// #[tokio::main]
/// async fn main() {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 74a29be6077f4093373c647a2e3834bb5e2e9cd7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/74a29be6077f4093373c647a2e3834bb5e2e9cd7/tokio/src/sync/mutex.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:13 | /// This method is identical to [`Mutex::lock`], except that the returned
/// guard references the `Mutex` with an [`Arc`] rather than by borrowing
/// it. Therefore, the `Mutex` must be wrapped in an `Arc` to call this
/// method, and the guard will live for the `'static` lifetime, as it keeps
/// the ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 74a29be6077f4093373c647a2e3834bb5e2e9cd7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/74a29be6077f4093373c647a2e3834bb5e2e9cd7/tokio/src/sync/mutex.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:14 | self.resource_span.in_scope(|| {
tracing::trace!(
target: "runtime::resource::state_update",
locked = true,
);
});
#[cfg(all(tokio_unstable, feature = "tracing"))]
let resource_span = self.resource_span.clone();
#[cfg(any(not(toki... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 74a29be6077f4093373c647a2e3834bb5e2e9cd7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/74a29be6077f4093373c647a2e3834bb5e2e9cd7/tokio/src/sync/mutex.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:15 | /// let n = mutex.try_lock()?;
/// assert_eq!(*n, 1);
/// # Ok(())
/// # }
/// ```
pub fn try_lock(&self) -> Result<MutexGuard<'_, T>, TryLockError> {
match self.s.try_acquire(1) {
Ok(_) => {
#[cfg(all(tokio_unstable, feature = "tracing"))]
self.re... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 74a29be6077f4093373c647a2e3834bb5e2e9cd7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/74a29be6077f4093373c647a2e3834bb5e2e9cd7/tokio/src/sync/mutex.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:16 | /// *n = 2;
/// }
/// ```
pub fn get_mut(&mut self) -> &mut T {
unsafe {
// Safety: This is https://github.com/rust-lang/rust/pull/76936
&mut *self.c.get()
}
}
/// Attempts to acquire the lock, and returns [`TryLockError`] if the lock
/// is currently... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 74a29be6077f4093373c647a2e3834bb5e2e9cd7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/74a29be6077f4093373c647a2e3834bb5e2e9cd7/tokio/src/sync/mutex.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:17 | target: "runtime::resource::state_update",
locked = true,
);
});
#[cfg(all(tokio_unstable, feature = "tracing"))]
let resource_span = self.resource_span.clone();
Ok(OwnedMutexGuard {
lock: s... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 74a29be6077f4093373c647a2e3834bb5e2e9cd7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/74a29be6077f4093373c647a2e3834bb5e2e9cd7/tokio/src/sync/mutex.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:18 | impl<T> From<T> for Mutex<T> {
fn from(s: T) -> Self {
Self::new(s)
}
}
impl<T> Default for Mutex<T>
where
T: Default,
{
fn default() -> Self {
Self::new(T::default())
}
}
impl<T: ?Sized> std::fmt::Debug for Mutex<T>
where
T: std::fmt::Debug,
{
fn fmt(&self, f: &mut std::fm... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 74a29be6077f4093373c647a2e3834bb5e2e9cd7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/74a29be6077f4093373c647a2e3834bb5e2e9cd7/tokio/src/sync/mutex.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:19 | ///
/// ```
/// use tokio::sync::{Mutex, MutexGuard};
///
/// #[derive(Debug, Clone, Copy, PartialEq, Eq)]
/// struct Foo(u32);
///
/// # #[tokio::main]
/// # async fn main() {
/// let foo = Mutex::new(Foo(1));
///
/// {
/// let mut mapped = MutexGuard::map(foo.lock()... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 74a29be6077f4093373c647a2e3834bb5e2e9cd7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/74a29be6077f4093373c647a2e3834bb5e2e9cd7/tokio/src/sync/mutex.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:20 | /// This operation cannot fail as the [`MutexGuard`] passed in already locked the mutex.
///
/// This is an associated function that needs to be used as `MutexGuard::try_map(...)`. A
/// method would interfere with methods of the same name on the contents of the locked data.
///
/// # Examples
/... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 74a29be6077f4093373c647a2e3834bb5e2e9cd7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/74a29be6077f4093373c647a2e3834bb5e2e9cd7/tokio/src/sync/mutex.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:21 | Ok(MappedMutexGuard {
s,
data,
marker: marker::PhantomData,
})
}
/// Returns a reference to the original `Mutex`.
///
/// ```
/// use tokio::sync::{Mutex, MutexGuard};
///
/// async fn unlock_and_relock<'l>(guard: MutexGuard<'l, u32>) -> MutexGuar... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 74a29be6077f4093373c647a2e3834bb5e2e9cd7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/74a29be6077f4093373c647a2e3834bb5e2e9cd7/tokio/src/sync/mutex.rs | 801 | 860 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:22 | locked = false,
);
});
self.lock.s.release(1);
}
}
impl<T: ?Sized> Deref for MutexGuard<'_, T> {
type Target = T;
fn deref(&self) -> &Self::Target {
unsafe { &*self.lock.c.get() }
}
}
impl<T: ?Sized> DerefMut for MutexGuard<'_, T> {
fn deref_mut(&mut self) -> &m... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 74a29be6077f4093373c647a2e3834bb5e2e9cd7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/74a29be6077f4093373c647a2e3834bb5e2e9cd7/tokio/src/sync/mutex.rs | 841 | 900 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:23 | ///
/// async fn unlock_and_relock(guard: OwnedMutexGuard<u32>) -> OwnedMutexGuard<u32> {
/// println!("1. contains: {:?}", *guard);
/// let mutex: Arc<Mutex<u32>> = OwnedMutexGuard::mutex(&guard).clone();
/// drop(guard);
/// let guard = mutex.lock_owned().await;
/// println... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 74a29be6077f4093373c647a2e3834bb5e2e9cd7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/74a29be6077f4093373c647a2e3834bb5e2e9cd7/tokio/src/sync/mutex.rs | 881 | 940 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:24 | }
}
impl<T: ?Sized> DerefMut for OwnedMutexGuard<T> {
fn deref_mut(&mut self) -> &mut Self::Target {
unsafe { &mut *self.lock.c.get() }
}
}
impl<T: ?Sized + fmt::Debug> fmt::Debug for OwnedMutexGuard<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Debug::fmt(&**self, f... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 74a29be6077f4093373c647a2e3834bb5e2e9cd7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/74a29be6077f4093373c647a2e3834bb5e2e9cd7/tokio/src/sync/mutex.rs | 921 | 980 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:25 | MappedMutexGuard {
s,
data,
marker: marker::PhantomData,
}
}
/// Attempts to make a new [`MappedMutexGuard`] for a component of the locked data. The
/// original guard is returned if the closure returns `None`.
///
/// This operation cannot fail as the [`... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 74a29be6077f4093373c647a2e3834bb5e2e9cd7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/74a29be6077f4093373c647a2e3834bb5e2e9cd7/tokio/src/sync/mutex.rs | 961 | 1,020 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:26 | impl<'a, T: ?Sized> Deref for MappedMutexGuard<'a, T> {
type Target = T;
fn deref(&self) -> &Self::Target {
unsafe { &*self.data }
}
}
impl<'a, T: ?Sized> DerefMut for MappedMutexGuard<'a, T> {
fn deref_mut(&mut self) -> &mut Self::Target {
unsafe { &mut *self.data }
}
}
impl<'a, T... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 74a29be6077f4093373c647a2e3834bb5e2e9cd7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/74a29be6077f4093373c647a2e3834bb5e2e9cd7/tokio/src/sync/mutex.rs | 1,001 | 1,025 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:5 | ///
/// The lock is automatically released whenever the guard is dropped, at which
/// point `lock` will succeed yet again.
///
/// [`Arc`]: std::sync::Arc
pub struct OwnedMutexGuard<T: ?Sized> {
#[cfg(all(tokio_unstable, feature = "tracing"))]
resource_span: tracing::Span,
lock: Arc<Mutex<T>>,
}
/// A han... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 3886a3eaf4f513cc3522597a6fdd990e4f68b922 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3886a3eaf4f513cc3522597a6fdd990e4f68b922/tokio/src/sync/mutex.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:6 | /// by an exclusive writer.
///
/// `RwLock::try_write` operation will if lock is held by any reader or by an
/// exclusive writer.
///
/// [`Mutex::try_lock`]: Mutex::try_lock
/// [`RwLock::try_read`]: fn@super::RwLock::try_read
/// [`RwLock::try_write`]: fn@super::RwLock::try_write
#[derive(Debug)]
pub struct TryLock... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 3886a3eaf4f513cc3522597a6fdd990e4f68b922 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3886a3eaf4f513cc3522597a6fdd990e4f68b922/tokio/src/sync/mutex.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:12 | /// use std::sync::Arc;
///
/// #[tokio::main]
/// async fn main() {
/// let mutex = Arc::new(Mutex::new(1));
///
/// let mut n = mutex.clone().lock_owned().await;
/// *n = 2;
/// }
/// ```
///
/// [`Arc`]: std::sync::Arc
pub async fn lock_owned(self: Arc<Self... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | ff6fbc327dcd8f8d023dbe7b684d9ca13ac3aec4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ff6fbc327dcd8f8d023dbe7b684d9ca13ac3aec4/tokio/src/sync/mutex.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:13 | resource_span,
}
}
async fn acquire(&self) {
self.s.acquire(1).await.unwrap_or_else(|_| {
// The semaphore was closed. but, we never explicitly close it, and
// we own it exclusively, which means that this can never happen.
unreachable!()
});
}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | ff6fbc327dcd8f8d023dbe7b684d9ca13ac3aec4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ff6fbc327dcd8f8d023dbe7b684d9ca13ac3aec4/tokio/src/sync/mutex.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:14 | Ok(MutexGuard {
lock: self,
#[cfg(all(tokio_unstable, feature = "tracing"))]
resource_span: self.resource_span.clone(),
})
}
Err(_) => Err(TryLockError(())),
}
}
/// Returns a mutable reference to the un... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | ff6fbc327dcd8f8d023dbe7b684d9ca13ac3aec4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ff6fbc327dcd8f8d023dbe7b684d9ca13ac3aec4/tokio/src/sync/mutex.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:15 | /// this method, and the guard will live for the `'static` lifetime, as it
/// keeps the `Mutex` alive by holding an `Arc`.
///
/// [`TryLockError`]: TryLockError
/// [`Arc`]: std::sync::Arc
/// # Examples
///
/// ```
/// use tokio::sync::Mutex;
/// use std::sync::Arc;
/// # asyn... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | ff6fbc327dcd8f8d023dbe7b684d9ca13ac3aec4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ff6fbc327dcd8f8d023dbe7b684d9ca13ac3aec4/tokio/src/sync/mutex.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:16 | }
/// Consumes the mutex, returning the underlying data.
/// # Examples
///
/// ```
/// use tokio::sync::Mutex;
///
/// #[tokio::main]
/// async fn main() {
/// let mutex = Mutex::new(1);
///
/// let n = mutex.into_inner();
/// assert_eq!(n, 1);
/// }
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | ff6fbc327dcd8f8d023dbe7b684d9ca13ac3aec4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ff6fbc327dcd8f8d023dbe7b684d9ca13ac3aec4/tokio/src/sync/mutex.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:17 | where
T: std::fmt::Debug,
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut d = f.debug_struct("Mutex");
match self.try_lock() {
Ok(inner) => d.field("data", &&*inner),
Err(_) => d.field("data", &format_args!("<locked>")),
};
d... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | ff6fbc327dcd8f8d023dbe7b684d9ca13ac3aec4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ff6fbc327dcd8f8d023dbe7b684d9ca13ac3aec4/tokio/src/sync/mutex.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:18 | /// assert_eq!(Foo(2), *foo.lock().await);
/// # }
/// ```
///
/// [`MutexGuard`]: struct@MutexGuard
/// [`MappedMutexGuard`]: struct@MappedMutexGuard
#[inline]
pub fn map<U, F>(mut this: Self, f: F) -> MappedMutexGuard<'a, U>
where
F: FnOnce(&mut T) -> &mut U,
{
let ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | ff6fbc327dcd8f8d023dbe7b684d9ca13ac3aec4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ff6fbc327dcd8f8d023dbe7b684d9ca13ac3aec4/tokio/src/sync/mutex.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:19 | ///
/// {
/// let mut mapped = MutexGuard::try_map(foo.lock().await, |f| Some(&mut f.0))
/// .expect("should not fail");
/// *mapped = 2;
/// }
///
/// assert_eq!(Foo(2), *foo.lock().await);
/// # }
/// ```
///
/// [`MutexGuard`]: struct@MutexGuard
/// [`M... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | ff6fbc327dcd8f8d023dbe7b684d9ca13ac3aec4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ff6fbc327dcd8f8d023dbe7b684d9ca13ac3aec4/tokio/src/sync/mutex.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:20 | /// let guard = mutex.lock().await;
/// println!("2. contains: {:?}", *guard);
/// guard
/// }
/// #
/// # #[tokio::main]
/// # async fn main() {
/// # let mutex = Mutex::new(0u32);
/// # let guard = mutex.lock().await;
/// # let _guard = unlock_and_relock(gua... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | ff6fbc327dcd8f8d023dbe7b684d9ca13ac3aec4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ff6fbc327dcd8f8d023dbe7b684d9ca13ac3aec4/tokio/src/sync/mutex.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:21 | unsafe { &mut *self.lock.c.get() }
}
}
impl<T: ?Sized + fmt::Debug> fmt::Debug for MutexGuard<'_, T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Debug::fmt(&**self, f)
}
}
impl<T: ?Sized + fmt::Display> fmt::Display for MutexGuard<'_, T> {
fn fmt(&self, f: &mut fmt::Forma... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | ff6fbc327dcd8f8d023dbe7b684d9ca13ac3aec4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ff6fbc327dcd8f8d023dbe7b684d9ca13ac3aec4/tokio/src/sync/mutex.rs | 801 | 860 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:22 | /// ```
#[inline]
pub fn mutex(this: &Self) -> &Arc<Mutex<T>> {
&this.lock
}
}
impl<T: ?Sized> Drop for OwnedMutexGuard<T> {
fn drop(&mut self) {
#[cfg(all(tokio_unstable, feature = "tracing"))]
self.resource_span.in_scope(|| {
tracing::trace!(
target... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | ff6fbc327dcd8f8d023dbe7b684d9ca13ac3aec4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ff6fbc327dcd8f8d023dbe7b684d9ca13ac3aec4/tokio/src/sync/mutex.rs | 841 | 900 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:23 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(&**self, f)
}
}
// === impl MappedMutexGuard ===
impl<'a, T: ?Sized> MappedMutexGuard<'a, T> {
/// Makes a new [`MappedMutexGuard`] for a component of the locked data.
///
/// This operation cannot fail as the [`Mappe... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | ff6fbc327dcd8f8d023dbe7b684d9ca13ac3aec4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ff6fbc327dcd8f8d023dbe7b684d9ca13ac3aec4/tokio/src/sync/mutex.rs | 881 | 940 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:24 | #[inline]
pub fn try_map<U, F>(mut this: Self, f: F) -> Result<MappedMutexGuard<'a, U>, Self>
where
F: FnOnce(&mut T) -> Option<&mut U>,
{
let data = match f(&mut *this) {
Some(data) => data as *mut U,
None => return Err(this),
};
let s = this.s;
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | ff6fbc327dcd8f8d023dbe7b684d9ca13ac3aec4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ff6fbc327dcd8f8d023dbe7b684d9ca13ac3aec4/tokio/src/sync/mutex.rs | 921 | 969 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:4 | ///
/// [`Mutex`]: struct@Mutex
/// [`MutexGuard`]: struct@MutexGuard
/// [`Arc`]: struct@std::sync::Arc
/// [`std::sync::Mutex`]: struct@std::sync::Mutex
/// [`Send`]: trait@std::marker::Send
/// [`lock`]: method@Mutex::lock
pub struct Mutex<T: ?Sized> {
#[cfg(all(tokio_unstable, feature = "tracing"))]
resourc... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 4daeea8cad1ce8e67946bc0e17d499ab304b5ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4daeea8cad1ce8e67946bc0e17d499ab304b5ca2/tokio/src/sync/mutex.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:5 | /// The lock is automatically released whenever the guard is dropped, at which
/// point `lock` will succeed yet again.
///
/// [`Arc`]: std::sync::Arc
pub struct OwnedMutexGuard<T: ?Sized> {
#[cfg(all(tokio_unstable, feature = "tracing"))]
resource_span: tracing::Span,
lock: Arc<Mutex<T>>,
}
/// A handle ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 4daeea8cad1ce8e67946bc0e17d499ab304b5ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4daeea8cad1ce8e67946bc0e17d499ab304b5ca2/tokio/src/sync/mutex.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:6 | ///
/// `RwLock::try_write` operation will if lock is held by any reader or by an
/// exclusive writer.
///
/// [`Mutex::try_lock`]: Mutex::try_lock
/// [`RwLock::try_read`]: fn@super::RwLock::try_read
/// [`RwLock::try_write`]: fn@super::RwLock::try_write
#[derive(Debug)]
pub struct TryLockError(pub(super) ());
impl ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 4daeea8cad1ce8e67946bc0e17d499ab304b5ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4daeea8cad1ce8e67946bc0e17d499ab304b5ca2/tokio/src/sync/mutex.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:8 | #[cfg(any(not(tokio_unstable), not(feature = "tracing")))]
let s = semaphore::Semaphore::new(1);
Self {
c: UnsafeCell::new(t),
s,
#[cfg(all(tokio_unstable, feature = "tracing"))]
resource_span,
}
}
/// Creates a new lock in an unlocked st... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 4daeea8cad1ce8e67946bc0e17d499ab304b5ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4daeea8cad1ce8e67946bc0e17d499ab304b5ca2/tokio/src/sync/mutex.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:9 | /// This method uses a queue to fairly distribute locks in the order they
/// were requested. Cancelling a call to `lock` makes you lose your place in
/// the queue.
///
/// # Examples
///
/// ```
/// use tokio::sync::Mutex;
///
/// #[tokio::main]
/// async fn main() {
/// ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 4daeea8cad1ce8e67946bc0e17d499ab304b5ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4daeea8cad1ce8e67946bc0e17d499ab304b5ca2/tokio/src/sync/mutex.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:11 | /// assert_eq!(*lock, 1);
/// // Release the lock.
/// drop(lock);
///
/// // Await the completion of the blocking task.
/// blocking_task.await.unwrap();
///
/// // Assert uncontended.
/// let n = mutex.try_lock().unwrap();
/// assert_eq!(*n, 2);
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 4daeea8cad1ce8e67946bc0e17d499ab304b5ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4daeea8cad1ce8e67946bc0e17d499ab304b5ca2/tokio/src/sync/mutex.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:12 | ///
/// #[tokio::main]
/// async fn main() {
/// let mutex = Arc::new(Mutex::new(1));
///
/// let mut n = mutex.clone().lock_owned().await;
/// *n = 2;
/// }
/// ```
///
/// [`Arc`]: std::sync::Arc
pub async fn lock_owned(self: Arc<Self>) -> OwnedMutexGuard<T> {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 4daeea8cad1ce8e67946bc0e17d499ab304b5ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4daeea8cad1ce8e67946bc0e17d499ab304b5ca2/tokio/src/sync/mutex.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:13 | }
}
async fn acquire(&self) {
self.s.acquire(1).await.unwrap_or_else(|_| {
// The semaphore was closed. but, we never explicitly close it, and
// we own it exclusively, which means that this can never happen.
unreachable!()
});
}
/// Attempts to acqu... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 4daeea8cad1ce8e67946bc0e17d499ab304b5ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4daeea8cad1ce8e67946bc0e17d499ab304b5ca2/tokio/src/sync/mutex.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:14 | lock: self,
#[cfg(all(tokio_unstable, feature = "tracing"))]
resource_span: self.resource_span.clone(),
})
}
Err(_) => Err(TryLockError(())),
}
}
/// Returns a mutable reference to the underlying data.
///
/// Since... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 4daeea8cad1ce8e67946bc0e17d499ab304b5ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4daeea8cad1ce8e67946bc0e17d499ab304b5ca2/tokio/src/sync/mutex.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:15 | /// keeps the `Mutex` alive by holding an `Arc`.
///
/// [`TryLockError`]: TryLockError
/// [`Arc`]: std::sync::Arc
/// # Examples
///
/// ```
/// use tokio::sync::Mutex;
/// use std::sync::Arc;
/// # async fn dox() -> Result<(), tokio::sync::TryLockError> {
///
/// let mutex... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 4daeea8cad1ce8e67946bc0e17d499ab304b5ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4daeea8cad1ce8e67946bc0e17d499ab304b5ca2/tokio/src/sync/mutex.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:16 | /// Consumes the mutex, returning the underlying data.
/// # Examples
///
/// ```
/// use tokio::sync::Mutex;
///
/// #[tokio::main]
/// async fn main() {
/// let mutex = Mutex::new(1);
///
/// let n = mutex.into_inner();
/// assert_eq!(n, 1);
/// }
/// ``... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 4daeea8cad1ce8e67946bc0e17d499ab304b5ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4daeea8cad1ce8e67946bc0e17d499ab304b5ca2/tokio/src/sync/mutex.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:17 | T: std::fmt::Debug,
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut d = f.debug_struct("Mutex");
match self.try_lock() {
Ok(inner) => d.field("data", &&*inner),
Err(_) => d.field("data", &format_args!("<locked>")),
};
d.finish()
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 4daeea8cad1ce8e67946bc0e17d499ab304b5ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4daeea8cad1ce8e67946bc0e17d499ab304b5ca2/tokio/src/sync/mutex.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:18 | /// # }
/// ```
///
/// [`MutexGuard`]: struct@MutexGuard
/// [`MappedMutexGuard`]: struct@MappedMutexGuard
#[inline]
pub fn map<U, F>(mut this: Self, f: F) -> MappedMutexGuard<'a, U>
where
F: FnOnce(&mut T) -> &mut U,
{
let data = f(&mut *this) as *mut U;
let s =... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 4daeea8cad1ce8e67946bc0e17d499ab304b5ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4daeea8cad1ce8e67946bc0e17d499ab304b5ca2/tokio/src/sync/mutex.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:19 | /// {
/// let mut mapped = MutexGuard::try_map(foo.lock().await, |f| Some(&mut f.0))
/// .expect("should not fail");
/// *mapped = 2;
/// }
///
/// assert_eq!(Foo(2), *foo.lock().await);
/// # }
/// ```
///
/// [`MutexGuard`]: struct@MutexGuard
/// [`MappedMut... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 4daeea8cad1ce8e67946bc0e17d499ab304b5ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4daeea8cad1ce8e67946bc0e17d499ab304b5ca2/tokio/src/sync/mutex.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:20 | /// println!("2. contains: {:?}", *guard);
/// guard
/// }
/// #
/// # #[tokio::main]
/// # async fn main() {
/// # let mutex = Mutex::new(0u32);
/// # let guard = mutex.lock().await;
/// # unlock_and_relock(guard).await;
/// # }
/// ```
#[inline]
pub ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 4daeea8cad1ce8e67946bc0e17d499ab304b5ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4daeea8cad1ce8e67946bc0e17d499ab304b5ca2/tokio/src/sync/mutex.rs | 761 | 820 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.