id stringlengths 22 133 | text stringlengths 40 40.2k | arch stringclasses 1
value | syntax stringclasses 1
value | kind stringclasses 4
values | repo stringclasses 27
values | path stringlengths 5 116 | license stringclasses 6
values | commit stringlengths 40 40 | source_host stringclasses 1
value | category stringclasses 16
values | source_url stringlengths 85 196 | line_start int64 1 4.28k | line_end int64 4 4.31k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
tokio-rs/tokio:tokio/src/sync/mutex.rs:7 | c: UnsafeCell::new(t),
s: semaphore::Semaphore::const_new(1),
}
}
/// 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`].
///
/// # Examples
///
/// ```
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 575938d4579e6fe6a89b700aadb0ae2bbab5483b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/575938d4579e6fe6a89b700aadb0ae2bbab5483b/tokio/src/sync/mutex.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:8 | /// use tokio::sync::Mutex;
/// use std::sync::Arc;
///
/// #[tokio::main]
/// async fn main() {
/// let mutex = Arc::new(Mutex::new(1));
///
/// let mut n = mutex.clone().lock_owned().await;
/// *n = 2;
/// }
/// ```
///
/// [`Arc`]: std::sync::Arc
pub as... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 575938d4579e6fe6a89b700aadb0ae2bbab5483b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/575938d4579e6fe6a89b700aadb0ae2bbab5483b/tokio/src/sync/mutex.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:10 | /// this method, and the guard will live for the `'static` lifetime, as it
/// keeps the `Mutex` alive by holding an `Arc`.
///
/// [`TryLockError`]: TryLockError
/// [`Arc`]: std::sync::Arc
/// # Examples
///
/// ```
/// use tokio::sync::Mutex;
/// use std::sync::Arc;
/// # asyn... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 575938d4579e6fe6a89b700aadb0ae2bbab5483b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/575938d4579e6fe6a89b700aadb0ae2bbab5483b/tokio/src/sync/mutex.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:11 | 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 {
Self::new(T::default())
}
}
impl<T> std::fmt::Debug for Mutex<T>
where
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 575938d4579e6fe6a89b700aadb0ae2bbab5483b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/575938d4579e6fe6a89b700aadb0ae2bbab5483b/tokio/src/sync/mutex.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:12 | self.lock.s.release(1)
}
}
impl<T: ?Sized> Deref for MutexGuard<'_, T> {
type Target = T;
fn deref(&self) -> &Self::Target {
unsafe { &*self.lock.c.get() }
}
}
impl<T: ?Sized> DerefMut for MutexGuard<'_, T> {
fn deref_mut(&mut self) -> &mut Self::Target {
unsafe { &mut *self.lock.c... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 575938d4579e6fe6a89b700aadb0ae2bbab5483b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/575938d4579e6fe6a89b700aadb0ae2bbab5483b/tokio/src/sync/mutex.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:13 | 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: &mut fmt::Formatter<'_>) -> fmt::Result {... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 575938d4579e6fe6a89b700aadb0ae2bbab5483b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/575938d4579e6fe6a89b700aadb0ae2bbab5483b/tokio/src/sync/mutex.rs | 481 | 501 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:4 | }
/// A handle to a held `Mutex`.
///
/// As long as you have this guard, you have exclusive access to the underlying
/// `T`. The guard internally borrows the `Mutex`, so the mutex will not be
/// dropped while a guard exists.
///
/// The lock is automatically released whenever the guard is dropped, at which
/// poin... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 0f70530ee7cda68b68f2f8131b5866cfa937ee1f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0f70530ee7cda68b68f2f8131b5866cfa937ee1f/tokio/src/sync/mutex.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:5 | /// Error returned from the [`Mutex::try_lock`] function.
///
/// A `try_lock` operation can only fail if the mutex is already locked.
///
/// [`Mutex::try_lock`]: Mutex::try_lock
#[derive(Debug)]
pub struct TryLockError(());
impl fmt::Display for TryLockError {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 0f70530ee7cda68b68f2f8131b5866cfa937ee1f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0f70530ee7cda68b68f2f8131b5866cfa937ee1f/tokio/src/sync/mutex.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:6 | 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);
/// ```
pub fn new(t: T) -> Self
where
T: Sized,
{
Self {
c: Unsa... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 0f70530ee7cda68b68f2f8131b5866cfa937ee1f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0f70530ee7cda68b68f2f8131b5866cfa937ee1f/tokio/src/sync/mutex.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:8 | /// #[tokio::main]
/// async fn main() {
/// let mutex = Arc::new(Mutex::new(1));
///
/// let mut n = mutex.clone().lock_owned().await;
/// *n = 2;
/// }
/// ```
///
/// [`Arc`]: std::sync::Arc
pub async fn lock_owned(self: Arc<Self>) -> OwnedMutexGuard<T> {
s... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 0f70530ee7cda68b68f2f8131b5866cfa937ee1f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0f70530ee7cda68b68f2f8131b5866cfa937ee1f/tokio/src/sync/mutex.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:9 | pub fn try_lock(&self) -> Result<MutexGuard<'_, T>, TryLockError> {
match self.s.try_acquire(1) {
Ok(_) => Ok(MutexGuard { lock: self }),
Err(_) => Err(TryLockError(())),
}
}
/// Returns a mutable reference to the underlying data.
///
/// Since this call borrows ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 0f70530ee7cda68b68f2f8131b5866cfa937ee1f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0f70530ee7cda68b68f2f8131b5866cfa937ee1f/tokio/src/sync/mutex.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:10 | /// [`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 | 0f70530ee7cda68b68f2f8131b5866cfa937ee1f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0f70530ee7cda68b68f2f8131b5866cfa937ee1f/tokio/src/sync/mutex.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:11 | self.c.into_inner()
}
}
impl<T> From<T> for Mutex<T> {
fn from(s: T) -> Self {
Self::new(s)
}
}
impl<T> Default for Mutex<T>
where
T: Default,
{
fn default() -> Self {
Self::new(T::default())
}
}
impl<T> std::fmt::Debug for Mutex<T>
where
T: std::fmt::Debug,
{
fn fmt(&... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 0f70530ee7cda68b68f2f8131b5866cfa937ee1f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0f70530ee7cda68b68f2f8131b5866cfa937ee1f/tokio/src/sync/mutex.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:12 | 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: ?Sized... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 0f70530ee7cda68b68f2f8131b5866cfa937ee1f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0f70530ee7cda68b68f2f8131b5866cfa937ee1f/tokio/src/sync/mutex.rs | 441 | 498 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:13 | 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 | 0f70530ee7cda68b68f2f8131b5866cfa937ee1f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0f70530ee7cda68b68f2f8131b5866cfa937ee1f/tokio/src/sync/mutex.rs | 481 | 498 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:8 | /// #[tokio::main]
/// async fn main() {
/// let mutex = Arc::new(Mutex::new(1));
///
/// let mut n = mutex.clone().lock_owned().await;
/// *n = 2;
/// }
/// ```
///
/// [`Arc`]: std::sync::Arc
pub async fn lock_owned(self: Arc<Self>) -> OwnedMutexGuard<T> {
s... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 20ef28655354ae729a4af2098426a413e3f4d769 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/20ef28655354ae729a4af2098426a413e3f4d769/tokio/src/sync/mutex.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:9 | pub fn try_lock(&self) -> Result<MutexGuard<'_, T>, TryLockError> {
match self.s.try_acquire(1) {
Ok(_) => Ok(MutexGuard { lock: self }),
Err(_) => Err(TryLockError(())),
}
}
/// Attempts to acquire the lock, and returns [`TryLockError`] if the lock
/// is currently ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 20ef28655354ae729a4af2098426a413e3f4d769 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/20ef28655354ae729a4af2098426a413e3f4d769/tokio/src/sync/mutex.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:10 | ///
/// ```
/// 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 | 20ef28655354ae729a4af2098426a413e3f4d769 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/20ef28655354ae729a4af2098426a413e3f4d769/tokio/src/sync/mutex.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:11 | 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<T: ?Sized> Drop for MutexGuard<'_, T> {
fn drop(&mut self)... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 20ef28655354ae729a4af2098426a413e3f4d769 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/20ef28655354ae729a4af2098426a413e3f4d769/tokio/src/sync/mutex.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:12 | }
// === impl OwnedMutexGuard ===
impl<T: ?Sized> Drop for OwnedMutexGuard<T> {
fn drop(&mut self) {
self.lock.s.release(1)
}
}
impl<T: ?Sized> Deref for OwnedMutexGuard<T> {
type Target = T;
fn deref(&self) -> &Self::Target {
unsafe { &*self.lock.c.get() }
}
}
impl<T: ?Sized> De... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 20ef28655354ae729a4af2098426a413e3f4d769 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/20ef28655354ae729a4af2098426a413e3f4d769/tokio/src/sync/mutex.rs | 441 | 474 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:6 | 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);
/// ```
pub fn new(t: T) -> Self
where
T: Sized,
{
Self {
c: Unsa... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 8fda719845e5bd90b5222a36155ae559de31a605 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8fda719845e5bd90b5222a36155ae559de31a605/tokio/src/sync/mutex.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:9 | /// 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.clone().try_lock_owned()?;
/// assert_eq!(*n, 1);
/// # Ok(())
/// # }
pub fn try_lock_owned(self... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 8fda719845e5bd90b5222a36155ae559de31a605 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8fda719845e5bd90b5222a36155ae559de31a605/tokio/src/sync/mutex.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:10 | fn from(s: T) -> Self {
Self::new(s)
}
}
impl<T> Default for Mutex<T>
where
T: Default,
{
fn default() -> Self {
Self::new(T::default())
}
}
impl<T> std::fmt::Debug for Mutex<T>
where
T: std::fmt::Debug,
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 8fda719845e5bd90b5222a36155ae559de31a605 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8fda719845e5bd90b5222a36155ae559de31a605/tokio/src/sync/mutex.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:11 | }
}
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 | 8fda719845e5bd90b5222a36155ae559de31a605 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8fda719845e5bd90b5222a36155ae559de31a605/tokio/src/sync/mutex.rs | 401 | 453 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:12 | }
impl<T: ?Sized + fmt::Debug> fmt::Debug for OwnedMutexGuard<T> {
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:... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 8fda719845e5bd90b5222a36155ae559de31a605 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8fda719845e5bd90b5222a36155ae559de31a605/tokio/src/sync/mutex.rs | 441 | 453 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:4 | c: UnsafeCell<T>,
}
/// A handle to a held `Mutex`.
///
/// As long as you have this guard, you have exclusive access to the underlying
/// `T`. The guard internally borrows the `Mutex`, so the mutex will not be
/// dropped while a guard exists.
///
/// The lock is automatically released whenever the guard is dropped,... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | d685bceb030ac7e77446a5ac65e482c6f9612048 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d685bceb030ac7e77446a5ac65e482c6f9612048/tokio/src/sync/mutex.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:5 | unsafe impl<T> Sync for OwnedMutexGuard<T> where T: ?Sized + Send + Sync {}
/// Error returned from the [`Mutex::try_lock`] function.
///
/// A `try_lock` operation can only fail if the mutex is already locked.
///
/// [`Mutex::try_lock`]: Mutex::try_lock
#[derive(Debug)]
pub struct TryLockError(());
impl fmt::Displa... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | d685bceb030ac7e77446a5ac65e482c6f9612048 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d685bceb030ac7e77446a5ac65e482c6f9612048/tokio/src/sync/mutex.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:6 | }
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);
/// ```
pub fn new(t: T) -> Self
where
T: Sized,
{
Self {
c: U... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | d685bceb030ac7e77446a5ac65e482c6f9612048 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d685bceb030ac7e77446a5ac65e482c6f9612048/tokio/src/sync/mutex.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:8 | });
}
/// 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> {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | d685bceb030ac7e77446a5ac65e482c6f9612048 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d685bceb030ac7e77446a5ac65e482c6f9612048/tokio/src/sync/mutex.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:9 | /// ```
/// 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.clone().try_lock_owned()?;
/// assert_eq!(*n, 1);
/// # Ok(())
/// # }
pub fn try_loc... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | d685bceb030ac7e77446a5ac65e482c6f9612048 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d685bceb030ac7e77446a5ac65e482c6f9612048/tokio/src/sync/mutex.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:10 | impl<T> From<T> for Mutex<T> {
fn from(s: T) -> Self {
Self::new(s)
}
}
impl<T> Default for Mutex<T>
where
T: Default,
{
fn default() -> Self {
Self::new(T::default())
}
}
// === impl MutexGuard ===
impl<T: ?Sized> Drop for MutexGuard<'_, T> {
fn drop(&mut self) {
self... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | d685bceb030ac7e77446a5ac65e482c6f9612048 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d685bceb030ac7e77446a5ac65e482c6f9612048/tokio/src/sync/mutex.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:11 | }
impl<T: ?Sized + fmt::Display> fmt::Display for MutexGuard<'_, T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(&**self, f)
}
}
// === impl OwnedMutexGuard ===
impl<T: ?Sized> Drop for OwnedMutexGuard<T> {
fn drop(&mut self) {
self.lock.s.release(1)
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | d685bceb030ac7e77446a5ac65e482c6f9612048 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d685bceb030ac7e77446a5ac65e482c6f9612048/tokio/src/sync/mutex.rs | 401 | 440 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:4 | /// is identical to `MutexGuard`, except that rather than borrowing the `Mutex`,
/// it clones the `Arc`, incrementing the reference count. This means that
/// unlike `MutexGuard`, it will have the `'static` lifetime.
///
/// As long as you have this guard, you have exclusive access to the underlying
/// `T`. The guard... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | d2f81b506a469481ab0b62aaeaf48fc8c60e4c66 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d2f81b506a469481ab0b62aaeaf48fc8c60e4c66/tokio/src/sync/mutex.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:5 | #[test]
#[cfg(not(loom))]
fn bounds() {
fn check_send<T: Send>() {}
fn check_unpin<T: Unpin>() {}
// This has to take a value, since the async fn's return type is unnameable.
fn check_send_sync_val<T: Send + Sync>(_t: T) {}
fn check_send_sync<T: Send + Sync>() {}
fn check_static<T: 'static>() {}... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | d2f81b506a469481ab0b62aaeaf48fc8c60e4c66 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d2f81b506a469481ab0b62aaeaf48fc8c60e4c66/tokio/src/sync/mutex.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:7 | /// use std::sync::Arc;
///
/// #[tokio::main]
/// async fn main() {
/// let mutex = Arc::new(Mutex::new(1));
///
/// let mut n = mutex.clone().lock_owned().await;
/// *n = 2;
/// }
/// ```
///
/// [`Arc`]: std::sync::Arc
pub async fn lock_owned(self: Arc<Self... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | d2f81b506a469481ab0b62aaeaf48fc8c60e4c66 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d2f81b506a469481ab0b62aaeaf48fc8c60e4c66/tokio/src/sync/mutex.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:8 | /// # }
/// ```
pub fn try_lock(&self) -> Result<MutexGuard<'_, T>, TryLockError> {
match self.s.try_acquire(1) {
Ok(_) => Ok(MutexGuard { lock: self }),
Err(_) => Err(TryLockError(())),
}
}
/// Attempts to acquire the lock, and returns [`TryLockError`] if the lo... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | d2f81b506a469481ab0b62aaeaf48fc8c60e4c66 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d2f81b506a469481ab0b62aaeaf48fc8c60e4c66/tokio/src/sync/mutex.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:9 | /// Consumes the mutex, returning the underlying data.
/// # Examples
///
/// ```
/// use tokio::sync::Mutex;
///
/// #[tokio::main]
/// async fn main() {
/// let mutex = Mutex::new(1);
///
/// let n = mutex.into_inner();
/// assert_eq!(n, 1);
/// }
/// ``... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | d2f81b506a469481ab0b62aaeaf48fc8c60e4c66 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d2f81b506a469481ab0b62aaeaf48fc8c60e4c66/tokio/src/sync/mutex.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:10 | fn drop(&mut self) {
self.lock.s.release(1)
}
}
impl<T: ?Sized> Deref for MutexGuard<'_, T> {
type Target = T;
fn deref(&self) -> &Self::Target {
unsafe { &*self.lock.c.get() }
}
}
impl<T: ?Sized> DerefMut for MutexGuard<'_, T> {
fn deref_mut(&mut self) -> &mut Self::Target {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | d2f81b506a469481ab0b62aaeaf48fc8c60e4c66 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d2f81b506a469481ab0b62aaeaf48fc8c60e4c66/tokio/src/sync/mutex.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:11 | 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 | d2f81b506a469481ab0b62aaeaf48fc8c60e4c66 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d2f81b506a469481ab0b62aaeaf48fc8c60e4c66/tokio/src/sync/mutex.rs | 401 | 422 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:4 | /// This guard is only available from a `Mutex` that is wrapped in an [`Arc`]. It
/// is identical to `MutexGuard`, except that rather than borrowing the `Mutex`,
/// it clones the `Arc`, incrementing the reference count. This means that
/// unlike `MutexGuard`, it will have the `'static` lifetime.
///
/// As long as y... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 4010335c84517571e9b2d13f66f7c72170493622 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4010335c84517571e9b2d13f66f7c72170493622/tokio/src/sync/mutex.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:5 | #[test]
#[cfg(not(loom))]
fn bounds() {
fn check_send<T: Send>() {}
fn check_unpin<T: Unpin>() {}
// This has to take a value, since the async fn's return type is unnameable.
fn check_send_sync_val<T: Send + Sync>(_t: T) {}
fn check_send_sync<T: Send + Sync>() {}
fn check_static<T: 'static>() {}... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 4010335c84517571e9b2d13f66f7c72170493622 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4010335c84517571e9b2d13f66f7c72170493622/tokio/src/sync/mutex.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:8 | pub fn try_lock(&self) -> Result<MutexGuard<'_, T>, TryLockError> {
match self.s.try_acquire(1) {
Ok(_) => Ok(MutexGuard { lock: self }),
Err(_) => Err(TryLockError(())),
}
}
/// Attempts to acquire the lock, and returns [`TryLockError`] if the lock
/// is currently ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 4010335c84517571e9b2d13f66f7c72170493622 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4010335c84517571e9b2d13f66f7c72170493622/tokio/src/sync/mutex.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:9 | ///
/// ```
/// 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 {
self.c.into_inner()
}
}
impl... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 4010335c84517571e9b2d13f66f7c72170493622 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4010335c84517571e9b2d13f66f7c72170493622/tokio/src/sync/mutex.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:10 | impl<'a, T> Deref for MutexGuard<'a, T> {
type Target = T;
fn deref(&self) -> &Self::Target {
unsafe { &*self.lock.c.get() }
}
}
impl<'a, T> DerefMut for MutexGuard<'a, T> {
fn deref_mut(&mut self) -> &mut Self::Target {
unsafe { &mut *self.lock.c.get() }
}
}
impl<'a, T: fmt::Debug... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 4010335c84517571e9b2d13f66f7c72170493622 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4010335c84517571e9b2d13f66f7c72170493622/tokio/src/sync/mutex.rs | 361 | 417 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:11 | impl<T> DerefMut for OwnedMutexGuard<T> {
fn deref_mut(&mut self) -> &mut Self::Target {
unsafe { &mut *self.lock.c.get() }
}
}
impl<T: fmt::Debug> fmt::Debug for OwnedMutexGuard<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Debug::fmt(&**self, f)
}
}
impl<T: fmt... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 4010335c84517571e9b2d13f66f7c72170493622 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4010335c84517571e9b2d13f66f7c72170493622/tokio/src/sync/mutex.rs | 401 | 417 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:4 | /// This guard is only available from a `Mutex` that is wrapped in an [`Arc`]. It
/// is identical to `MutexGuard`, except that rather than borrowing the `Mutex`,
/// it clones the `Arc`, incrementing the reference count. This means that
/// unlike `MutexGuard`, it will have the `'static` lifetime.
///
/// As long as y... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | e70a1b6d64ac2b3943d674d8f3b0b362fdc668b9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e70a1b6d64ac2b3943d674d8f3b0b362fdc668b9/tokio/src/sync/mutex.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:4 | ///
/// This guard is only available from a `Mutex` that is wrapped in an [`Arc`]. It
/// is identical to `MutexGuard`, except that rather than borrowing the `Mutex`,
/// it clones the `Arc`, incrementing the reference count. This means that
/// unlike `MutexGuard`, it will have the `'static` lifetime.
///
/// As long ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 45773c56413267cbcf9d5e7877e8dc4afc1e5b07 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/45773c56413267cbcf9d5e7877e8dc4afc1e5b07/tokio/src/sync/mutex.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:5 | impl Error for TryLockError {}
#[test]
#[cfg(not(loom))]
fn bounds() {
fn check_send<T: Send>() {}
fn check_unpin<T: Unpin>() {}
// This has to take a value, since the async fn's return type is unnameable.
fn check_send_sync_val<T: Send + Sync>(_t: T) {}
fn check_send_sync<T: Send + Sync>() {}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 45773c56413267cbcf9d5e7877e8dc4afc1e5b07 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/45773c56413267cbcf9d5e7877e8dc4afc1e5b07/tokio/src/sync/mutex.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:7 | ///
/// #[tokio::main]
/// async fn main() {
/// let mutex = Arc::new(Mutex::new(1));
///
/// let mut n = mutex.clone().lock_owned().await;
/// *n = 2;
/// }
/// ```
///
/// [`Arc`]: std::sync::Arc
pub async fn lock_owned(self: Arc<Self>) -> OwnedMutexGuard<T> {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 45773c56413267cbcf9d5e7877e8dc4afc1e5b07 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/45773c56413267cbcf9d5e7877e8dc4afc1e5b07/tokio/src/sync/mutex.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:8 | /// ```
pub fn try_lock(&self) -> Result<MutexGuard<'_, T>, TryLockError> {
match self.s.try_acquire(1) {
Ok(_) => Ok(MutexGuard { lock: self }),
Err(_) => Err(TryLockError(())),
}
}
/// Attempts to acquire the lock, and returns [`TryLockError`] if the lock
/// i... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 45773c56413267cbcf9d5e7877e8dc4afc1e5b07 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/45773c56413267cbcf9d5e7877e8dc4afc1e5b07/tokio/src/sync/mutex.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:9 | /// # 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 {
self.c.into_in... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 45773c56413267cbcf9d5e7877e8dc4afc1e5b07 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/45773c56413267cbcf9d5e7877e8dc4afc1e5b07/tokio/src/sync/mutex.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:3 | /// the Mutex is "fair" and predictable in how it distributes the locks to inner data. This is why
/// the output of the program above is an in-order count to 50. Locks are released and reacquired
/// after every iteration, so basically, each thread goes to the back of the line after it increments
/// the value once. F... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 6349efd2374624f04a8346b1cbef5b6a896dbf5d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6349efd2374624f04a8346b1cbef5b6a896dbf5d/tokio/src/sync/mutex.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:4 | unsafe impl<T> Sync for Mutex<T> where T: Send {}
unsafe impl<'a, T> Sync for MutexGuard<'a, T> where T: Send + Sync {}
/// Error returned from the [`Mutex::try_lock`] function.
///
/// A `try_lock` operation can only fail if the mutex is already locked.
///
/// [`Mutex::try_lock`]: Mutex::try_lock
#[derive(Debug)]
pu... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 6349efd2374624f04a8346b1cbef5b6a896dbf5d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6349efd2374624f04a8346b1cbef5b6a896dbf5d/tokio/src/sync/mutex.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:5 | /// ```
/// use tokio::sync::Mutex;
///
/// let lock = Mutex::new(5);
/// ```
pub fn new(t: T) -> Self {
Self {
c: UnsafeCell::new(t),
s: semaphore::Semaphore::new(1),
}
}
/// Locks this mutex, causing the current task
/// to yield until the lock ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 6349efd2374624f04a8346b1cbef5b6a896dbf5d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6349efd2374624f04a8346b1cbef5b6a896dbf5d/tokio/src/sync/mutex.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:6 | ///
/// [`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 | 6349efd2374624f04a8346b1cbef5b6a896dbf5d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6349efd2374624f04a8346b1cbef5b6a896dbf5d/tokio/src/sync/mutex.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:7 | impl<'a, T> Drop for MutexGuard<'a, T> {
fn drop(&mut self) {
self.lock.s.release(1)
}
}
impl<T> From<T> for Mutex<T> {
fn from(s: T) -> Self {
Self::new(s)
}
}
impl<T> Default for Mutex<T>
where
T: Default,
{
fn default() -> Self {
Self::new(T::default())
}
}
impl... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 6349efd2374624f04a8346b1cbef5b6a896dbf5d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6349efd2374624f04a8346b1cbef5b6a896dbf5d/tokio/src/sync/mutex.rs | 241 | 286 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:3 | use crate::coop::CoopFutureExt;
use crate::sync::batch_semaphore as semaphore;
use std::cell::UnsafeCell;
use std::error::Error;
use std::fmt;
use std::ops::{Deref, DerefMut};
/// An asynchronous mutual exclusion primitive useful for protecting shared data
///
/// Each mutex has a type parameter (`T`) which represent... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | f39c15334e74b07a44efaa0f7201262e17e4f062 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f39c15334e74b07a44efaa0f7201262e17e4f062/tokio/src/sync/mutex.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:4 | /// A `try_lock` operation can only fail if the mutex is already locked.
///
/// [`Mutex::try_lock`]: Mutex::try_lock
#[derive(Debug)]
pub struct TryLockError(());
impl fmt::Display for TryLockError {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(fmt, "{}", "operation would block")
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | f39c15334e74b07a44efaa0f7201262e17e4f062 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f39c15334e74b07a44efaa0f7201262e17e4f062/tokio/src/sync/mutex.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:5 | pub async fn lock(&self) -> MutexGuard<'_, T> {
self.s.acquire(1).cooperate().await.unwrap_or_else(|_| {
// The semaphore was closed. but, we never explicitly close it, and we have a
// handle to it through the Arc, which means that this can never happen.
unreachable!()
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | f39c15334e74b07a44efaa0f7201262e17e4f062 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f39c15334e74b07a44efaa0f7201262e17e4f062/tokio/src/sync/mutex.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:6 | Self::new(T::default())
}
}
impl<'a, T> Deref for MutexGuard<'a, T> {
type Target = T;
fn deref(&self) -> &Self::Target {
unsafe { &*self.lock.c.get() }
}
}
impl<'a, T> DerefMut for MutexGuard<'a, T> {
fn deref_mut(&mut self) -> &mut Self::Target {
unsafe { &mut *self.lock.c.get() ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | f39c15334e74b07a44efaa0f7201262e17e4f062 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f39c15334e74b07a44efaa0f7201262e17e4f062/tokio/src/sync/mutex.rs | 201 | 228 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:3 | use crate::coop::CoopFutureExt;
use crate::sync::batch_semaphore as semaphore;
use std::cell::UnsafeCell;
use std::error::Error;
use std::fmt;
use std::ops::{Deref, DerefMut};
/// An asynchronous mutual exclusion primitive useful for protecting shared data
///
/// Each mutex has a type parameter (`T`) which represent... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | acf8a7da7a64bf08d578db9a9836a8e061765314 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/acf8a7da7a64bf08d578db9a9836a8e061765314/tokio/src/sync/mutex.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:4 | /// A `try_lock` operation can only fail if the mutex is already locked.
///
/// [`Mutex::try_lock`]: Mutex::try_lock
#[derive(Debug)]
pub struct TryLockError(());
impl fmt::Display for TryLockError {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(fmt, "{}", "operation would block")
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | acf8a7da7a64bf08d578db9a9836a8e061765314 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/acf8a7da7a64bf08d578db9a9836a8e061765314/tokio/src/sync/mutex.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:5 | }
/// Tries to acquire the lock
pub fn try_lock(&self) -> Result<MutexGuard<'_, T>, TryLockError> {
match self.s.try_acquire(1) {
Ok(_) => Ok(MutexGuard { lock: self }),
Err(_) => Err(TryLockError(())),
}
}
/// Consumes the mutex, returning the underlying data.
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | acf8a7da7a64bf08d578db9a9836a8e061765314 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/acf8a7da7a64bf08d578db9a9836a8e061765314/tokio/src/sync/mutex.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:6 | unsafe { &*self.lock.c.get() }
}
}
impl<'a, T> DerefMut for MutexGuard<'a, T> {
fn deref_mut(&mut self) -> &mut Self::Target {
unsafe { &mut *self.lock.c.get() }
}
}
impl<'a, T: fmt::Debug> fmt::Debug for MutexGuard<'a, T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fm... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | acf8a7da7a64bf08d578db9a9836a8e061765314 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/acf8a7da7a64bf08d578db9a9836a8e061765314/tokio/src/sync/mutex.rs | 201 | 221 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:3 | use crate::future::poll_fn;
use crate::sync::semaphore_ll as semaphore;
use std::cell::UnsafeCell;
use std::error::Error;
use std::fmt;
use std::ops::{Deref, DerefMut};
/// An asynchronous mutual exclusion primitive useful for protecting shared data
///
/// Each mutex has a type parameter (`T`) which represents the d... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 06a4d895ec8787386058a24b422dfa9a8514bc8e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/06a4d895ec8787386058a24b422dfa9a8514bc8e/tokio/src/sync/mutex.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:4 | /// Error returned from the [`Mutex::try_lock`] function.
///
/// A `try_lock` operation can only fail if the mutex is already locked.
///
/// [`Mutex::try_lock`]: Mutex::try_lock
#[derive(Debug)]
pub struct TryLockError(());
impl fmt::Display for TryLockError {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 06a4d895ec8787386058a24b422dfa9a8514bc8e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/06a4d895ec8787386058a24b422dfa9a8514bc8e/tokio/src/sync/mutex.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:5 | ready!(crate::coop::poll_proceed(cx));
guard.permit.poll_acquire(cx, 1, &self.s)
})
.await
.unwrap_or_else(|_| {
// The semaphore was closed. but, we never explicitly close it, and we have a
// handle to it through the Arc, which means that this can never hap... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 06a4d895ec8787386058a24b422dfa9a8514bc8e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/06a4d895ec8787386058a24b422dfa9a8514bc8e/tokio/src/sync/mutex.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:6 | impl<T> Default for Mutex<T>
where
T: Default,
{
fn default() -> Self {
Self::new(T::default())
}
}
impl<'a, T> Deref for MutexGuard<'a, T> {
type Target = T;
fn deref(&self) -> &Self::Target {
assert!(self.permit.is_acquired());
unsafe { &*self.lock.c.get() }
}
}
impl<... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 06a4d895ec8787386058a24b422dfa9a8514bc8e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/06a4d895ec8787386058a24b422dfa9a8514bc8e/tokio/src/sync/mutex.rs | 201 | 235 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:4 | /// Error returned from the [`Mutex::try_lock`] function.
///
/// A `try_lock` operation can only fail if the mutex is already locked.
///
/// [`Mutex::try_lock`]: Mutex::try_lock
#[derive(Debug)]
pub struct TryLockError(());
impl fmt::Display for TryLockError {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 09b5f47381dba99e1fcf666e0639cff627048ad2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/09b5f47381dba99e1fcf666e0639cff627048ad2/tokio/src/sync/mutex.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:5 | .unwrap_or_else(|_| {
// The semaphore was closed. but, we never explicitly close it, and we have a
// handle to it through the Arc, which means that this can never happen.
unreachable!()
});
guard
}
/// Tries to acquire the lock
pub fn tr... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 09b5f47381dba99e1fcf666e0639cff627048ad2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/09b5f47381dba99e1fcf666e0639cff627048ad2/tokio/src/sync/mutex.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:6 | Self::new(T::default())
}
}
impl<'a, T> Deref for MutexGuard<'a, T> {
type Target = T;
fn deref(&self) -> &Self::Target {
assert!(self.permit.is_acquired());
unsafe { &*self.lock.c.get() }
}
}
impl<'a, T> DerefMut for MutexGuard<'a, T> {
fn deref_mut(&mut self) -> &mut Self::Target... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 09b5f47381dba99e1fcf666e0639cff627048ad2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/09b5f47381dba99e1fcf666e0639cff627048ad2/tokio/src/sync/mutex.rs | 201 | 230 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:4 | /// Error returned from the [`Mutex::try_lock`] function.
///
/// A `try_lock` operation can only fail if the mutex is already locked.
///
/// [`Mutex::try_lock`]: Mutex::try_lock
#[derive(Debug)]
pub struct TryLockError(());
impl fmt::Display for TryLockError {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | f9ddb93604a830d106475bd4c4cae436fafcc0da | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f9ddb93604a830d106475bd4c4cae436fafcc0da/tokio/src/sync/mutex.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:5 | .unwrap_or_else(|_| {
// The semaphore was closed. but, we never explicitly close it, and we have a
// handle to it through the Arc, which means that this can never happen.
unreachable!()
});
guard
}
/// Tries to acquire the lock
pub fn tr... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | f9ddb93604a830d106475bd4c4cae436fafcc0da | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f9ddb93604a830d106475bd4c4cae436fafcc0da/tokio/src/sync/mutex.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:6 | type Target = T;
fn deref(&self) -> &Self::Target {
assert!(self.permit.is_acquired());
unsafe { &*self.lock.c.get() }
}
}
impl<'a, T> DerefMut for MutexGuard<'a, T> {
fn deref_mut(&mut self) -> &mut Self::Target {
assert!(self.permit.is_acquired());
unsafe { &mut *self.lock... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | f9ddb93604a830d106475bd4c4cae436fafcc0da | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f9ddb93604a830d106475bd4c4cae436fafcc0da/tokio/src/sync/mutex.rs | 201 | 225 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:4 | /// Error returned from the [`Mutex::try_lock`] function.
///
/// A `try_lock` operation can only fail if the mutex is already locked.
///
/// [`Mutex::try_lock`]: Mutex::try_lock
#[derive(Debug)]
pub struct TryLockError(());
impl fmt::Display for TryLockError {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | efcbf9613f2d5048550f9c828e3be422644f1391 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/efcbf9613f2d5048550f9c828e3be422644f1391/tokio/src/sync/mutex.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:5 | .unwrap_or_else(|_| {
// The semaphore was closed. but, we never explicitly close it, and we have a
// handle to it through the Arc, which means that this can never happen.
unreachable!()
});
guard
}
/// Try to acquire the lock
pub fn try_... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | efcbf9613f2d5048550f9c828e3be422644f1391 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/efcbf9613f2d5048550f9c828e3be422644f1391/tokio/src/sync/mutex.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:4 | /// Error returned from the [`Mutex::try_lock`] function.
///
/// A `try_lock` operation can only fail if the mutex is already locked.
///
/// [`Mutex::try_lock`]: Mutex::try_lock
#[derive(Debug)]
pub struct TryLockError(());
impl fmt::Display for TryLockError {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 6ff4e349e28a4d89098f2587e70c86281c2ae182 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6ff4e349e28a4d89098f2587e70c86281c2ae182/tokio/src/sync/mutex.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:5 | .unwrap_or_else(|_| {
// The semaphore was closed. but, we never explicitly close it, and we have a
// handle to it through the Arc, which means that this can never happen.
unreachable!()
});
guard
}
/// Try to acquire the lock
pub fn try_... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 6ff4e349e28a4d89098f2587e70c86281c2ae182 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6ff4e349e28a4d89098f2587e70c86281c2ae182/tokio/src/sync/mutex.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:2 | use std::error::Error;
use std::fmt;
use std::ops::{Deref, DerefMut};
/// An asynchronous mutual exclusion primitive useful for protecting shared data
///
/// Each mutex has a type parameter (`T`) which represents the data that it is protecting. The data
/// can only be accessed through the RAII guards returned from `... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | b0836ece7aa5219e9e40355d0eb784baffc7b6c6 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b0836ece7aa5219e9e40355d0eb784baffc7b6c6/tokio/src/sync/mutex.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:3 | #[derive(Debug)]
pub struct TryLockError(());
impl fmt::Display for TryLockError {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(fmt, "{}", "operation would block")
}
}
impl Error for TryLockError {}
#[test]
#[cfg(not(loom))]
fn bounds() {
fn check<T: Send>() {}
check::<... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | b0836ece7aa5219e9e40355d0eb784baffc7b6c6 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b0836ece7aa5219e9e40355d0eb784baffc7b6c6/tokio/src/sync/mutex.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:4 | guard
}
/// Try to acquire the lock
pub fn try_lock(&self) -> Result<MutexGuard<'_, T>, TryLockError> {
let mut permit = semaphore::Permit::new();
match permit.try_acquire(&self.s) {
Ok(_) => Ok(MutexGuard { lock: self, permit }),
Err(_) => Err(TryLockError(())),
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | b0836ece7aa5219e9e40355d0eb784baffc7b6c6 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b0836ece7aa5219e9e40355d0eb784baffc7b6c6/tokio/src/sync/mutex.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:5 | }
impl<'a, T> DerefMut for MutexGuard<'a, T> {
fn deref_mut(&mut self) -> &mut Self::Target {
assert!(self.permit.is_acquired());
unsafe { &mut *self.lock.c.get() }
}
}
impl<'a, T: fmt::Debug> fmt::Debug for MutexGuard<'a, T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | b0836ece7aa5219e9e40355d0eb784baffc7b6c6 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b0836ece7aa5219e9e40355d0eb784baffc7b6c6/tokio/src/sync/mutex.rs | 161 | 180 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:2 | use std::error::Error;
use std::fmt;
use std::ops::{Deref, DerefMut};
/// An asynchronous mutual exclusion primitive useful for protecting shared data
///
/// Each mutex has a type parameter (`T`) which represents the data that it is protecting. The data
/// can only be accessed through the RAII guards returned from `... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 9211adbe01661585cd1831214279262024d04816 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/9211adbe01661585cd1831214279262024d04816/tokio/src/sync/mutex.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:3 | /// The lock could not be acquired at this time because the operation
/// would otherwise block.
WouldBlock,
}
impl fmt::Display for TryLockError {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
fmt,
"{}",
match self {
TryLoc... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 9211adbe01661585cd1831214279262024d04816 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/9211adbe01661585cd1831214279262024d04816/tokio/src/sync/mutex.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:4 | };
poll_fn(|cx| guard.permit.poll_acquire(cx, &self.s))
.await
.unwrap_or_else(|_| {
// The semaphore was closed. but, we never explicitly close it, and we have a
// handle to it through the Arc, which means that this can never happen.
unre... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 9211adbe01661585cd1831214279262024d04816 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/9211adbe01661585cd1831214279262024d04816/tokio/src/sync/mutex.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:5 | }
impl<'a, T> Deref for MutexGuard<'a, T> {
type Target = T;
fn deref(&self) -> &Self::Target {
assert!(self.permit.is_acquired());
unsafe { &*self.lock.c.get() }
}
}
impl<'a, T> DerefMut for MutexGuard<'a, T> {
fn deref_mut(&mut self) -> &mut Self::Target {
assert!(self.permit... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 9211adbe01661585cd1831214279262024d04816 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/9211adbe01661585cd1831214279262024d04816/tokio/src/sync/mutex.rs | 161 | 188 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:2 | use std::error::Error;
use std::fmt;
use std::ops::{Deref, DerefMut};
/// An asynchronous mutual exclusion primitive useful for protecting shared data
///
/// Each mutex has a type parameter (`T`) which represents the data that it is protecting. The data
/// can only be accessed through the RAII guards returned from `... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | e5b99b0f7a12ca27b390535b8628f87a61a08eb6 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e5b99b0f7a12ca27b390535b8628f87a61a08eb6/tokio/src/sync/mutex.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:3 | /// The lock could not be acquired at this time because the operation
/// would otherwise block.
WouldBlock,
}
impl fmt::Display for TryLockError {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
fmt,
"{}",
match self {
TryLoc... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | e5b99b0f7a12ca27b390535b8628f87a61a08eb6 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e5b99b0f7a12ca27b390535b8628f87a61a08eb6/tokio/src/sync/mutex.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:4 | };
poll_fn(|cx| guard.permit.poll_acquire(cx, &self.s))
.await
.unwrap_or_else(|_| {
// The semaphore was closed. but, we never explicitly close it, and we have a
// handle to it through the Arc, which means that this can never happen.
unre... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | e5b99b0f7a12ca27b390535b8628f87a61a08eb6 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e5b99b0f7a12ca27b390535b8628f87a61a08eb6/tokio/src/sync/mutex.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:2 | use std::error::Error;
use std::fmt;
use std::ops::{Deref, DerefMut};
/// An asynchronous mutual exclusion primitive useful for protecting shared data
///
/// Each mutex has a type parameter (`T`) which represents the data that it is protecting. The data
/// can only be accessed through the RAII guards returned from `... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 975576952f33c64e4faaa616f67ae9d6b596e4aa | github | async-runtime | https://github.com/tokio-rs/tokio/blob/975576952f33c64e4faaa616f67ae9d6b596e4aa/tokio/src/sync/mutex.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:3 | pub enum TryLockError {
/// The lock could not be acquired at this time because the operation
/// would otherwise block.
WouldBlock,
}
impl fmt::Display for TryLockError {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
fmt,
"{}",
match s... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 975576952f33c64e4faaa616f67ae9d6b596e4aa | github | async-runtime | https://github.com/tokio-rs/tokio/blob/975576952f33c64e4faaa616f67ae9d6b596e4aa/tokio/src/sync/mutex.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:4 | permit: semaphore::Permit::new(),
};
poll_fn(|cx| guard.permit.poll_acquire(cx, &self.s))
.await
.unwrap_or_else(|_| {
// The semaphore was closed. but, we never explicitly close it, and we have a
// handle to it through the Arc, which means that t... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 975576952f33c64e4faaa616f67ae9d6b596e4aa | github | async-runtime | https://github.com/tokio-rs/tokio/blob/975576952f33c64e4faaa616f67ae9d6b596e4aa/tokio/src/sync/mutex.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:5 | }
}
impl<'a, T> Deref for MutexGuard<'a, T> {
type Target = T;
fn deref(&self) -> &Self::Target {
assert!(self.permit.is_acquired());
unsafe { &*self.lock.c.get() }
}
}
impl<'a, T> DerefMut for MutexGuard<'a, T> {
fn deref_mut(&mut self) -> &mut Self::Target {
assert!(self.perm... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 975576952f33c64e4faaa616f67ae9d6b596e4aa | github | async-runtime | https://github.com/tokio-rs/tokio/blob/975576952f33c64e4faaa616f67ae9d6b596e4aa/tokio/src/sync/mutex.rs | 161 | 183 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:2 | use std::fmt;
use std::ops::{Deref, DerefMut};
/// An asynchronous mutual exclusion primitive useful for protecting shared data
///
/// Each mutex has a type parameter (`T`) which represents the data that it is protecting. The data
/// can only be accessed through the RAII guards returned from `lock`, which
/// guaran... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 41ffdbb7d9396708bed868906cd5da837377c9fc | github | async-runtime | https://github.com/tokio-rs/tokio/blob/41ffdbb7d9396708bed868906cd5da837377c9fc/tokio/src/sync/mutex.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:3 | }
impl<T> Mutex<T> {
/// Creates a new lock in an unlocked state ready for use.
pub fn new(t: T) -> Self {
Self {
c: UnsafeCell::new(t),
s: semaphore::Semaphore::new(1),
}
}
/// A future that resolves on acquiring the lock and returns the `MutexGuard`.
pub a... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 41ffdbb7d9396708bed868906cd5da837377c9fc | github | async-runtime | https://github.com/tokio-rs/tokio/blob/41ffdbb7d9396708bed868906cd5da837377c9fc/tokio/src/sync/mutex.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:4 | impl<T> Default for Mutex<T>
where
T: Default,
{
fn default() -> Self {
Self::new(T::default())
}
}
impl<'a, T> Deref for MutexGuard<'a, T> {
type Target = T;
fn deref(&self) -> &Self::Target {
assert!(self.permit.is_acquired());
unsafe { &*self.lock.c.get() }
}
}
impl<... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 41ffdbb7d9396708bed868906cd5da837377c9fc | github | async-runtime | https://github.com/tokio-rs/tokio/blob/41ffdbb7d9396708bed868906cd5da837377c9fc/tokio/src/sync/mutex.rs | 121 | 149 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:2 | /// Each mutex has a type parameter (`T`) which represents the data that it is protecting. The data
/// can only be accessed through the RAII guards returned from `lock`, which
/// guarantees that the data is only ever accessed when the mutex is locked.
#[derive(Debug)]
pub struct Mutex<T> {
c: UnsafeCell<T>,
s... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | c632337e6f94013d9d39495f1d442351e6fbf6b6 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c632337e6f94013d9d39495f1d442351e6fbf6b6/tokio/src/sync/mutex.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:3 | Self {
c: UnsafeCell::new(t),
s: semaphore::Semaphore::new(1),
}
}
/// A future that resolves on acquiring the lock and returns the `MutexGuard`.
pub async fn lock(&self) -> MutexGuard<'_, T> {
let mut guard = MutexGuard {
lock: self,
permit: ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | c632337e6f94013d9d39495f1d442351e6fbf6b6 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c632337e6f94013d9d39495f1d442351e6fbf6b6/tokio/src/sync/mutex.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:4 | Self::new(T::default())
}
}
impl<'a, T> Deref for MutexGuard<'a, T> {
type Target = T;
fn deref(&self) -> &Self::Target {
assert!(self.permit.is_acquired());
unsafe { &*self.lock.c.get() }
}
}
impl<'a, T> DerefMut for MutexGuard<'a, T> {
fn deref_mut(&mut self) -> &mut Self::Target... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | c632337e6f94013d9d39495f1d442351e6fbf6b6 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c632337e6f94013d9d39495f1d442351e6fbf6b6/tokio/src/sync/mutex.rs | 121 | 144 |
tokio-rs/tokio:tokio/src/sync/mutex.rs:2 | /// Each mutex has a type parameter (`T`) which represents the data that it is protecting. The data
/// can only be accessed through the RAII guards returned from `lock`, which
/// guarantees that the data is only ever accessed when the mutex is locked.
#[derive(Debug)]
pub struct Mutex<T> {
c: UnsafeCell<T>,
s... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 8a7e57786a5dca139f5b4261685e22991ded0859 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8a7e57786a5dca139f5b4261685e22991ded0859/tokio/src/sync/mutex.rs | 41 | 100 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.