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:19 | /// Attempts to acquire the lock, and returns [`TryLockError`] if the lock
/// is currently held somewhere else.
///
/// This method is identical to [`Mutex::try_lock`], except that the
/// returned guard references the `Mutex` with an [`Arc`] rather than by
/// borrowing it. Therefore, the `Mutex`... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | a99a3518020e1c7ea6db6f9d2e7e567637a3d7e7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a99a3518020e1c7ea6db6f9d2e7e567637a3d7e7/tokio/src/sync/mutex.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:20 | });
Ok(guard)
}
Err(_) => Err(TryLockError(())),
}
}
/// Consumes the mutex, returning the underlying data.
/// # Examples
///
/// ```
/// use tokio::sync::Mutex;
///
/// #[tokio::main]
/// async fn main() {
/// let mutex = Mu... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | a99a3518020e1c7ea6db6f9d2e7e567637a3d7e7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a99a3518020e1c7ea6db6f9d2e7e567637a3d7e7/tokio/src/sync/mutex.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:21 | 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");
match self.try_lock() {
Ok(inner) => d.fi... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | a99a3518020e1c7ea6db6f9d2e7e567637a3d7e7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a99a3518020e1c7ea6db6f9d2e7e567637a3d7e7/tokio/src/sync/mutex.rs | 801 | 860 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:22 | /// # Examples
///
/// ```
/// 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 = MutexGu... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | a99a3518020e1c7ea6db6f9d2e7e567637a3d7e7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a99a3518020e1c7ea6db6f9d2e7e567637a3d7e7/tokio/src/sync/mutex.rs | 841 | 900 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:23 | /// 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 | a99a3518020e1c7ea6db6f9d2e7e567637a3d7e7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a99a3518020e1c7ea6db6f9d2e7e567637a3d7e7/tokio/src/sync/mutex.rs | 881 | 940 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:24 | None => return Err(this),
};
let inner = this.skip_drop();
Ok(MappedMutexGuard {
s: &inner.lock.s,
data,
marker: PhantomData,
#[cfg(all(tokio_unstable, feature = "tracing"))]
resource_span: inner.resource_span,
})
}
///... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | a99a3518020e1c7ea6db6f9d2e7e567637a3d7e7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a99a3518020e1c7ea6db6f9d2e7e567637a3d7e7/tokio/src/sync/mutex.rs | 921 | 980 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:25 | 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 | a99a3518020e1c7ea6db6f9d2e7e567637a3d7e7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a99a3518020e1c7ea6db6f9d2e7e567637a3d7e7/tokio/src/sync/mutex.rs | 961 | 1,020 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:26 | impl<T: ?Sized> OwnedMutexGuard<T> {
fn skip_drop(self) -> OwnedMutexGuardInner<T> {
let me = mem::ManuallyDrop::new(self);
// SAFETY: This duplicates the values in every field of the guard, then
// forgets the originals, so in the end no value is duplicated.
unsafe {
Own... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | a99a3518020e1c7ea6db6f9d2e7e567637a3d7e7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a99a3518020e1c7ea6db6f9d2e7e567637a3d7e7/tokio/src/sync/mutex.rs | 1,001 | 1,060 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:27 | /// # }
/// ```
///
/// [`OwnedMutexGuard`]: struct@OwnedMutexGuard
/// [`OwnedMappedMutexGuard`]: struct@OwnedMappedMutexGuard
#[inline]
pub fn map<U, F>(mut this: Self, f: F) -> OwnedMappedMutexGuard<T, U>
where
U: ?Sized,
F: FnOnce(&mut T) -> &mut U,
{
let data... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | a99a3518020e1c7ea6db6f9d2e7e567637a3d7e7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a99a3518020e1c7ea6db6f9d2e7e567637a3d7e7/tokio/src/sync/mutex.rs | 1,041 | 1,100 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:28 | /// let foo = Arc::new(Mutex::new(Foo(1)));
///
/// {
/// let mut mapped = OwnedMutexGuard::try_map(foo.clone().lock_owned().await, |f| Some(&mut f.0))
/// .expect("should not fail");
/// *mapped = 2;
/// }
///
/// assert_eq!(Foo(2), *foo.lock().await);
/// # }
//... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | a99a3518020e1c7ea6db6f9d2e7e567637a3d7e7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a99a3518020e1c7ea6db6f9d2e7e567637a3d7e7/tokio/src/sync/mutex.rs | 1,081 | 1,140 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:29 | /// println!("1. contains: {:?}", *guard);
/// let mutex: Arc<Mutex<u32>> = OwnedMutexGuard::mutex(&guard).clone();
/// drop(guard);
/// let guard = mutex.lock_owned().await;
/// println!("2. contains: {:?}", *guard);
/// guard
/// }
/// #
/// # #[tokio::main]
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | a99a3518020e1c7ea6db6f9d2e7e567637a3d7e7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a99a3518020e1c7ea6db6f9d2e7e567637a3d7e7/tokio/src/sync/mutex.rs | 1,121 | 1,180 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:30 | }
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 | a99a3518020e1c7ea6db6f9d2e7e567637a3d7e7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a99a3518020e1c7ea6db6f9d2e7e567637a3d7e7/tokio/src/sync/mutex.rs | 1,161 | 1,220 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:31 | /// [`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.skip_drop();
MappedMutexGuard {
s: inner.s,
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | a99a3518020e1c7ea6db6f9d2e7e567637a3d7e7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a99a3518020e1c7ea6db6f9d2e7e567637a3d7e7/tokio/src/sync/mutex.rs | 1,201 | 1,260 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:32 | #[cfg(all(tokio_unstable, feature = "tracing"))]
resource_span: inner.resource_span,
})
}
}
impl<'a, T: ?Sized> Drop for MappedMutexGuard<'a, T> {
fn drop(&mut self) {
self.s.release(1);
#[cfg(all(tokio_unstable, feature = "tracing"))]
self.resource_span.in_scope(||... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | a99a3518020e1c7ea6db6f9d2e7e567637a3d7e7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a99a3518020e1c7ea6db6f9d2e7e567637a3d7e7/tokio/src/sync/mutex.rs | 1,241 | 1,300 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:33 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(&**self, f)
}
}
// === impl OwnedMappedMutexGuard ===
impl<T: ?Sized, U: ?Sized> OwnedMappedMutexGuard<T, U> {
fn skip_drop(self) -> OwnedMappedMutexGuardInner<T, U> {
let me = mem::ManuallyDrop::new(self);
//... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | a99a3518020e1c7ea6db6f9d2e7e567637a3d7e7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a99a3518020e1c7ea6db6f9d2e7e567637a3d7e7/tokio/src/sync/mutex.rs | 1,281 | 1,340 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:34 | #[cfg(all(tokio_unstable, feature = "tracing"))]
resource_span: inner.resource_span,
}
}
/// 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 ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | a99a3518020e1c7ea6db6f9d2e7e567637a3d7e7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a99a3518020e1c7ea6db6f9d2e7e567637a3d7e7/tokio/src/sync/mutex.rs | 1,321 | 1,380 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:35 | tracing::trace!(
target: "runtime::resource::state_update",
locked = false,
);
});
}
}
impl<T: ?Sized, U: ?Sized> Deref for OwnedMappedMutexGuard<T, U> {
type Target = U;
fn deref(&self) -> &Self::Target {
unsafe { &*self.data }
}
}
impl<T: ?... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | a99a3518020e1c7ea6db6f9d2e7e567637a3d7e7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a99a3518020e1c7ea6db6f9d2e7e567637a3d7e7/tokio/src/sync/mutex.rs | 1,361 | 1,392 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:18 | let guard = MutexGuard {
lock: self,
#[cfg(all(tokio_unstable, feature = "tracing"))]
resource_span: self.resource_span.clone(),
};
#[cfg(all(tokio_unstable, feature = "tracing"))]
self.resource_span.in_scope(||... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 8463af92afb398aa94600eaac84eafe3ee83b737 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8463af92afb398aa94600eaac84eafe3ee83b737/tokio/src/sync/mutex.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:19 | &mut *self.c.get()
}
}
/// Attempts to acquire the lock, and returns [`TryLockError`] if the lock
/// is currently held somewhere else.
///
/// This method is identical to [`Mutex::try_lock`], except that the
/// returned guard references the `Mutex` with an [`Arc`] rather than by
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 8463af92afb398aa94600eaac84eafe3ee83b737 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8463af92afb398aa94600eaac84eafe3ee83b737/tokio/src/sync/mutex.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:20 | target: "runtime::resource::state_update",
locked = true,
);
});
Ok(guard)
}
Err(_) => Err(TryLockError(())),
}
}
/// Consumes the mutex, returning the underlying data.
/// # Examples
///
//... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 8463af92afb398aa94600eaac84eafe3ee83b737 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8463af92afb398aa94600eaac84eafe3ee83b737/tokio/src/sync/mutex.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:21 | 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");
match self.try_lock() {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 8463af92afb398aa94600eaac84eafe3ee83b737 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8463af92afb398aa94600eaac84eafe3ee83b737/tokio/src/sync/mutex.rs | 801 | 860 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:22 | /// 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 | 8463af92afb398aa94600eaac84eafe3ee83b737 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8463af92afb398aa94600eaac84eafe3ee83b737/tokio/src/sync/mutex.rs | 841 | 900 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:23 | }
}
/// 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 ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 8463af92afb398aa94600eaac84eafe3ee83b737 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8463af92afb398aa94600eaac84eafe3ee83b737/tokio/src/sync/mutex.rs | 881 | 940 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:24 | {
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,
#[cfg(all(tokio_unstable,... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 8463af92afb398aa94600eaac84eafe3ee83b737 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8463af92afb398aa94600eaac84eafe3ee83b737/tokio/src/sync/mutex.rs | 921 | 980 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:25 | }
impl<T: ?Sized> Drop for MutexGuard<'_, 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 = fal... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 8463af92afb398aa94600eaac84eafe3ee83b737 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8463af92afb398aa94600eaac84eafe3ee83b737/tokio/src/sync/mutex.rs | 961 | 1,020 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:26 | // === impl OwnedMutexGuard ===
impl<T: ?Sized> OwnedMutexGuard<T> {
fn skip_drop(self) -> OwnedMutexGuardInner<T> {
let me = mem::ManuallyDrop::new(self);
// SAFETY: This duplicates the values in every field of the guard, then
// forgets the originals, so in the end no value is duplicated.... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 8463af92afb398aa94600eaac84eafe3ee83b737 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8463af92afb398aa94600eaac84eafe3ee83b737/tokio/src/sync/mutex.rs | 1,001 | 1,060 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:27 | /// }
///
/// assert_eq!(Foo(2), *foo.lock().await);
/// # }
/// ```
///
/// [`OwnedMutexGuard`]: struct@OwnedMutexGuard
/// [`OwnedMappedMutexGuard`]: struct@OwnedMappedMutexGuard
#[inline]
pub fn map<U, F>(mut this: Self, f: F) -> OwnedMappedMutexGuard<T, U>
where
U: ?S... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 8463af92afb398aa94600eaac84eafe3ee83b737 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8463af92afb398aa94600eaac84eafe3ee83b737/tokio/src/sync/mutex.rs | 1,041 | 1,100 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:28 | ///
/// # #[tokio::main]
/// # async fn main() {
/// let foo = Arc::new(Mutex::new(Foo(1)));
///
/// {
/// let mut mapped = OwnedMutexGuard::try_map(foo.clone().lock_owned().await, |f| Some(&mut f.0))
/// .expect("should not fail");
/// *mapped = 2;
/// }
///
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 8463af92afb398aa94600eaac84eafe3ee83b737 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8463af92afb398aa94600eaac84eafe3ee83b737/tokio/src/sync/mutex.rs | 1,081 | 1,140 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:29 | /// 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();
/// drop(guard);
/// let gu... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 8463af92afb398aa94600eaac84eafe3ee83b737 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8463af92afb398aa94600eaac84eafe3ee83b737/tokio/src/sync/mutex.rs | 1,121 | 1,180 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:30 | 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> {
fn fmt(&self, f... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 8463af92afb398aa94600eaac84eafe3ee83b737 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8463af92afb398aa94600eaac84eafe3ee83b737/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::map(...)`. A
/// method would interfere with methods of the same name on the contents of the locked data.
///
/// [`MappedMutexGuard`]: struct@MappedMutexGuard
#[inline]
pub fn map<U, F>(mut this: Self, f: F) -> MappedMut... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 8463af92afb398aa94600eaac84eafe3ee83b737 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8463af92afb398aa94600eaac84eafe3ee83b737/tokio/src/sync/mutex.rs | 1,201 | 1,260 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:32 | s: inner.s,
data,
marker: PhantomData,
#[cfg(all(tokio_unstable, feature = "tracing"))]
resource_span: inner.resource_span,
})
}
}
impl<'a, T: ?Sized> Drop for MappedMutexGuard<'a, T> {
fn drop(&mut self) {
self.s.release(1);
#[cfg(all(to... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 8463af92afb398aa94600eaac84eafe3ee83b737 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8463af92afb398aa94600eaac84eafe3ee83b737/tokio/src/sync/mutex.rs | 1,241 | 1,300 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:33 | }
impl<'a, T: ?Sized + fmt::Display> fmt::Display for MappedMutexGuard<'a, T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(&**self, f)
}
}
// === impl OwnedMappedMutexGuard ===
impl<T: ?Sized, U: ?Sized> OwnedMappedMutexGuard<T, U> {
fn skip_drop(self) -> OwnedMa... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 8463af92afb398aa94600eaac84eafe3ee83b737 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8463af92afb398aa94600eaac84eafe3ee83b737/tokio/src/sync/mutex.rs | 1,281 | 1,340 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:34 | OwnedMappedMutexGuard {
data,
lock: inner.lock,
#[cfg(all(tokio_unstable, feature = "tracing"))]
resource_span: inner.resource_span,
}
}
/// Attempts to make a new [`OwnedMappedMutexGuard`] for a component of the locked data. The
/// original guard is... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 8463af92afb398aa94600eaac84eafe3ee83b737 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8463af92afb398aa94600eaac84eafe3ee83b737/tokio/src/sync/mutex.rs | 1,321 | 1,380 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:35 | #[cfg(all(tokio_unstable, feature = "tracing"))]
self.resource_span.in_scope(|| {
tracing::trace!(
target: "runtime::resource::state_update",
locked = false,
);
});
}
}
impl<T: ?Sized, U: ?Sized> Deref for OwnedMappedMutexGuard<T, U> {
typ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 8463af92afb398aa94600eaac84eafe3ee83b737 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8463af92afb398aa94600eaac84eafe3ee83b737/tokio/src/sync/mutex.rs | 1,361 | 1,395 |
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 | 3468b4b72f4e5a5ae89b1ff059ccde576dceb459 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3468b4b72f4e5a5ae89b1ff059ccde576dceb459/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 | 3468b4b72f4e5a5ae89b1ff059ccde576dceb459 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3468b4b72f4e5a5ae89b1ff059ccde576dceb459/tokio/src/sync/mutex.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:6 | ///
/// [`OwnedMutexGuard::map`]: method@OwnedMutexGuard::map
#[clippy::has_significant_drop]
#[must_use = "if unused the Mutex will immediately unlock"]
pub struct OwnedMappedMutexGuard<T: ?Sized, U: ?Sized = T> {
// When changing the fields in this struct, make sure to update the
// `skip_drop` method.
#[... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 3468b4b72f4e5a5ae89b1ff059ccde576dceb459 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3468b4b72f4e5a5ae89b1ff059ccde576dceb459/tokio/src/sync/mutex.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:7 | /// A helper type used when taking apart a `OwnedMappedMutexGuard` without running
/// its Drop implementation.
#[allow(dead_code)] // Unused fields are still used in Drop.
struct OwnedMappedMutexGuardInner<T: ?Sized, U: ?Sized> {
#[cfg(all(tokio_unstable, feature = "tracing"))]
resource_span: tracing::Span,
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 3468b4b72f4e5a5ae89b1ff059ccde576dceb459 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3468b4b72f4e5a5ae89b1ff059ccde576dceb459/tokio/src/sync/mutex.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:8 | ///
/// `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(Debug)]
pub struct TryLockErro... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 3468b4b72f4e5a5ae89b1ff059ccde576dceb459 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3468b4b72f4e5a5ae89b1ff059ccde576dceb459/tokio/src/sync/mutex.rs | 281 | 340 |
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 | 3468b4b72f4e5a5ae89b1ff059ccde576dceb459 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3468b4b72f4e5a5ae89b1ff059ccde576dceb459/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 | 3468b4b72f4e5a5ae89b1ff059ccde576dceb459 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3468b4b72f4e5a5ae89b1ff059ccde576dceb459/tokio/src/sync/mutex.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:11 | }
/// Locks this mutex, causing the current task to yield until the lock has
/// been acquired. When the lock has been acquired, function returns a
/// [`MutexGuard`].
///
/// If the mutex is available to be acquired immediately, then this call
/// will typically not yield to the runtime. Howe... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 3468b4b72f4e5a5ae89b1ff059ccde576dceb459 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3468b4b72f4e5a5ae89b1ff059ccde576dceb459/tokio/src/sync/mutex.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:12 | #[cfg(all(tokio_unstable, feature = "tracing"))]
let acquire_fut = trace::async_op(
move || acquire_fut,
self.resource_span.clone(),
"Mutex::lock",
"poll",
false,
);
#[allow(clippy::let_and_return)] // this lint triggers when disabling... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 3468b4b72f4e5a5ae89b1ff059ccde576dceb459 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3468b4b72f4e5a5ae89b1ff059ccde576dceb459/tokio/src/sync/mutex.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:15 | ///
/// // Assert uncontended.
/// let n = mutex.try_lock().unwrap();
/// assert_eq!(*n, 2);
/// }
///
/// ```
#[track_caller]
#[cfg(feature = "sync")]
pub fn blocking_lock_owned(self: Arc<Self>) -> OwnedMutexGuard<T> {
crate::future::block_on(self.lock_owned())
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 3468b4b72f4e5a5ae89b1ff059ccde576dceb459 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3468b4b72f4e5a5ae89b1ff059ccde576dceb459/tokio/src/sync/mutex.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:16 | /// 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> {
#[cfg(all(tokio_unstable... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 3468b4b72f4e5a5ae89b1ff059ccde576dceb459 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3468b4b72f4e5a5ae89b1ff059ccde576dceb459/tokio/src/sync/mutex.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:17 | );
});
guard
}
async fn acquire(&self) {
crate::trace::async_trace_leaf().await;
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 h... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 3468b4b72f4e5a5ae89b1ff059ccde576dceb459 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3468b4b72f4e5a5ae89b1ff059ccde576dceb459/tokio/src/sync/mutex.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:18 | };
#[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 | 3468b4b72f4e5a5ae89b1ff059ccde576dceb459 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3468b4b72f4e5a5ae89b1ff059ccde576dceb459/tokio/src/sync/mutex.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:19 | /// Attempts to acquire the lock, and returns [`TryLockError`] if the lock
/// is currently held somewhere else.
///
/// This method is identical to [`Mutex::try_lock`], except that the
/// returned guard references the `Mutex` with an [`Arc`] rather than by
/// borrowing it. Therefore, the `Mutex`... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 3468b4b72f4e5a5ae89b1ff059ccde576dceb459 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3468b4b72f4e5a5ae89b1ff059ccde576dceb459/tokio/src/sync/mutex.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:20 | Ok(guard)
}
Err(_) => Err(TryLockError(())),
}
}
/// Consumes the mutex, returning the underlying data.
/// # Examples
///
/// ```
/// use tokio::sync::Mutex;
///
/// #[tokio::main]
/// async fn main() {
/// let mutex = Mutex::new(1);
///
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 3468b4b72f4e5a5ae89b1ff059ccde576dceb459 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3468b4b72f4e5a5ae89b1ff059ccde576dceb459/tokio/src/sync/mutex.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:21 | 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");
match self.try_lock() {
Ok(inner) => d.field("data", &&*inner),
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 3468b4b72f4e5a5ae89b1ff059ccde576dceb459 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3468b4b72f4e5a5ae89b1ff059ccde576dceb459/tokio/src/sync/mutex.rs | 801 | 860 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:22 | ///
/// ```
/// 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 | 3468b4b72f4e5a5ae89b1ff059ccde576dceb459 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3468b4b72f4e5a5ae89b1ff059ccde576dceb459/tokio/src/sync/mutex.rs | 841 | 900 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:23 | /// 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 used as `MutexGuard::try_map(...)`. A
/// method would interfere with methods of the same... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 3468b4b72f4e5a5ae89b1ff059ccde576dceb459 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3468b4b72f4e5a5ae89b1ff059ccde576dceb459/tokio/src/sync/mutex.rs | 881 | 940 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:24 | };
let inner = this.skip_drop();
Ok(MappedMutexGuard {
s: &inner.lock.s,
data,
marker: PhantomData,
#[cfg(all(tokio_unstable, feature = "tracing"))]
resource_span: inner.resource_span,
})
}
/// Returns a reference to the origin... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 3468b4b72f4e5a5ae89b1ff059ccde576dceb459 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3468b4b72f4e5a5ae89b1ff059ccde576dceb459/tokio/src/sync/mutex.rs | 921 | 980 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:25 | 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 MutexGuard<'_, ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 3468b4b72f4e5a5ae89b1ff059ccde576dceb459 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3468b4b72f4e5a5ae89b1ff059ccde576dceb459/tokio/src/sync/mutex.rs | 961 | 1,020 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:26 | fn skip_drop(self) -> OwnedMutexGuardInner<T> {
let me = mem::ManuallyDrop::new(self);
// SAFETY: This duplicates the values in every field of the guard, then
// forgets the originals, so in the end no value is duplicated.
unsafe {
OwnedMutexGuardInner {
lock:... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 3468b4b72f4e5a5ae89b1ff059ccde576dceb459 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3468b4b72f4e5a5ae89b1ff059ccde576dceb459/tokio/src/sync/mutex.rs | 1,001 | 1,060 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:27 | /// ```
///
/// [`OwnedMutexGuard`]: struct@OwnedMutexGuard
/// [`OwnedMappedMutexGuard`]: struct@OwnedMappedMutexGuard
#[inline]
pub fn map<U, F>(mut this: Self, f: F) -> OwnedMappedMutexGuard<T, U>
where
U: ?Sized,
F: FnOnce(&mut T) -> &mut U,
{
let data = f(&mut *t... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 3468b4b72f4e5a5ae89b1ff059ccde576dceb459 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3468b4b72f4e5a5ae89b1ff059ccde576dceb459/tokio/src/sync/mutex.rs | 1,041 | 1,100 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:28 | ///
/// {
/// let mut mapped = OwnedMutexGuard::try_map(foo.clone().lock_owned().await, |f| Some(&mut f.0))
/// .expect("should not fail");
/// *mapped = 2;
/// }
///
/// assert_eq!(Foo(2), *foo.lock().await);
/// # }
/// ```
///
/// [`OwnedMutexGuard`]: struc... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 3468b4b72f4e5a5ae89b1ff059ccde576dceb459 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3468b4b72f4e5a5ae89b1ff059ccde576dceb459/tokio/src/sync/mutex.rs | 1,081 | 1,140 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:29 | /// let mutex: Arc<Mutex<u32>> = OwnedMutexGuard::mutex(&guard).clone();
/// drop(guard);
/// let guard = mutex.lock_owned().await;
/// println!("2. contains: {:?}", *guard);
/// guard
/// }
/// #
/// # #[tokio::main]
/// # async fn main() {
/// # let mutex = ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 3468b4b72f4e5a5ae89b1ff059ccde576dceb459 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3468b4b72f4e5a5ae89b1ff059ccde576dceb459/tokio/src/sync/mutex.rs | 1,121 | 1,180 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:30 | 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 | 3468b4b72f4e5a5ae89b1ff059ccde576dceb459 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3468b4b72f4e5a5ae89b1ff059ccde576dceb459/tokio/src/sync/mutex.rs | 1,161 | 1,220 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:31 | #[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.skip_drop();
MappedMutexGuard {
s: inner.s,
data,
marker: PhantomData,
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 3468b4b72f4e5a5ae89b1ff059ccde576dceb459 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3468b4b72f4e5a5ae89b1ff059ccde576dceb459/tokio/src/sync/mutex.rs | 1,201 | 1,260 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:32 | resource_span: inner.resource_span,
})
}
}
impl<'a, T: ?Sized> Drop for MappedMutexGuard<'a, T> {
fn drop(&mut self) {
self.s.release(1);
#[cfg(all(tokio_unstable, feature = "tracing"))]
self.resource_span.in_scope(|| {
tracing::trace!(
target: "runt... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 3468b4b72f4e5a5ae89b1ff059ccde576dceb459 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3468b4b72f4e5a5ae89b1ff059ccde576dceb459/tokio/src/sync/mutex.rs | 1,241 | 1,300 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:33 | fmt::Display::fmt(&**self, f)
}
}
// === impl OwnedMappedMutexGuard ===
impl<T: ?Sized, U: ?Sized> OwnedMappedMutexGuard<T, U> {
fn skip_drop(self) -> OwnedMappedMutexGuardInner<T, U> {
let me = mem::ManuallyDrop::new(self);
// SAFETY: This duplicates the values in every field of the guard, th... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 3468b4b72f4e5a5ae89b1ff059ccde576dceb459 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3468b4b72f4e5a5ae89b1ff059ccde576dceb459/tokio/src/sync/mutex.rs | 1,281 | 1,340 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:34 | resource_span: inner.resource_span,
}
}
/// 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... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 3468b4b72f4e5a5ae89b1ff059ccde576dceb459 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3468b4b72f4e5a5ae89b1ff059ccde576dceb459/tokio/src/sync/mutex.rs | 1,321 | 1,380 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:35 | target: "runtime::resource::state_update",
locked = false,
);
});
}
}
impl<T: ?Sized, U: ?Sized> Deref for OwnedMappedMutexGuard<T, U> {
type Target = U;
fn deref(&self) -> &Self::Target {
unsafe { &*self.data }
}
}
impl<T: ?Sized, U: ?Sized> DerefMut for Ow... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 3468b4b72f4e5a5ae89b1ff059ccde576dceb459 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3468b4b72f4e5a5ae89b1ff059ccde576dceb459/tokio/src/sync/mutex.rs | 1,361 | 1,391 |
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 | 7b555185ff9186f618b198126ee853980b187698 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7b555185ff9186f618b198126ee853980b187698/tokio/src/sync/mutex.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:11 | }
/// Locks this mutex, causing the current task to yield until the lock has
/// been acquired. When the lock has been acquired, function returns a
/// [`MutexGuard`].
///
/// # Cancel safety
///
/// This method uses a queue to fairly distribute locks in the order they
/// were request... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 7b555185ff9186f618b198126ee853980b187698 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7b555185ff9186f618b198126ee853980b187698/tokio/src/sync/mutex.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:12 | "Mutex::lock",
"poll",
false,
);
#[allow(clippy::let_and_return)] // this lint triggers when disabling tracing
let guard = acquire_fut.await;
#[cfg(all(tokio_unstable, feature = "tracing"))]
self.resource_span.in_scope(|| {
tracing::trace!(
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 7b555185ff9186f618b198126ee853980b187698 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7b555185ff9186f618b198126ee853980b187698/tokio/src/sync/mutex.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:15 | /// }
///
/// ```
#[track_caller]
#[cfg(feature = "sync")]
pub fn blocking_lock_owned(self: Arc<Self>) -> OwnedMutexGuard<T> {
crate::future::block_on(self.lock_owned())
}
/// Locks this mutex, causing the current task to yield until the lock has
/// been acquired. When the lock... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 7b555185ff9186f618b198126ee853980b187698 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7b555185ff9186f618b198126ee853980b187698/tokio/src/sync/mutex.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:16 | /// [`Arc`]: std::sync::Arc
pub async fn lock_owned(self: Arc<Self>) -> OwnedMutexGuard<T> {
#[cfg(all(tokio_unstable, feature = "tracing"))]
let resource_span = self.resource_span.clone();
let acquire_fut = async {
self.acquire().await;
OwnedMutexGuard {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 7b555185ff9186f618b198126ee853980b187698 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7b555185ff9186f618b198126ee853980b187698/tokio/src/sync/mutex.rs | 601 | 660 |
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 | 7b555185ff9186f618b198126ee853980b187698 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7b555185ff9186f618b198126ee853980b187698/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... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 7b555185ff9186f618b198126ee853980b187698 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7b555185ff9186f618b198126ee853980b187698/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 = m... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 7b555185ff9186f618b198126ee853980b187698 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7b555185ff9186f618b198126ee853980b187698/tokio/src/sync/mutex.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:20 | /// # Examples
///
/// ```
/// use tokio::sync::Mutex;
///
/// #[tokio::main]
/// async fn main() {
/// let mutex = Mutex::new(1);
///
/// let n = mutex.into_inner();
/// assert_eq!(n, 1);
/// }
/// ```
pub fn into_inner(self) -> T
where
T: Siz... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 7b555185ff9186f618b198126ee853980b187698 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7b555185ff9186f618b198126ee853980b187698/tokio/src/sync/mutex.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:21 | 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()
}
}
// === impl Mutex... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 7b555185ff9186f618b198126ee853980b187698 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7b555185ff9186f618b198126ee853980b187698/tokio/src/sync/mutex.rs | 801 | 860 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:22 | /// # async fn main() {
/// 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@MutexGuar... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 7b555185ff9186f618b198126ee853980b187698 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7b555185ff9186f618b198126ee853980b187698/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.lo... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 7b555185ff9186f618b198126ee853980b187698 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7b555185ff9186f618b198126ee853980b187698/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::mute... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 7b555185ff9186f618b198126ee853980b187698 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7b555185ff9186f618b198126ee853980b187698/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() }
}
}
i... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 7b555185ff9186f618b198126ee853980b187698 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7b555185ff9186f618b198126ee853980b187698/tokio/src/sync/mutex.rs | 961 | 1,020 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:26 | resource_span: ptr::read(&me.resource_span),
}
}
}
/// 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 need... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 7b555185ff9186f618b198126ee853980b187698 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7b555185ff9186f618b198126ee853980b187698/tokio/src/sync/mutex.rs | 1,001 | 1,060 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:27 | F: FnOnce(&mut T) -> &mut U,
{
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,
}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 7b555185ff9186f618b198126ee853980b187698 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7b555185ff9186f618b198126ee853980b187698/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 ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 7b555185ff9186f618b198126ee853980b187698 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7b555185ff9186f618b198126ee853980b187698/tokio/src/sync/mutex.rs | 1,081 | 1,140 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:29 | /// # async fn main() {
/// # 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 Own... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 7b555185ff9186f618b198126ee853980b187698 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7b555185ff9186f618b198126ee853980b187698/tokio/src/sync/mutex.rs | 1,121 | 1,180 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:30 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
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 ===
imp... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 7b555185ff9186f618b198126ee853980b187698 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7b555185ff9186f618b198126ee853980b187698/tokio/src/sync/mutex.rs | 1,161 | 1,220 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:31 | s: inner.s,
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 t... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 7b555185ff9186f618b198126ee853980b187698 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7b555185ff9186f618b198126ee853980b187698/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 | 7b555185ff9186f618b198126ee853980b187698 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7b555185ff9186f618b198126ee853980b187698/tokio/src/sync/mutex.rs | 1,241 | 1,300 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:33 | let me = mem::ManuallyDrop::new(self);
// 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... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 7b555185ff9186f618b198126ee853980b187698 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7b555185ff9186f618b198126ee853980b187698/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@OwnedMappedMutexGu... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 7b555185ff9186f618b198126ee853980b187698 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7b555185ff9186f618b198126ee853980b187698/tokio/src/sync/mutex.rs | 1,321 | 1,380 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:35 | type Target = U;
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 Owne... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 7b555185ff9186f618b198126ee853980b187698 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7b555185ff9186f618b198126ee853980b187698/tokio/src/sync/mutex.rs | 1,361 | 1,383 |
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 | 6871084629ad95c37c7136d865890ab2e371ea12 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6871084629ad95c37c7136d865890ab2e371ea12/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 | 6871084629ad95c37c7136d865890ab2e371ea12 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6871084629ad95c37c7136d865890ab2e371ea12/tokio/src/sync/mutex.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:11 | /// Locks this mutex, causing the current task to yield until the lock has
/// been acquired. When the lock has been acquired, function returns a
/// [`MutexGuard`].
///
/// # Cancel safety
///
/// This method uses a queue to fairly distribute locks in the order they
/// were requested. Can... | 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 | 401 | 460 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:12 | "poll",
false,
);
#[allow(clippy::let_and_return)] // this lint triggers when disabling tracing
let guard = acquire_fut.await;
#[cfg(all(tokio_unstable, feature = "tracing"))]
self.resource_span.in_scope(|| {
tracing::trace!(
target: "run... | 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 | 441 | 500 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:15 | ///
/// ```
#[track_caller]
#[cfg(feature = "sync")]
pub fn blocking_lock_owned(self: Arc<Self>) -> OwnedMutexGuard<T> {
crate::future::block_on(self.lock_owned())
}
/// Locks this mutex, causing the current task to yield until the lock has
/// been acquired. When the lock has been ... | 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 | 561 | 620 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:16 | pub async fn lock_owned(self: Arc<Self>) -> OwnedMutexGuard<T> {
#[cfg(all(tokio_unstable, feature = "tracing"))]
let resource_span = self.resource_span.clone();
let acquire_fut = async {
self.acquire().await;
OwnedMutexGuard {
#[cfg(all(tokio_unstable, ... | 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 | 601 | 660 |
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 | 6871084629ad95c37c7136d865890ab2e371ea12 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6871084629ad95c37c7136d865890ab2e371ea12/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 | 6871084629ad95c37c7136d865890ab2e371ea12 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6871084629ad95c37c7136d865890ab2e371ea12/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 | 6871084629ad95c37c7136d865890ab2e371ea12 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6871084629ad95c37c7136d865890ab2e371ea12/tokio/src/sync/mutex.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:20 | ///
/// ```
/// use tokio::sync::Mutex;
///
/// #[tokio::main]
/// async fn main() {
/// let mutex = Mutex::new(1);
///
/// let n = mutex.into_inner();
/// assert_eq!(n, 1);
/// }
/// ```
pub fn into_inner(self) -> T
where
T: Sized,
{
s... | 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 | 761 | 820 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:21 | 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()
}
}
// === impl MutexGuard ===
impl<'a, T: ?Sized> MutexGuard<'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 | 801 | 860 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.