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:22 | /// let foo = Mutex::new(Foo(1));
///
/// {
/// let mut mapped = MutexGuard::map(foo.lock().await, |f| &mut f.0);
/// *mapped = 2;
/// }
///
/// assert_eq!(Foo(2), *foo.lock().await);
/// # }
/// ```
///
/// [`MutexGuard`]: struct@MutexGuard
/// [`MappedMutexGuard... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 6871084629ad95c37c7136d865890ab2e371ea12 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6871084629ad95c37c7136d865890ab2e371ea12/tokio/src/sync/mutex.rs | 841 | 900 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:23 | /// ```
/// 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::try_map(foo.lock().awa... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 6871084629ad95c37c7136d865890ab2e371ea12 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6871084629ad95c37c7136d865890ab2e371ea12/tokio/src/sync/mutex.rs | 881 | 940 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:24 | }
/// Returns a reference to the original `Mutex`.
///
/// ```
/// use tokio::sync::{Mutex, MutexGuard};
///
/// async fn unlock_and_relock<'l>(guard: MutexGuard<'l, u32>) -> MutexGuard<'l, u32> {
/// println!("1. contains: {:?}", *guard);
/// let mutex = MutexGuard::mutex(&guar... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 6871084629ad95c37c7136d865890ab2e371ea12 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6871084629ad95c37c7136d865890ab2e371ea12/tokio/src/sync/mutex.rs | 921 | 980 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:25 | }
}
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) -> &mut Self::Target {
unsafe { &mut *self.lock.c.get() }
}
}
impl<T: ?... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 6871084629ad95c37c7136d865890ab2e371ea12 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6871084629ad95c37c7136d865890ab2e371ea12/tokio/src/sync/mutex.rs | 961 | 1,020 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:26 | }
}
}
/// Makes a new [`OwnedMappedMutexGuard`] for a component of the locked data.
///
/// This operation cannot fail as the [`OwnedMutexGuard`] passed in already locked the mutex.
///
/// This is an associated function that needs to be used as `OwnedMutexGuard::map(...)`. A method
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 6871084629ad95c37c7136d865890ab2e371ea12 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6871084629ad95c37c7136d865890ab2e371ea12/tokio/src/sync/mutex.rs | 1,001 | 1,060 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:27 | {
let data = f(&mut *this) as *mut U;
let inner = this.skip_drop();
OwnedMappedMutexGuard {
data,
lock: inner.lock,
#[cfg(all(tokio_unstable, feature = "tracing"))]
resource_span: inner.resource_span,
}
}
/// Attempts to make a new... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 6871084629ad95c37c7136d865890ab2e371ea12 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6871084629ad95c37c7136d865890ab2e371ea12/tokio/src/sync/mutex.rs | 1,041 | 1,100 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:28 | /// ```
///
/// [`OwnedMutexGuard`]: struct@OwnedMutexGuard
/// [`OwnedMappedMutexGuard`]: struct@OwnedMappedMutexGuard
#[inline]
pub fn try_map<U, F>(mut this: Self, f: F) -> Result<OwnedMappedMutexGuard<T, U>, Self>
where
U: ?Sized,
F: FnOnce(&mut T) -> Option<&mut U>,
{
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 6871084629ad95c37c7136d865890ab2e371ea12 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6871084629ad95c37c7136d865890ab2e371ea12/tokio/src/sync/mutex.rs | 1,081 | 1,140 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:29 | /// # let mutex = Arc::new(Mutex::new(0u32));
/// # let guard = mutex.lock_owned().await;
/// # unlock_and_relock(guard).await;
/// # }
/// ```
#[inline]
pub fn mutex(this: &Self) -> &Arc<Mutex<T>> {
&this.lock
}
}
impl<T: ?Sized> Drop for OwnedMutexGuard<T> {
fn dro... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 6871084629ad95c37c7136d865890ab2e371ea12 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6871084629ad95c37c7136d865890ab2e371ea12/tokio/src/sync/mutex.rs | 1,121 | 1,180 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:30 | fmt::Debug::fmt(&**self, f)
}
}
impl<T: ?Sized + fmt::Display> fmt::Display for OwnedMutexGuard<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(&**self, f)
}
}
// === impl MappedMutexGuard ===
impl<'a, T: ?Sized> MappedMutexGuard<'a, T> {
fn skip_drop(self) -... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 6871084629ad95c37c7136d865890ab2e371ea12 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6871084629ad95c37c7136d865890ab2e371ea12/tokio/src/sync/mutex.rs | 1,161 | 1,220 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:31 | data,
marker: PhantomData,
#[cfg(all(tokio_unstable, feature = "tracing"))]
resource_span: inner.resource_span,
}
}
/// Attempts to make a new [`MappedMutexGuard`] for a component of the locked data. The
/// original guard is returned if the closure returns `None... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 6871084629ad95c37c7136d865890ab2e371ea12 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6871084629ad95c37c7136d865890ab2e371ea12/tokio/src/sync/mutex.rs | 1,201 | 1,260 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:32 | #[cfg(all(tokio_unstable, feature = "tracing"))]
self.resource_span.in_scope(|| {
tracing::trace!(
target: "runtime::resource::state_update",
locked = false,
);
});
}
}
impl<'a, T: ?Sized> Deref for MappedMutexGuard<'a, T> {
type Target = ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 6871084629ad95c37c7136d865890ab2e371ea12 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6871084629ad95c37c7136d865890ab2e371ea12/tokio/src/sync/mutex.rs | 1,241 | 1,300 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:33 | // SAFETY: This duplicates the values in every field of the guard, then
// forgets the originals, so in the end no value is duplicated.
unsafe {
OwnedMappedMutexGuardInner {
data: me.data,
lock: ptr::read(&me.lock),
#[cfg(all(tokio_unstable, fe... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 6871084629ad95c37c7136d865890ab2e371ea12 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6871084629ad95c37c7136d865890ab2e371ea12/tokio/src/sync/mutex.rs | 1,281 | 1,340 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:34 | /// This is an associated function that needs to be used as `OwnedMutexGuard::try_map(...)`. A
/// method would interfere with methods of the same name on the contents of the locked data.
///
/// [`OwnedMutexGuard`]: struct@OwnedMutexGuard
/// [`OwnedMappedMutexGuard`]: struct@OwnedMappedMutexGuard
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 6871084629ad95c37c7136d865890ab2e371ea12 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6871084629ad95c37c7136d865890ab2e371ea12/tokio/src/sync/mutex.rs | 1,321 | 1,380 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:35 | fn deref(&self) -> &Self::Target {
unsafe { &*self.data }
}
}
impl<T: ?Sized, U: ?Sized> DerefMut for OwnedMappedMutexGuard<T, U> {
fn deref_mut(&mut self) -> &mut Self::Target {
unsafe { &mut *self.data }
}
}
impl<T: ?Sized, U: ?Sized + fmt::Debug> fmt::Debug for OwnedMappedMutexGuard<T, ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 6871084629ad95c37c7136d865890ab2e371ea12 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6871084629ad95c37c7136d865890ab2e371ea12/tokio/src/sync/mutex.rs | 1,361 | 1,382 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:17 | 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 acquire the lock, and returns [`TryLockError`] if t... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | aa36807c028ec359d757d359c02e4919cd14f783 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/aa36807c028ec359d757d359c02e4919cd14f783/tokio/src/sync/mutex.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:18 | Ok(guard)
}
Err(_) => Err(TryLockError(())),
}
}
/// Returns a mutable reference to the underlying data.
///
/// Since this call borrows the `Mutex` mutably, no actual locking needs to
/// take place -- the mutable borrow statically guarantees no locks exist.
///... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | aa36807c028ec359d757d359c02e4919cd14f783 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/aa36807c028ec359d757d359c02e4919cd14f783/tokio/src/sync/mutex.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:19 | /// [`TryLockError`]: TryLockError
/// [`Arc`]: std::sync::Arc
/// # Examples
///
/// ```
/// use tokio::sync::Mutex;
/// use std::sync::Arc;
/// # async fn dox() -> Result<(), tokio::sync::TryLockError> {
///
/// let mutex = Arc::new(Mutex::new(1));
///
/// let n = mutex.clo... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | aa36807c028ec359d757d359c02e4919cd14f783 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/aa36807c028ec359d757d359c02e4919cd14f783/tokio/src/sync/mutex.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:9 | }
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
where
T: Sized,
{
#[c... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 61f095fdc136f3e2a547d09b60a3ce1ef598b1f7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/61f095fdc136f3e2a547d09b60a3ce1ef598b1f7/tokio/src/sync/mutex.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:10 | #[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 | 61f095fdc136f3e2a547d09b60a3ce1ef598b1f7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/61f095fdc136f3e2a547d09b60a3ce1ef598b1f7/tokio/src/sync/mutex.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:11 | /// 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() {
/// let mutex = Mutex::new(1);
///
/// let mut n = mutex.lock().awai... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 61f095fdc136f3e2a547d09b60a3ce1ef598b1f7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/61f095fdc136f3e2a547d09b60a3ce1ef598b1f7/tokio/src/sync/mutex.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:15 | /// 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 | 61f095fdc136f3e2a547d09b60a3ce1ef598b1f7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/61f095fdc136f3e2a547d09b60a3ce1ef598b1f7/tokio/src/sync/mutex.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:16 | #[cfg(all(tokio_unstable, feature = "tracing"))]
resource_span: self.resource_span.clone(),
lock: self,
}
};
#[cfg(all(tokio_unstable, feature = "tracing"))]
let acquire_fut = trace::async_op(
move || acquire_fut,
resource_span... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 61f095fdc136f3e2a547d09b60a3ce1ef598b1f7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/61f095fdc136f3e2a547d09b60a3ce1ef598b1f7/tokio/src/sync/mutex.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:17 | /// lock is currently held somewhere else.
///
/// [`TryLockError`]: TryLockError
/// # Examples
///
/// ```
/// use tokio::sync::Mutex;
/// # async fn dox() -> Result<(), tokio::sync::TryLockError> {
///
/// let mutex = Mutex::new(1);
///
/// let n = mutex.try_lock()?;
/... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 61f095fdc136f3e2a547d09b60a3ce1ef598b1f7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/61f095fdc136f3e2a547d09b60a3ce1ef598b1f7/tokio/src/sync/mutex.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:18 | ///
/// Since this call borrows the `Mutex` mutably, no actual locking needs to
/// take place -- the mutable borrow statically guarantees no locks exist.
///
/// # Examples
///
/// ```
/// use tokio::sync::Mutex;
///
/// fn main() {
/// let mut mutex = Mutex::new(1);
///... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 61f095fdc136f3e2a547d09b60a3ce1ef598b1f7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/61f095fdc136f3e2a547d09b60a3ce1ef598b1f7/tokio/src/sync/mutex.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:19 | ///
/// let mutex = Arc::new(Mutex::new(1));
///
/// let n = mutex.clone().try_lock_owned()?;
/// assert_eq!(*n, 1);
/// # Ok(())
/// # }
pub fn try_lock_owned(self: Arc<Self>) -> Result<OwnedMutexGuard<T>, TryLockError> {
match self.s.try_acquire(1) {
Ok(_) => {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 61f095fdc136f3e2a547d09b60a3ce1ef598b1f7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/61f095fdc136f3e2a547d09b60a3ce1ef598b1f7/tokio/src/sync/mutex.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:20 | /// let n = mutex.into_inner();
/// assert_eq!(n, 1);
/// }
/// ```
pub fn into_inner(self) -> T
where
T: Sized,
{
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
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 61f095fdc136f3e2a547d09b60a3ce1ef598b1f7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/61f095fdc136f3e2a547d09b60a3ce1ef598b1f7/tokio/src/sync/mutex.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:21 | // === impl MutexGuard ===
impl<'a, T: ?Sized> MutexGuard<'a, T> {
fn skip_drop(self) -> MutexGuardInner<'a, T> {
let me = mem::ManuallyDrop::new(self);
// SAFETY: This duplicates the `resource_span` and then forgets the
// original. In the end, we have not duplicated or forgotten any value... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 61f095fdc136f3e2a547d09b60a3ce1ef598b1f7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/61f095fdc136f3e2a547d09b60a3ce1ef598b1f7/tokio/src/sync/mutex.rs | 801 | 860 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:22 | /// # }
/// ```
///
/// [`MutexGuard`]: struct@MutexGuard
/// [`MappedMutexGuard`]: struct@MappedMutexGuard
#[inline]
pub fn map<U, F>(mut this: Self, f: F) -> MappedMutexGuard<'a, U>
where
U: ?Sized,
F: FnOnce(&mut T) -> &mut U,
{
let data = f(&mut *this) as *mut... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 61f095fdc136f3e2a547d09b60a3ce1ef598b1f7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/61f095fdc136f3e2a547d09b60a3ce1ef598b1f7/tokio/src/sync/mutex.rs | 841 | 900 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:23 | /// let foo = Mutex::new(Foo(1));
///
/// {
/// 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);
/// # }
/// ```
///
/// [`Mutex... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 61f095fdc136f3e2a547d09b60a3ce1ef598b1f7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/61f095fdc136f3e2a547d09b60a3ce1ef598b1f7/tokio/src/sync/mutex.rs | 881 | 940 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:24 | /// println!("1. contains: {:?}", *guard);
/// let mutex = MutexGuard::mutex(&guard);
/// drop(guard);
/// let guard = mutex.lock().await;
/// println!("2. contains: {:?}", *guard);
/// guard
/// }
/// #
/// # #[tokio::main]
/// # async fn main() {
/// # ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 61f095fdc136f3e2a547d09b60a3ce1ef598b1f7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/61f095fdc136f3e2a547d09b60a3ce1ef598b1f7/tokio/src/sync/mutex.rs | 921 | 980 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:25 | }
impl<T: ?Sized> DerefMut for MutexGuard<'_, T> {
fn deref_mut(&mut self) -> &mut Self::Target {
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)
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 61f095fdc136f3e2a547d09b60a3ce1ef598b1f7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/61f095fdc136f3e2a547d09b60a3ce1ef598b1f7/tokio/src/sync/mutex.rs | 961 | 1,020 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:26 | /// This is an associated function that needs to be used as `OwnedMutexGuard::map(...)`. A method
/// would interfere with methods of the same name on the contents of the locked data.
///
/// # Examples
///
/// ```
/// use tokio::sync::{Mutex, OwnedMutexGuard};
/// use std::sync::Arc;
//... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 61f095fdc136f3e2a547d09b60a3ce1ef598b1f7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/61f095fdc136f3e2a547d09b60a3ce1ef598b1f7/tokio/src/sync/mutex.rs | 1,001 | 1,060 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:27 | }
}
/// Attempts to make a new [`OwnedMappedMutexGuard`] for a component of the locked data. The
/// original guard is returned if the closure returns `None`.
///
/// This operation cannot fail as the [`OwnedMutexGuard`] passed in already locked the mutex.
///
/// This is an associated func... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 61f095fdc136f3e2a547d09b60a3ce1ef598b1f7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/61f095fdc136f3e2a547d09b60a3ce1ef598b1f7/tokio/src/sync/mutex.rs | 1,041 | 1,100 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:28 | F: FnOnce(&mut T) -> Option<&mut U>,
{
let data = match f(&mut *this) {
Some(data) => data as *mut U,
None => return Err(this),
};
let inner = this.skip_drop();
Ok(OwnedMappedMutexGuard {
data,
lock: inner.lock,
#[cfg(all(to... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 61f095fdc136f3e2a547d09b60a3ce1ef598b1f7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/61f095fdc136f3e2a547d09b60a3ce1ef598b1f7/tokio/src/sync/mutex.rs | 1,081 | 1,140 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:29 | }
}
impl<T: ?Sized> Drop for OwnedMutexGuard<T> {
fn drop(&mut self) {
self.lock.s.release(1);
#[cfg(all(tokio_unstable, feature = "tracing"))]
self.resource_span.in_scope(|| {
tracing::trace!(
target: "runtime::resource::state_update",
locked = ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 61f095fdc136f3e2a547d09b60a3ce1ef598b1f7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/61f095fdc136f3e2a547d09b60a3ce1ef598b1f7/tokio/src/sync/mutex.rs | 1,121 | 1,180 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:30 | }
// === impl MappedMutexGuard ===
impl<'a, T: ?Sized> MappedMutexGuard<'a, T> {
fn skip_drop(self) -> MappedMutexGuardInner<'a, T> {
let me = mem::ManuallyDrop::new(self);
MappedMutexGuardInner {
s: me.s,
data: me.data,
#[cfg(all(tokio_unstable, feature = "trac... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 61f095fdc136f3e2a547d09b60a3ce1ef598b1f7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/61f095fdc136f3e2a547d09b60a3ce1ef598b1f7/tokio/src/sync/mutex.rs | 1,161 | 1,220 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:31 | /// original guard is returned if the closure returns `None`.
///
/// 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::try_map(...)`. A
/// method would interfere with methods... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 61f095fdc136f3e2a547d09b60a3ce1ef598b1f7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/61f095fdc136f3e2a547d09b60a3ce1ef598b1f7/tokio/src/sync/mutex.rs | 1,201 | 1,260 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:32 | }
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... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 61f095fdc136f3e2a547d09b60a3ce1ef598b1f7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/61f095fdc136f3e2a547d09b60a3ce1ef598b1f7/tokio/src/sync/mutex.rs | 1,241 | 1,300 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:33 | }
}
}
/// Makes a new [`OwnedMappedMutexGuard`] for a component of the locked data.
///
/// This operation cannot fail as the [`OwnedMappedMutexGuard`] passed in already locked the mutex.
///
/// This is an associated function that needs to be used as `OwnedMappedMutexGuard::map(...)`. ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 61f095fdc136f3e2a547d09b60a3ce1ef598b1f7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/61f095fdc136f3e2a547d09b60a3ce1ef598b1f7/tokio/src/sync/mutex.rs | 1,281 | 1,340 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:34 | F: FnOnce(&mut U) -> Option<&mut S>,
{
let data = match f(&mut *this) {
Some(data) => data as *mut S,
None => return Err(this),
};
let inner = this.skip_drop();
Ok(OwnedMappedMutexGuard {
data,
lock: inner.lock,
#[cfg(all(to... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 61f095fdc136f3e2a547d09b60a3ce1ef598b1f7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/61f095fdc136f3e2a547d09b60a3ce1ef598b1f7/tokio/src/sync/mutex.rs | 1,321 | 1,374 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:35 | }
}
impl<T: ?Sized, U: ?Sized + fmt::Debug> fmt::Debug for OwnedMappedMutexGuard<T, U> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Debug::fmt(&**self, f)
}
}
impl<T: ?Sized, U: ?Sized + fmt::Display> fmt::Display for OwnedMappedMutexGuard<T, U> {
fn fmt(&self, f: &mut fmt::Fo... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 61f095fdc136f3e2a547d09b60a3ce1ef598b1f7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/61f095fdc136f3e2a547d09b60a3ce1ef598b1f7/tokio/src/sync/mutex.rs | 1,361 | 1,374 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:21 | // === impl MutexGuard ===
impl<'a, T: ?Sized> MutexGuard<'a, T> {
fn skip_drop(self) -> MutexGuardInner<'a, T> {
let me = mem::ManuallyDrop::new(self);
// SAFETY: This duplicates the `resource_span` and then forgets the
// original. In the end, we have not duplicated or forgotten any value... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | efe3ab679a05f3da3fcc511a44120239830254f2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/efe3ab679a05f3da3fcc511a44120239830254f2/tokio/src/sync/mutex.rs | 801 | 860 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:22 | /// # }
/// ```
///
/// [`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 inn... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | efe3ab679a05f3da3fcc511a44120239830254f2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/efe3ab679a05f3da3fcc511a44120239830254f2/tokio/src/sync/mutex.rs | 841 | 900 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:23 | ///
/// {
/// 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 | efe3ab679a05f3da3fcc511a44120239830254f2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/efe3ab679a05f3da3fcc511a44120239830254f2/tokio/src/sync/mutex.rs | 881 | 940 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:24 | /// drop(guard);
/// 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 _guar... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | efe3ab679a05f3da3fcc511a44120239830254f2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/efe3ab679a05f3da3fcc511a44120239830254f2/tokio/src/sync/mutex.rs | 921 | 980 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:25 | impl<T: ?Sized> DerefMut for MutexGuard<'_, T> {
fn deref_mut(&mut self) -> &mut Self::Target {
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)
}... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | efe3ab679a05f3da3fcc511a44120239830254f2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/efe3ab679a05f3da3fcc511a44120239830254f2/tokio/src/sync/mutex.rs | 961 | 1,020 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:26 | ///
/// # Examples
///
/// ```
/// use tokio::sync::{Mutex, OwnedMutexGuard};
/// use std::sync::Arc;
///
/// #[derive(Debug, Clone, Copy, PartialEq, Eq)]
/// struct Foo(u32);
///
/// # #[tokio::main]
/// # async fn main() {
/// let foo = Arc::new(Mutex::new(Foo(1)));
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | efe3ab679a05f3da3fcc511a44120239830254f2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/efe3ab679a05f3da3fcc511a44120239830254f2/tokio/src/sync/mutex.rs | 1,001 | 1,060 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:27 | /// Attempts to make a new [`OwnedMappedMutexGuard`] for a component of the locked data. The
/// original guard is returned if the closure returns `None`.
///
/// This operation cannot fail as the [`OwnedMutexGuard`] passed in already locked the mutex.
///
/// This is an associated function that nee... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | efe3ab679a05f3da3fcc511a44120239830254f2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/efe3ab679a05f3da3fcc511a44120239830254f2/tokio/src/sync/mutex.rs | 1,041 | 1,100 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:28 | None => return Err(this),
};
let inner = this.skip_drop();
Ok(OwnedMappedMutexGuard {
data,
lock: inner.lock,
#[cfg(all(tokio_unstable, feature = "tracing"))]
resource_span: inner.resource_span,
})
}
/// Returns a reference to the ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | efe3ab679a05f3da3fcc511a44120239830254f2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/efe3ab679a05f3da3fcc511a44120239830254f2/tokio/src/sync/mutex.rs | 1,081 | 1,140 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:29 | fn drop(&mut self) {
self.lock.s.release(1);
#[cfg(all(tokio_unstable, feature = "tracing"))]
self.resource_span.in_scope(|| {
tracing::trace!(
target: "runtime::resource::state_update",
locked = false,
);
});
}
}
impl<T: ?Siz... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | efe3ab679a05f3da3fcc511a44120239830254f2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/efe3ab679a05f3da3fcc511a44120239830254f2/tokio/src/sync/mutex.rs | 1,121 | 1,180 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:30 | impl<'a, T: ?Sized> MappedMutexGuard<'a, T> {
fn skip_drop(self) -> MappedMutexGuardInner<'a, T> {
let me = mem::ManuallyDrop::new(self);
MappedMutexGuardInner {
s: me.s,
data: me.data,
#[cfg(all(tokio_unstable, feature = "tracing"))]
resource_span: un... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | efe3ab679a05f3da3fcc511a44120239830254f2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/efe3ab679a05f3da3fcc511a44120239830254f2/tokio/src/sync/mutex.rs | 1,161 | 1,220 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:31 | /// This is an associated function that needs to be used as `MappedMutexGuard::try_map(...)`. A
/// method would interfere with methods of the same name on the contents of the locked data.
///
/// [`MappedMutexGuard`]: struct@MappedMutexGuard
#[inline]
pub fn try_map<U, F>(mut this: Self, f: F) -> R... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | efe3ab679a05f3da3fcc511a44120239830254f2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/efe3ab679a05f3da3fcc511a44120239830254f2/tokio/src/sync/mutex.rs | 1,201 | 1,260 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:32 | 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: ?Sized + fmt::Debug> fmt::Debug for MappedMutexGuard<'a, T> {
fn fmt(&self,... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | efe3ab679a05f3da3fcc511a44120239830254f2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/efe3ab679a05f3da3fcc511a44120239830254f2/tokio/src/sync/mutex.rs | 1,241 | 1,300 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:33 | /// Makes a new [`OwnedMappedMutexGuard`] for a component of the locked data.
///
/// This operation cannot fail as the [`OwnedMappedMutexGuard`] passed in already locked the mutex.
///
/// This is an associated function that needs to be used as `OwnedMappedMutexGuard::map(...)`. A method
/// would ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | efe3ab679a05f3da3fcc511a44120239830254f2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/efe3ab679a05f3da3fcc511a44120239830254f2/tokio/src/sync/mutex.rs | 1,281 | 1,340 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:34 | None => return Err(this),
};
let inner = this.skip_drop();
Ok(OwnedMappedMutexGuard {
data,
lock: inner.lock,
#[cfg(all(tokio_unstable, feature = "tracing"))]
resource_span: inner.resource_span,
})
}
}
impl<T: ?Sized, U: ?Sized> Drop f... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | efe3ab679a05f3da3fcc511a44120239830254f2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/efe3ab679a05f3da3fcc511a44120239830254f2/tokio/src/sync/mutex.rs | 1,321 | 1,370 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:35 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Debug::fmt(&**self, f)
}
}
impl<T: ?Sized, U: ?Sized + fmt::Display> fmt::Display for OwnedMappedMutexGuard<T, U> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(&**self, f)
}
} | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | efe3ab679a05f3da3fcc511a44120239830254f2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/efe3ab679a05f3da3fcc511a44120239830254f2/tokio/src/sync/mutex.rs | 1,361 | 1,370 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:10 | #[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 | 7a99f87df203d589d9a8ad042a64b105a954f9fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7a99f87df203d589d9a8ad042a64b105a954f9fb/tokio/src/sync/mutex.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:11 | /// 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 | 7a99f87df203d589d9a8ad042a64b105a954f9fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7a99f87df203d589d9a8ad042a64b105a954f9fb/tokio/src/sync/mutex.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:15 | /// 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 | 7a99f87df203d589d9a8ad042a64b105a954f9fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7a99f87df203d589d9a8ad042a64b105a954f9fb/tokio/src/sync/mutex.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:16 | OwnedMutexGuard {
#[cfg(all(tokio_unstable, feature = "tracing"))]
resource_span: self.resource_span.clone(),
lock: self,
}
};
#[cfg(all(tokio_unstable, feature = "tracing"))]
let acquire_fut = trace::async_op(
move || acqu... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 7a99f87df203d589d9a8ad042a64b105a954f9fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7a99f87df203d589d9a8ad042a64b105a954f9fb/tokio/src/sync/mutex.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:17 | /// Attempts to acquire the lock, and returns [`TryLockError`] if the
/// lock is currently held somewhere else.
///
/// [`TryLockError`]: TryLockError
/// # Examples
///
/// ```
/// use tokio::sync::Mutex;
/// # async fn dox() -> Result<(), tokio::sync::TryLockError> {
///
/// l... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 7a99f87df203d589d9a8ad042a64b105a954f9fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7a99f87df203d589d9a8ad042a64b105a954f9fb/tokio/src/sync/mutex.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:18 | /// Returns a mutable reference to the underlying data.
///
/// Since this call borrows the `Mutex` mutably, no actual locking needs to
/// take place -- the mutable borrow statically guarantees no locks exist.
///
/// # Examples
///
/// ```
/// use tokio::sync::Mutex;
///
/// fn... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 7a99f87df203d589d9a8ad042a64b105a954f9fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7a99f87df203d589d9a8ad042a64b105a954f9fb/tokio/src/sync/mutex.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:19 | /// # async fn dox() -> Result<(), tokio::sync::TryLockError> {
///
/// let mutex = Arc::new(Mutex::new(1));
///
/// let n = mutex.clone().try_lock_owned()?;
/// assert_eq!(*n, 1);
/// # Ok(())
/// # }
pub fn try_lock_owned(self: Arc<Self>) -> Result<OwnedMutexGuard<T>, TryLockError> {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 7a99f87df203d589d9a8ad042a64b105a954f9fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7a99f87df203d589d9a8ad042a64b105a954f9fb/tokio/src/sync/mutex.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:20 | ///
/// let n = mutex.into_inner();
/// assert_eq!(n, 1);
/// }
/// ```
pub fn into_inner(self) -> T
where
T: Sized,
{
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>
wh... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 7a99f87df203d589d9a8ad042a64b105a954f9fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7a99f87df203d589d9a8ad042a64b105a954f9fb/tokio/src/sync/mutex.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:21 | }
// === impl MutexGuard ===
impl<'a, T: ?Sized> MutexGuard<'a, T> {
fn skip_drop(self) -> MutexGuardInner<'a, T> {
let me = mem::ManuallyDrop::new(self);
// SAFETY: This duplicates the `resource_span` and then forgets the
// original. In the end, we have not duplicated or forgotten any va... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 7a99f87df203d589d9a8ad042a64b105a954f9fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7a99f87df203d589d9a8ad042a64b105a954f9fb/tokio/src/sync/mutex.rs | 801 | 860 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:22 | /// 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 | 7a99f87df203d589d9a8ad042a64b105a954f9fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7a99f87df203d589d9a8ad042a64b105a954f9fb/tokio/src/sync/mutex.rs | 841 | 900 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:23 | /// let foo = Mutex::new(Foo(1));
///
/// {
/// 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);
/// # }
/// ```
///
/// [`Mutex... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 7a99f87df203d589d9a8ad042a64b105a954f9fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7a99f87df203d589d9a8ad042a64b105a954f9fb/tokio/src/sync/mutex.rs | 881 | 940 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:24 | /// let mutex = MutexGuard::mutex(&guard);
/// drop(guard);
/// let guard = mutex.lock().await;
/// println!("2. contains: {:?}", *guard);
/// guard
/// }
/// #
/// # #[tokio::main]
/// # async fn main() {
/// # let mutex = Mutex::new(0u32);
/// # let ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 7a99f87df203d589d9a8ad042a64b105a954f9fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7a99f87df203d589d9a8ad042a64b105a954f9fb/tokio/src/sync/mutex.rs | 921 | 980 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:25 | impl<T: ?Sized> DerefMut for MutexGuard<'_, T> {
fn deref_mut(&mut self) -> &mut Self::Target {
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)
}... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 7a99f87df203d589d9a8ad042a64b105a954f9fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7a99f87df203d589d9a8ad042a64b105a954f9fb/tokio/src/sync/mutex.rs | 961 | 1,020 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:26 | /// would interfere with methods of the same name on the contents of the locked data.
///
/// # Examples
///
/// ```
/// use tokio::sync::{Mutex, OwnedMutexGuard};
/// use std::sync::Arc;
///
/// #[derive(Debug, Clone, Copy, PartialEq, Eq)]
/// struct Foo(u32);
///
/// # #[to... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 7a99f87df203d589d9a8ad042a64b105a954f9fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7a99f87df203d589d9a8ad042a64b105a954f9fb/tokio/src/sync/mutex.rs | 1,001 | 1,060 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:27 | /// Attempts to make a new [`OwnedMappedMutexGuard`] for a component of the locked data. The
/// original guard is returned if the closure returns `None`.
///
/// This operation cannot fail as the [`OwnedMutexGuard`] passed in already locked the mutex.
///
/// This is an associated function that nee... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 7a99f87df203d589d9a8ad042a64b105a954f9fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7a99f87df203d589d9a8ad042a64b105a954f9fb/tokio/src/sync/mutex.rs | 1,041 | 1,100 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:28 | Some(data) => data as *mut U,
None => return Err(this),
};
let inner = this.skip_drop();
Ok(OwnedMappedMutexGuard {
data,
lock: inner.lock,
#[cfg(all(tokio_unstable, feature = "tracing"))]
resource_span: inner.resource_span,
})
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 7a99f87df203d589d9a8ad042a64b105a954f9fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7a99f87df203d589d9a8ad042a64b105a954f9fb/tokio/src/sync/mutex.rs | 1,081 | 1,140 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:29 | impl<T: ?Sized> Drop for OwnedMutexGuard<T> {
fn drop(&mut self) {
self.lock.s.release(1);
#[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 | 7a99f87df203d589d9a8ad042a64b105a954f9fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7a99f87df203d589d9a8ad042a64b105a954f9fb/tokio/src/sync/mutex.rs | 1,121 | 1,180 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:30 | impl<'a, T: ?Sized> MappedMutexGuard<'a, T> {
fn skip_drop(self) -> MappedMutexGuardInner<'a, T> {
let me = mem::ManuallyDrop::new(self);
MappedMutexGuardInner {
s: me.s,
data: me.data,
#[cfg(all(tokio_unstable, feature = "tracing"))]
resource_span: un... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 7a99f87df203d589d9a8ad042a64b105a954f9fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7a99f87df203d589d9a8ad042a64b105a954f9fb/tokio/src/sync/mutex.rs | 1,161 | 1,220 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:31 | ///
/// This is an associated function that needs to be used as `MappedMutexGuard::try_map(...)`. A
/// method would interfere with methods of the same name on the contents of the locked data.
///
/// [`MappedMutexGuard`]: struct@MappedMutexGuard
#[inline]
pub fn try_map<U, F>(mut this: Self, f:... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 7a99f87df203d589d9a8ad042a64b105a954f9fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7a99f87df203d589d9a8ad042a64b105a954f9fb/tokio/src/sync/mutex.rs | 1,201 | 1,260 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:32 | 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: ?Sized + fmt::Debug> fmt::Debug for MappedMutexGuard<'a, T... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 7a99f87df203d589d9a8ad042a64b105a954f9fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7a99f87df203d589d9a8ad042a64b105a954f9fb/tokio/src/sync/mutex.rs | 1,241 | 1,300 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:33 | /// Makes a new [`OwnedMappedMutexGuard`] for a component of the locked data.
///
/// This operation cannot fail as the [`OwnedMappedMutexGuard`] passed in already locked the mutex.
///
/// This is an associated function that needs to be used as `OwnedMappedMutexGuard::map(...)`. A method
/// would ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 7a99f87df203d589d9a8ad042a64b105a954f9fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7a99f87df203d589d9a8ad042a64b105a954f9fb/tokio/src/sync/mutex.rs | 1,281 | 1,340 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:34 | Some(data) => data as *mut S,
None => return Err(this),
};
let inner = this.skip_drop();
Ok(OwnedMappedMutexGuard {
data,
lock: inner.lock,
#[cfg(all(tokio_unstable, feature = "tracing"))]
resource_span: inner.resource_span,
})
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 7a99f87df203d589d9a8ad042a64b105a954f9fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7a99f87df203d589d9a8ad042a64b105a954f9fb/tokio/src/sync/mutex.rs | 1,321 | 1,371 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:35 | impl<T: ?Sized, U: ?Sized + fmt::Debug> fmt::Debug for OwnedMappedMutexGuard<T, U> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Debug::fmt(&**self, f)
}
}
impl<T: ?Sized, U: ?Sized + fmt::Display> fmt::Display for OwnedMappedMutexGuard<T, U> {
fn fmt(&self, f: &mut fmt::Formatt... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 7a99f87df203d589d9a8ad042a64b105a954f9fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7a99f87df203d589d9a8ad042a64b105a954f9fb/tokio/src/sync/mutex.rs | 1,361 | 1,371 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:16 | OwnedMutexGuard {
#[cfg(all(tokio_unstable, feature = "tracing"))]
resource_span: self.resource_span.clone(),
lock: self,
}
};
#[cfg(all(tokio_unstable, feature = "tracing"))]
let acquire_fut = trace::async_op(
move || acqu... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 2e0372be6f2fd03e5534aa73e6970c9a6e7bcd69 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2e0372be6f2fd03e5534aa73e6970c9a6e7bcd69/tokio/src/sync/mutex.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:17 | ///
/// [`TryLockError`]: TryLockError
/// # Examples
///
/// ```
/// use tokio::sync::Mutex;
/// # async fn dox() -> Result<(), tokio::sync::TryLockError> {
///
/// let mutex = Mutex::new(1);
///
/// let n = mutex.try_lock()?;
/// assert_eq!(*n, 1);
/// # Ok(())
/// ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 2e0372be6f2fd03e5534aa73e6970c9a6e7bcd69 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2e0372be6f2fd03e5534aa73e6970c9a6e7bcd69/tokio/src/sync/mutex.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:18 | /// Since this call borrows the `Mutex` mutably, no actual locking needs to
/// take place -- the mutable borrow statically guarantees no locks exist.
///
/// # Examples
///
/// ```
/// use tokio::sync::Mutex;
///
/// fn main() {
/// let mut mutex = Mutex::new(1);
///
///... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 2e0372be6f2fd03e5534aa73e6970c9a6e7bcd69 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2e0372be6f2fd03e5534aa73e6970c9a6e7bcd69/tokio/src/sync/mutex.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:19 | /// let mutex = Arc::new(Mutex::new(1));
///
/// let n = mutex.clone().try_lock_owned()?;
/// assert_eq!(*n, 1);
/// # Ok(())
/// # }
pub fn try_lock_owned(self: Arc<Self>) -> Result<OwnedMutexGuard<T>, TryLockError> {
match self.s.try_acquire(1) {
Ok(_) => {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 2e0372be6f2fd03e5534aa73e6970c9a6e7bcd69 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2e0372be6f2fd03e5534aa73e6970c9a6e7bcd69/tokio/src/sync/mutex.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:20 | /// assert_eq!(n, 1);
/// }
/// ```
pub fn into_inner(self) -> T
where
T: Sized,
{
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 {... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 2e0372be6f2fd03e5534aa73e6970c9a6e7bcd69 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2e0372be6f2fd03e5534aa73e6970c9a6e7bcd69/tokio/src/sync/mutex.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:22 | /// ```
///
/// [`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 inner = this.sk... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 2e0372be6f2fd03e5534aa73e6970c9a6e7bcd69 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2e0372be6f2fd03e5534aa73e6970c9a6e7bcd69/tokio/src/sync/mutex.rs | 841 | 900 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:23 | /// {
/// 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 | 2e0372be6f2fd03e5534aa73e6970c9a6e7bcd69 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2e0372be6f2fd03e5534aa73e6970c9a6e7bcd69/tokio/src/sync/mutex.rs | 881 | 940 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:24 | /// 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 | 2e0372be6f2fd03e5534aa73e6970c9a6e7bcd69 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2e0372be6f2fd03e5534aa73e6970c9a6e7bcd69/tokio/src/sync/mutex.rs | 921 | 980 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:25 | fn deref_mut(&mut self) -> &mut Self::Target {
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 M... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 2e0372be6f2fd03e5534aa73e6970c9a6e7bcd69 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2e0372be6f2fd03e5534aa73e6970c9a6e7bcd69/tokio/src/sync/mutex.rs | 961 | 1,020 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:26 | /// # Examples
///
/// ```
/// use tokio::sync::{Mutex, OwnedMutexGuard};
/// use std::sync::Arc;
///
/// #[derive(Debug, Clone, Copy, PartialEq, Eq)]
/// struct Foo(u32);
///
/// # #[tokio::main]
/// # async fn main() {
/// let foo = Arc::new(Mutex::new(Foo(1)));
///
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 2e0372be6f2fd03e5534aa73e6970c9a6e7bcd69 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2e0372be6f2fd03e5534aa73e6970c9a6e7bcd69/tokio/src/sync/mutex.rs | 1,001 | 1,060 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:27 | /// original guard is returned if the closure returns `None`.
///
/// This operation cannot fail as the [`OwnedMutexGuard`] passed in already locked the mutex.
///
/// This is an associated function that needs to be used as `OwnedMutexGuard::try_map(...)`. A
/// method would interfere with methods o... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 2e0372be6f2fd03e5534aa73e6970c9a6e7bcd69 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2e0372be6f2fd03e5534aa73e6970c9a6e7bcd69/tokio/src/sync/mutex.rs | 1,041 | 1,100 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:28 | };
let inner = this.skip_drop();
Ok(OwnedMappedMutexGuard {
data,
lock: inner.lock,
#[cfg(all(tokio_unstable, feature = "tracing"))]
resource_span: inner.resource_span,
})
}
/// Returns a reference to the original `Arc<Mutex>`.
///
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 2e0372be6f2fd03e5534aa73e6970c9a6e7bcd69 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2e0372be6f2fd03e5534aa73e6970c9a6e7bcd69/tokio/src/sync/mutex.rs | 1,081 | 1,140 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:29 | self.lock.s.release(1);
#[cfg(all(tokio_unstable, feature = "tracing"))]
self.resource_span.in_scope(|| {
tracing::trace!(
target: "runtime::resource::state_update",
locked = false,
);
});
}
}
impl<T: ?Sized> Deref for OwnedMutexGuard... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 2e0372be6f2fd03e5534aa73e6970c9a6e7bcd69 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2e0372be6f2fd03e5534aa73e6970c9a6e7bcd69/tokio/src/sync/mutex.rs | 1,121 | 1,180 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:30 | fn skip_drop(self) -> MappedMutexGuardInner<'a, T> {
let me = mem::ManuallyDrop::new(self);
MappedMutexGuardInner {
s: me.s,
data: me.data,
#[cfg(all(tokio_unstable, feature = "tracing"))]
resource_span: unsafe { std::ptr::read(&me.resource_span) },
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 2e0372be6f2fd03e5534aa73e6970c9a6e7bcd69 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2e0372be6f2fd03e5534aa73e6970c9a6e7bcd69/tokio/src/sync/mutex.rs | 1,161 | 1,220 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:31 | /// method would interfere with methods of the same name on the contents of the locked data.
///
/// [`MappedMutexGuard`]: struct@MappedMutexGuard
#[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>,
{
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 2e0372be6f2fd03e5534aa73e6970c9a6e7bcd69 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2e0372be6f2fd03e5534aa73e6970c9a6e7bcd69/tokio/src/sync/mutex.rs | 1,201 | 1,260 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:32 | 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: ?Sized + fmt::Debug> fmt::Debug for MappedMutexGuard<'a, T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 2e0372be6f2fd03e5534aa73e6970c9a6e7bcd69 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2e0372be6f2fd03e5534aa73e6970c9a6e7bcd69/tokio/src/sync/mutex.rs | 1,241 | 1,300 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:33 | ///
/// This operation cannot fail as the [`OwnedMappedMutexGuard`] passed in already locked the mutex.
///
/// This is an associated function that needs to be used as `OwnedMappedMutexGuard::map(...)`. A method
/// would interfere with methods of the same name on the contents of the locked data.
//... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 2e0372be6f2fd03e5534aa73e6970c9a6e7bcd69 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2e0372be6f2fd03e5534aa73e6970c9a6e7bcd69/tokio/src/sync/mutex.rs | 1,281 | 1,340 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:34 | };
let inner = this.skip_drop();
Ok(OwnedMappedMutexGuard {
data,
lock: inner.lock,
#[cfg(all(tokio_unstable, feature = "tracing"))]
resource_span: inner.resource_span,
})
}
}
impl<T: ?Sized, U: ?Sized> Drop for OwnedMappedMutexGuard<T, U> {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 2e0372be6f2fd03e5534aa73e6970c9a6e7bcd69 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2e0372be6f2fd03e5534aa73e6970c9a6e7bcd69/tokio/src/sync/mutex.rs | 1,321 | 1,369 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:4 | /// the data protected by the mutex in an inconsistent state.
///
/// [`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> {
... | 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 | 121 | 180 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:5 | ///
/// As long as you have this guard, you have exclusive access to the underlying
/// `T`. The guard internally keeps a reference-counted pointer to the original
/// `Mutex`, so even if the lock goes away, the guard remains valid.
///
/// The lock is automatically released whenever the guard is dropped, at which
/// ... | 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 | 161 | 220 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:6 | /// A helper type used when taking apart a `MappedMutexGuard` without running
/// its Drop implementation.
#[allow(dead_code)] // Unused fields are still used in Drop.
struct MappedMutexGuardInner<'a, T: ?Sized> {
s: &'a semaphore::Semaphore,
data: *mut T,
}
// As long as T: Send, it's fine to send and share M... | 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 | 201 | 260 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.