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/rwlock/write_guard.rs:7 | target: "runtime::resource::state_update",
current_readers = 1,
current_readers.op = "add",
)
});
guard
}
}
impl<T: ?Sized> ops::Deref for RwLockWriteGuard<'_, T> {
type Target = T;
fn deref(&self) -> &T {
unsafe { &*self.data }
}
}
impl<T:... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard.rs | MIT | 24aac0add3547803b571e9d5c6d6c3ecbd09bb5b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/24aac0add3547803b571e9d5c6d6c3ecbd09bb5b/tokio/src/sync/rwlock/write_guard.rs | 241 | 296 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard.rs:8 | }
impl<'a, T: ?Sized> Drop for RwLockWriteGuard<'a, T> {
fn drop(&mut self) {
self.s.release(self.permits_acquired as usize);
#[cfg(all(tokio_unstable, feature = "tracing"))]
self.resource_span.in_scope(|| {
tracing::trace!(
target: "runtime::resource::state_update"... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard.rs | MIT | 24aac0add3547803b571e9d5c6d6c3ecbd09bb5b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/24aac0add3547803b571e9d5c6d6c3ecbd09bb5b/tokio/src/sync/rwlock/write_guard.rs | 281 | 296 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard.rs:1 | use crate::sync::batch_semaphore::Semaphore;
use crate::sync::rwlock::read_guard::RwLockReadGuard;
use crate::sync::rwlock::write_guard_mapped::RwLockMappedWriteGuard;
use std::fmt;
use std::marker;
use std::mem;
use std::ops;
/// RAII structure used to release the exclusive write access of a lock when
/// dropped.
//... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard.rs | MIT | d6dbefcdc043da552615bf2c8ad1f3a9580a1735 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d6dbefcdc043da552615bf2c8ad1f3a9580a1735/tokio/src/sync/rwlock/write_guard.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard.rs:2 | /// [`RwLockMappedWriteGuard`]: struct@crate::sync::RwLockMappedWriteGuard
/// [`RwLockWriteGuard::map`]: https://docs.rs/lock_api/latest/lock_api/struct.RwLockWriteGuard.html#method.map
/// [`parking_lot` crate]: https://crates.io/crates/parking_lot
///
/// # Examples
///
/// ```
/// use to... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard.rs | MIT | d6dbefcdc043da552615bf2c8ad1f3a9580a1735 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d6dbefcdc043da552615bf2c8ad1f3a9580a1735/tokio/src/sync/rwlock/write_guard.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard.rs:3 | marker: marker::PhantomData,
#[cfg(all(tokio_unstable, feature = "tracing"))]
resource_span,
}
}
/// Attempts to make a new [`RwLockMappedWriteGuard`] for a component of
/// the locked data. The original guard is returned if the closure returns
/// `None`.
///
/... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard.rs | MIT | d6dbefcdc043da552615bf2c8ad1f3a9580a1735 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d6dbefcdc043da552615bf2c8ad1f3a9580a1735/tokio/src/sync/rwlock/write_guard.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard.rs:4 | /// }
///
/// assert_eq!(Foo(2), *lock.read().await);
/// # }
/// ```
#[inline]
pub fn try_map<F, U: ?Sized>(
mut this: Self,
f: F,
) -> Result<RwLockMappedWriteGuard<'a, U>, Self>
where
F: FnOnce(&mut T) -> Option<&mut U>,
{
let data = match f(&mut *t... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard.rs | MIT | d6dbefcdc043da552615bf2c8ad1f3a9580a1735 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d6dbefcdc043da552615bf2c8ad1f3a9580a1735/tokio/src/sync/rwlock/write_guard.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard.rs:5 | RwLockWriteGuard::map(this, |me| me)
}
/// Atomically downgrades a write lock into a read lock without allowing
/// any writers to take exclusive access of the lock in the meantime.
///
/// **Note:** This won't *necessarily* allow any additional readers to acquire
/// locks, since [`RwLock`] is... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard.rs | MIT | d6dbefcdc043da552615bf2c8ad1f3a9580a1735 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d6dbefcdc043da552615bf2c8ad1f3a9580a1735/tokio/src/sync/rwlock/write_guard.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard.rs:6 | pub fn downgrade(self) -> RwLockReadGuard<'a, T> {
let RwLockWriteGuard { s, data, .. } = self;
let to_release = (self.permits_acquired - 1) as usize;
// Release all but one of the permits held by the write guard
s.release(to_release);
#[cfg(all(tokio_unstable, feature = "tracing... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard.rs | MIT | d6dbefcdc043da552615bf2c8ad1f3a9580a1735 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d6dbefcdc043da552615bf2c8ad1f3a9580a1735/tokio/src/sync/rwlock/write_guard.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard.rs:7 | fn deref(&self) -> &T {
unsafe { &*self.data }
}
}
impl<T: ?Sized> ops::DerefMut for RwLockWriteGuard<'_, T> {
fn deref_mut(&mut self) -> &mut T {
unsafe { &mut *self.data }
}
}
impl<'a, T: ?Sized> fmt::Debug for RwLockWriteGuard<'a, T>
where
T: fmt::Debug,
{
fn fmt(&self, f: &mut ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard.rs | MIT | d6dbefcdc043da552615bf2c8ad1f3a9580a1735 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d6dbefcdc043da552615bf2c8ad1f3a9580a1735/tokio/src/sync/rwlock/write_guard.rs | 241 | 284 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard.rs:1 | use crate::sync::batch_semaphore::Semaphore;
use crate::sync::rwlock::read_guard::RwLockReadGuard;
use crate::sync::rwlock::write_guard_mapped::RwLockMappedWriteGuard;
use std::fmt;
use std::marker;
use std::mem;
use std::ops;
/// RAII structure used to release the exclusive write access of a lock when
/// dropped.
//... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard.rs | MIT | ff6fbc327dcd8f8d023dbe7b684d9ca13ac3aec4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ff6fbc327dcd8f8d023dbe7b684d9ca13ac3aec4/tokio/src/sync/rwlock/write_guard.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard.rs:2 | /// [`RwLockWriteGuard::map`]: https://docs.rs/lock_api/latest/lock_api/struct.RwLockWriteGuard.html#method.map
/// [`parking_lot` crate]: https://crates.io/crates/parking_lot
///
/// # Examples
///
/// ```
/// use tokio::sync::{RwLock, RwLockWriteGuard};
///
/// #[derive(Debug, Clone, C... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard.rs | MIT | ff6fbc327dcd8f8d023dbe7b684d9ca13ac3aec4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ff6fbc327dcd8f8d023dbe7b684d9ca13ac3aec4/tokio/src/sync/rwlock/write_guard.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard.rs:3 | #[cfg(all(tokio_unstable, feature = "tracing"))]
resource_span,
}
}
/// Attempts to make a new [`RwLockMappedWriteGuard`] for a component of
/// the locked data. The original guard is returned if the closure returns
/// `None`.
///
/// This operation cannot fail as the `RwL... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard.rs | MIT | ff6fbc327dcd8f8d023dbe7b684d9ca13ac3aec4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ff6fbc327dcd8f8d023dbe7b684d9ca13ac3aec4/tokio/src/sync/rwlock/write_guard.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard.rs:4 | ///
/// assert_eq!(Foo(2), *lock.read().await);
/// # }
/// ```
#[inline]
pub fn try_map<F, U: ?Sized>(
mut this: Self,
f: F,
) -> Result<RwLockMappedWriteGuard<'a, U>, Self>
where
F: FnOnce(&mut T) -> Option<&mut U>,
{
let data = match f(&mut *this) {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard.rs | MIT | ff6fbc327dcd8f8d023dbe7b684d9ca13ac3aec4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ff6fbc327dcd8f8d023dbe7b684d9ca13ac3aec4/tokio/src/sync/rwlock/write_guard.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard.rs:5 | }
/// Atomically downgrades a write lock into a read lock without allowing
/// any writers to take exclusive access of the lock in the meantime.
///
/// **Note:** This won't *necessarily* allow any additional readers to acquire
/// locks, since [`RwLock`] is fair and it is possible that a writer is... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard.rs | MIT | ff6fbc327dcd8f8d023dbe7b684d9ca13ac3aec4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ff6fbc327dcd8f8d023dbe7b684d9ca13ac3aec4/tokio/src/sync/rwlock/write_guard.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard.rs:6 | let RwLockWriteGuard { s, data, .. } = self;
let to_release = (self.permits_acquired - 1) as usize;
// Release all but one of the permits held by the write guard
s.release(to_release);
#[cfg(all(tokio_unstable, feature = "tracing"))]
self.resource_span.in_scope(|| {
t... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard.rs | MIT | ff6fbc327dcd8f8d023dbe7b684d9ca13ac3aec4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ff6fbc327dcd8f8d023dbe7b684d9ca13ac3aec4/tokio/src/sync/rwlock/write_guard.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard.rs:1 | use crate::sync::batch_semaphore::Semaphore;
use crate::sync::rwlock::read_guard::RwLockReadGuard;
use crate::sync::rwlock::write_guard_mapped::RwLockMappedWriteGuard;
use std::fmt;
use std::marker;
use std::mem;
use std::ops;
/// RAII structure used to release the exclusive write access of a lock when
/// dropped.
//... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard.rs | MIT | 4e3268d222423e874f5bbfa67e20f773da3c025f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4e3268d222423e874f5bbfa67e20f773da3c025f/tokio/src/sync/rwlock/write_guard.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard.rs:2 | /// [`parking_lot` crate]: https://crates.io/crates/parking_lot
///
/// # Examples
///
/// ```
/// use tokio::sync::{RwLock, RwLockWriteGuard};
///
/// #[derive(Debug, Clone, Copy, PartialEq, Eq)]
/// struct Foo(u32);
///
/// # #[tokio::main]
/// # async fn main() {
/// l... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard.rs | MIT | 4e3268d222423e874f5bbfa67e20f773da3c025f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4e3268d222423e874f5bbfa67e20f773da3c025f/tokio/src/sync/rwlock/write_guard.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard.rs:3 | resource_span,
}
}
/// Attempts to make a new [`RwLockMappedWriteGuard`] for a component of
/// the locked data. The original guard is returned if the closure returns
/// `None`.
///
/// This operation cannot fail as the `RwLockWriteGuard` passed in already
/// locked the data.
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard.rs | MIT | 4e3268d222423e874f5bbfa67e20f773da3c025f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4e3268d222423e874f5bbfa67e20f773da3c025f/tokio/src/sync/rwlock/write_guard.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard.rs:4 | /// assert_eq!(Foo(2), *lock.read().await);
/// # }
/// ```
#[inline]
pub fn try_map<F, U: ?Sized>(
mut this: Self,
f: F,
) -> Result<RwLockMappedWriteGuard<'a, U>, Self>
where
F: FnOnce(&mut T) -> Option<&mut U>,
{
let data = match f(&mut *this) {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard.rs | MIT | 4e3268d222423e874f5bbfa67e20f773da3c025f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4e3268d222423e874f5bbfa67e20f773da3c025f/tokio/src/sync/rwlock/write_guard.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard.rs:5 | /// Atomically downgrades a write lock into a read lock without allowing
/// any writers to take exclusive access of the lock in the meantime.
///
/// **Note:** This won't *necessarily* allow any additional readers to acquire
/// locks, since [`RwLock`] is fair and it is possible that a writer is next
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard.rs | MIT | 4e3268d222423e874f5bbfa67e20f773da3c025f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4e3268d222423e874f5bbfa67e20f773da3c025f/tokio/src/sync/rwlock/write_guard.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard.rs:6 | let to_release = (self.permits_acquired - 1) as usize;
// Release all but one of the permits held by the write guard
s.release(to_release);
#[cfg(all(tokio_unstable, feature = "tracing"))]
self.resource_span.in_scope(|| {
tracing::trace!(
target: "runtime::resourc... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard.rs | MIT | 4e3268d222423e874f5bbfa67e20f773da3c025f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4e3268d222423e874f5bbfa67e20f773da3c025f/tokio/src/sync/rwlock/write_guard.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard.rs:7 | unsafe { &*self.data }
}
}
impl<T: ?Sized> ops::DerefMut for RwLockWriteGuard<'_, T> {
fn deref_mut(&mut self) -> &mut T {
unsafe { &mut *self.data }
}
}
impl<'a, T: ?Sized> fmt::Debug for RwLockWriteGuard<'a, T>
where
T: fmt::Debug,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Resu... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard.rs | MIT | 4e3268d222423e874f5bbfa67e20f773da3c025f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4e3268d222423e874f5bbfa67e20f773da3c025f/tokio/src/sync/rwlock/write_guard.rs | 241 | 282 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard.rs:1 | use crate::sync::batch_semaphore::Semaphore;
use crate::sync::rwlock::read_guard::RwLockReadGuard;
use crate::sync::rwlock::write_guard_mapped::RwLockMappedWriteGuard;
use std::fmt;
use std::marker;
use std::mem;
use std::ops;
/// RAII structure used to release the exclusive write access of a lock when
/// dropped.
//... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard.rs | MIT | 03969cdae7674681d1b10926e6a56fbb8908dbb8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/sync/rwlock/write_guard.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard.rs:2 | /// # Examples
///
/// ```
/// use tokio::sync::{RwLock, RwLockWriteGuard};
///
/// #[derive(Debug, Clone, Copy, PartialEq, Eq)]
/// struct Foo(u32);
///
/// # #[tokio::main]
/// # async fn main() {
/// let lock = RwLock::new(Foo(1));
///
/// {
/// let mut mapped ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard.rs | MIT | 03969cdae7674681d1b10926e6a56fbb8908dbb8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/sync/rwlock/write_guard.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard.rs:3 | /// `None`.
///
/// This operation cannot fail as the `RwLockWriteGuard` passed in already
/// locked the data.
///
/// This is an associated function that needs to be
/// used as `RwLockWriteGuard::try_map(...)`. A method would interfere with
/// methods of the same name on the contents of ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard.rs | MIT | 03969cdae7674681d1b10926e6a56fbb8908dbb8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/sync/rwlock/write_guard.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard.rs:4 | f: F,
) -> Result<RwLockMappedWriteGuard<'a, U>, Self>
where
F: FnOnce(&mut T) -> Option<&mut U>,
{
let data = match f(&mut *this) {
Some(data) => data as *mut U,
None => return Err(this),
};
let s = this.s;
let permits_acquired = this.permits_... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard.rs | MIT | 03969cdae7674681d1b10926e6a56fbb8908dbb8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/sync/rwlock/write_guard.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard.rs:5 | ///
/// # Examples
///
/// ```
/// # use tokio::sync::RwLock;
/// # use std::sync::Arc;
/// #
/// # #[tokio::main]
/// # async fn main() {
/// let lock = Arc::new(RwLock::new(1));
///
/// let n = lock.write().await;
///
/// let cloned_lock = lock.clone();
/// let ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard.rs | MIT | 03969cdae7674681d1b10926e6a56fbb8908dbb8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/sync/rwlock/write_guard.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard.rs:6 | }
}
impl<T: ?Sized> ops::Deref for RwLockWriteGuard<'_, T> {
type Target = T;
fn deref(&self) -> &T {
unsafe { &*self.data }
}
}
impl<T: ?Sized> ops::DerefMut for RwLockWriteGuard<'_, T> {
fn deref_mut(&mut self) -> &mut T {
unsafe { &mut *self.data }
}
}
impl<'a, T: ?Sized> fmt:... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard.rs | MIT | 03969cdae7674681d1b10926e6a56fbb8908dbb8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/sync/rwlock/write_guard.rs | 201 | 240 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard.rs:1 | use crate::sync::batch_semaphore::Semaphore;
use crate::sync::rwlock::read_guard::RwLockReadGuard;
use crate::sync::rwlock::write_guard_mapped::RwLockMappedWriteGuard;
use std::fmt;
use std::marker;
use std::mem;
use std::ops;
/// RAII structure used to release the exclusive write access of a lock when
/// dropped.
//... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard.rs | MIT | e89c8981f151a667bb676213d38b7dbeb51620e9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e89c8981f151a667bb676213d38b7dbeb51620e9/tokio/src/sync/rwlock/write_guard.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard.rs:1 | use crate::sync::batch_semaphore::Semaphore;
use crate::sync::rwlock::read_guard::RwLockReadGuard;
use crate::sync::rwlock::write_guard_mapped::RwLockMappedWriteGuard;
use std::fmt;
use std::marker;
use std::mem;
use std::ops;
/// RAII structure used to release the exclusive write access of a lock when
/// dropped.
//... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard.rs | MIT | 0dc4769708279a076e01a66dc53ec226083c1bdb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0dc4769708279a076e01a66dc53ec226083c1bdb/tokio/src/sync/rwlock/write_guard.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard.rs:2 | ///
/// ```
/// use tokio::sync::{RwLock, RwLockWriteGuard};
///
/// #[derive(Debug, Clone, Copy, PartialEq, Eq)]
/// struct Foo(u32);
///
/// # #[tokio::main]
/// # async fn main() {
/// let lock = RwLock::new(Foo(1));
///
/// {
/// let mut mapped = RwLockWriteGuard:... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard.rs | MIT | 0dc4769708279a076e01a66dc53ec226083c1bdb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0dc4769708279a076e01a66dc53ec226083c1bdb/tokio/src/sync/rwlock/write_guard.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard.rs:3 | /// locked the data.
///
/// This is an associated function that needs to be
/// used as `RwLockWriteGuard::try_map(...)`. A method would interfere with
/// methods of the same name on the contents of the locked data.
///
/// This is an asynchronous version of [`RwLockWriteGuard::try_map`] from
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard.rs | MIT | 0dc4769708279a076e01a66dc53ec226083c1bdb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0dc4769708279a076e01a66dc53ec226083c1bdb/tokio/src/sync/rwlock/write_guard.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard.rs:4 | F: FnOnce(&mut T) -> Option<&mut U>,
{
let data = match f(&mut *this) {
Some(data) => data as *mut U,
None => return Err(this),
};
let s = this.s;
// NB: Forget to avoid drop impl from being called.
mem::forget(this);
Ok(RwLockMappedWriteGuard ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard.rs | MIT | 0dc4769708279a076e01a66dc53ec226083c1bdb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0dc4769708279a076e01a66dc53ec226083c1bdb/tokio/src/sync/rwlock/write_guard.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard.rs:5 | /// # use std::sync::Arc;
/// #
/// # #[tokio::main]
/// # async fn main() {
/// let lock = Arc::new(RwLock::new(1));
///
/// let n = lock.write().await;
///
/// let cloned_lock = lock.clone();
/// let handle = tokio::spawn(async move {
/// *cloned_lock.write().await = 2;
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard.rs | MIT | 0dc4769708279a076e01a66dc53ec226083c1bdb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0dc4769708279a076e01a66dc53ec226083c1bdb/tokio/src/sync/rwlock/write_guard.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard.rs:6 | fn deref(&self) -> &T {
unsafe { &*self.data }
}
}
impl<T: ?Sized> ops::DerefMut for RwLockWriteGuard<'_, T> {
fn deref_mut(&mut self) -> &mut T {
unsafe { &mut *self.data }
}
}
impl<'a, T: ?Sized> fmt::Debug for RwLockWriteGuard<'a, T>
where
T: fmt::Debug,
{
fn fmt(&self, f: &mut ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard.rs | MIT | 0dc4769708279a076e01a66dc53ec226083c1bdb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0dc4769708279a076e01a66dc53ec226083c1bdb/tokio/src/sync/rwlock/write_guard.rs | 201 | 235 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard.rs:1 | use crate::sync::batch_semaphore::Semaphore;
use crate::sync::rwlock::read_guard::RwLockReadGuard;
use crate::sync::rwlock::write_guard_mapped::RwLockMappedWriteGuard;
use std::fmt;
use std::marker;
use std::mem;
use std::ops;
/// RAII structure used to release the exclusive write access of a lock when
/// dropped.
//... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard.rs | MIT | e3f2dcf5bc8315f01c8843259e78c8e98203a978 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e3f2dcf5bc8315f01c8843259e78c8e98203a978/tokio/src/sync/rwlock/write_guard.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard_mapped.rs:1 | use crate::sync::batch_semaphore::Semaphore;
use std::marker::PhantomData;
use std::{fmt, mem, ops};
/// RAII structure used to release the exclusive write access of a lock when
/// dropped.
///
/// This structure is created by [mapping] an [`RwLockWriteGuard`]. It is a
/// separate type from `RwLockWriteGuard` to dis... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard_mapped.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/rwlock/write_guard_mapped.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard_mapped.rs:2 | #[cfg(all(tokio_unstable, feature = "tracing"))]
resource_span: unsafe { std::ptr::read(&me.resource_span) },
permits_acquired: me.permits_acquired,
s: me.s,
data: me.data,
}
}
/// Makes a new `RwLockMappedWriteGuard` for a component of the locked data.
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard_mapped.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/rwlock/write_guard_mapped.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard_mapped.rs:3 | /// assert_eq!(Foo(2), *lock.read().await);
/// # }
/// ```
#[inline]
pub fn map<F, U: ?Sized>(mut this: Self, f: F) -> RwLockMappedWriteGuard<'a, U>
where
F: FnOnce(&mut T) -> &mut U,
{
let data = f(&mut *this) as *mut U;
let this = this.skip_drop();
RwLockMappe... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard_mapped.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/rwlock/write_guard_mapped.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard_mapped.rs:4 | /// ```
/// use tokio::sync::{RwLock, RwLockWriteGuard};
///
/// #[derive(Debug, Clone, Copy, PartialEq, Eq)]
/// struct Foo(u32);
///
/// # #[tokio::main(flavor = "current_thread")]
/// # async fn main() {
/// let lock = RwLock::new(Foo(1));
///
/// {
/// let guard = loc... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard_mapped.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/rwlock/write_guard_mapped.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard_mapped.rs:5 | })
}
// Note: No `downgrade`, `downgrade_map` nor `try_downgrade_map` because they would be unsound, as we're already
// potentially been mapped with internal mutability.
}
impl<T: ?Sized> ops::Deref for RwLockMappedWriteGuard<'_, T> {
type Target = T;
fn deref(&self) -> &T {
unsafe... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard_mapped.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/rwlock/write_guard_mapped.rs | 161 | 213 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard_mapped.rs:6 | fn drop(&mut self) {
self.s.release(self.permits_acquired as usize);
#[cfg(all(tokio_unstable, feature = "tracing"))]
self.resource_span.in_scope(|| {
tracing::trace!(
target: "runtime::resource::state_update",
write_locked = false,
write_locked.o... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard_mapped.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/rwlock/write_guard_mapped.rs | 201 | 213 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard_mapped.rs:2 | #[cfg(all(tokio_unstable, feature = "tracing"))]
resource_span: unsafe { std::ptr::read(&me.resource_span) },
permits_acquired: me.permits_acquired,
s: me.s,
data: me.data,
}
}
/// Makes a new `RwLockMappedWriteGuard` for a component of the locked data.
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard_mapped.rs | MIT | 002f4a28c882d127a665bb8d71f751d4eb5e1b22 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/002f4a28c882d127a665bb8d71f751d4eb5e1b22/tokio/src/sync/rwlock/write_guard_mapped.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard_mapped.rs:3 | /// assert_eq!(Foo(2), *lock.read().await);
/// # }
/// ```
#[inline]
pub fn map<F, U: ?Sized>(mut this: Self, f: F) -> RwLockMappedWriteGuard<'a, U>
where
F: FnOnce(&mut T) -> &mut U,
{
let data = f(&mut *this) as *mut U;
let this = this.skip_drop();
RwLockMappe... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard_mapped.rs | MIT | 002f4a28c882d127a665bb8d71f751d4eb5e1b22 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/002f4a28c882d127a665bb8d71f751d4eb5e1b22/tokio/src/sync/rwlock/write_guard_mapped.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard_mapped.rs:4 | /// ```
/// use tokio::sync::{RwLock, RwLockWriteGuard};
///
/// #[derive(Debug, Clone, Copy, PartialEq, Eq)]
/// struct Foo(u32);
///
/// # #[tokio::main]
/// # async fn main() {
/// let lock = RwLock::new(Foo(1));
///
/// {
/// let guard = lock.write().await;
/// ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard_mapped.rs | MIT | 002f4a28c882d127a665bb8d71f751d4eb5e1b22 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/002f4a28c882d127a665bb8d71f751d4eb5e1b22/tokio/src/sync/rwlock/write_guard_mapped.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard_mapped.rs:4 | /// ```
/// use tokio::sync::{RwLock, RwLockWriteGuard};
///
/// #[derive(Debug, Clone, Copy, PartialEq, Eq)]
/// struct Foo(u32);
///
/// # #[tokio::main]
/// # async fn main() {
/// let lock = RwLock::new(Foo(1));
///
/// {
/// let guard = lock.write().await;
/// ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard_mapped.rs | MIT | 24aac0add3547803b571e9d5c6d6c3ecbd09bb5b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/24aac0add3547803b571e9d5c6d6c3ecbd09bb5b/tokio/src/sync/rwlock/write_guard_mapped.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard_mapped.rs:5 | })
}
}
impl<T: ?Sized> ops::Deref for RwLockMappedWriteGuard<'_, T> {
type Target = T;
fn deref(&self) -> &T {
unsafe { &*self.data }
}
}
impl<T: ?Sized> ops::DerefMut for RwLockMappedWriteGuard<'_, T> {
fn deref_mut(&mut self) -> &mut T {
unsafe { &mut *self.data }
}
}
impl<... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard_mapped.rs | MIT | 24aac0add3547803b571e9d5c6d6c3ecbd09bb5b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/24aac0add3547803b571e9d5c6d6c3ecbd09bb5b/tokio/src/sync/rwlock/write_guard_mapped.rs | 161 | 210 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard_mapped.rs:6 | #[cfg(all(tokio_unstable, feature = "tracing"))]
self.resource_span.in_scope(|| {
tracing::trace!(
target: "runtime::resource::state_update",
write_locked = false,
write_locked.op = "override",
)
});
}
} | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard_mapped.rs | MIT | 24aac0add3547803b571e9d5c6d6c3ecbd09bb5b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/24aac0add3547803b571e9d5c6d6c3ecbd09bb5b/tokio/src/sync/rwlock/write_guard_mapped.rs | 201 | 210 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard_mapped.rs:1 | use crate::sync::batch_semaphore::Semaphore;
use std::fmt;
use std::marker;
use std::mem;
use std::ops;
/// RAII structure used to release the exclusive write access of a lock when
/// dropped.
///
/// This structure is created by [mapping] an [`RwLockWriteGuard`]. It is a
/// separate type from `RwLockWriteGuard` to ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard_mapped.rs | MIT | d6dbefcdc043da552615bf2c8ad1f3a9580a1735 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d6dbefcdc043da552615bf2c8ad1f3a9580a1735/tokio/src/sync/rwlock/write_guard_mapped.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard_mapped.rs:2 | ///
/// # Examples
///
/// ```
/// use tokio::sync::{RwLock, RwLockWriteGuard};
///
/// #[derive(Debug, Clone, Copy, PartialEq, Eq)]
/// struct Foo(u32);
///
/// # #[tokio::main]
/// # async fn main() {
/// let lock = RwLock::new(Foo(1));
///
/// {
/// let mut... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard_mapped.rs | MIT | d6dbefcdc043da552615bf2c8ad1f3a9580a1735 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d6dbefcdc043da552615bf2c8ad1f3a9580a1735/tokio/src/sync/rwlock/write_guard_mapped.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard_mapped.rs:3 | resource_span,
}
}
/// Attempts to make a new [`RwLockMappedWriteGuard`] for a component of
/// the locked data. The original guard is returned if the closure returns
/// `None`.
///
/// This operation cannot fail as the `RwLockMappedWriteGuard` passed in already
/// locked the data... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard_mapped.rs | MIT | d6dbefcdc043da552615bf2c8ad1f3a9580a1735 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d6dbefcdc043da552615bf2c8ad1f3a9580a1735/tokio/src/sync/rwlock/write_guard_mapped.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard_mapped.rs:4 | /// # }
/// ```
#[inline]
pub fn try_map<F, U: ?Sized>(
mut this: Self,
f: F,
) -> Result<RwLockMappedWriteGuard<'a, U>, Self>
where
F: FnOnce(&mut T) -> Option<&mut U>,
{
let data = match f(&mut *this) {
Some(data) => data as *mut U,
None ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard_mapped.rs | MIT | d6dbefcdc043da552615bf2c8ad1f3a9580a1735 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d6dbefcdc043da552615bf2c8ad1f3a9580a1735/tokio/src/sync/rwlock/write_guard_mapped.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard_mapped.rs:5 | impl<T: ?Sized> ops::DerefMut for RwLockMappedWriteGuard<'_, T> {
fn deref_mut(&mut self) -> &mut T {
unsafe { &mut *self.data }
}
}
impl<'a, T: ?Sized> fmt::Debug for RwLockMappedWriteGuard<'a, T>
where
T: fmt::Debug,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::De... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard_mapped.rs | MIT | d6dbefcdc043da552615bf2c8ad1f3a9580a1735 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d6dbefcdc043da552615bf2c8ad1f3a9580a1735/tokio/src/sync/rwlock/write_guard_mapped.rs | 161 | 198 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard_mapped.rs:1 | use crate::sync::batch_semaphore::Semaphore;
use std::fmt;
use std::marker;
use std::mem;
use std::ops;
/// RAII structure used to release the exclusive write access of a lock when
/// dropped.
///
/// This structure is created by [mapping] an [`RwLockWriteGuard`]. It is a
/// separate type from `RwLockWriteGuard` to ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard_mapped.rs | MIT | 4e3268d222423e874f5bbfa67e20f773da3c025f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4e3268d222423e874f5bbfa67e20f773da3c025f/tokio/src/sync/rwlock/write_guard_mapped.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard_mapped.rs:2 | /// # Examples
///
/// ```
/// use tokio::sync::{RwLock, RwLockWriteGuard};
///
/// #[derive(Debug, Clone, Copy, PartialEq, Eq)]
/// struct Foo(u32);
///
/// # #[tokio::main]
/// # async fn main() {
/// let lock = RwLock::new(Foo(1));
///
/// {
/// let mut mapped ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard_mapped.rs | MIT | 4e3268d222423e874f5bbfa67e20f773da3c025f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4e3268d222423e874f5bbfa67e20f773da3c025f/tokio/src/sync/rwlock/write_guard_mapped.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard_mapped.rs:3 | }
}
/// Attempts to make a new [`RwLockMappedWriteGuard`] for a component of
/// the locked data. The original guard is returned if the closure returns
/// `None`.
///
/// This operation cannot fail as the `RwLockMappedWriteGuard` passed in already
/// locked the data.
///
/// This ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard_mapped.rs | MIT | 4e3268d222423e874f5bbfa67e20f773da3c025f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4e3268d222423e874f5bbfa67e20f773da3c025f/tokio/src/sync/rwlock/write_guard_mapped.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard_mapped.rs:4 | /// ```
#[inline]
pub fn try_map<F, U: ?Sized>(
mut this: Self,
f: F,
) -> Result<RwLockMappedWriteGuard<'a, U>, Self>
where
F: FnOnce(&mut T) -> Option<&mut U>,
{
let data = match f(&mut *this) {
Some(data) => data as *mut U,
None => return Er... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard_mapped.rs | MIT | 4e3268d222423e874f5bbfa67e20f773da3c025f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4e3268d222423e874f5bbfa67e20f773da3c025f/tokio/src/sync/rwlock/write_guard_mapped.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard_mapped.rs:5 | fn deref_mut(&mut self) -> &mut T {
unsafe { &mut *self.data }
}
}
impl<'a, T: ?Sized> fmt::Debug for RwLockMappedWriteGuard<'a, T>
where
T: fmt::Debug,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Debug::fmt(&**self, f)
}
}
impl<'a, T: ?Sized> fmt::Display for RwL... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard_mapped.rs | MIT | 4e3268d222423e874f5bbfa67e20f773da3c025f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4e3268d222423e874f5bbfa67e20f773da3c025f/tokio/src/sync/rwlock/write_guard_mapped.rs | 161 | 197 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard_mapped.rs:1 | use crate::sync::batch_semaphore::Semaphore;
use std::fmt;
use std::marker;
use std::mem;
use std::ops;
/// RAII structure used to release the exclusive write access of a lock when
/// dropped.
///
/// This structure is created by [mapping] an [`RwLockWriteGuard`]. It is a
/// separate type from `RwLockWriteGuard` to ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard_mapped.rs | MIT | 03969cdae7674681d1b10926e6a56fbb8908dbb8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/sync/rwlock/write_guard_mapped.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard_mapped.rs:2 | /// ```
/// use tokio::sync::{RwLock, RwLockWriteGuard};
///
/// #[derive(Debug, Clone, Copy, PartialEq, Eq)]
/// struct Foo(u32);
///
/// # #[tokio::main]
/// # async fn main() {
/// let lock = RwLock::new(Foo(1));
///
/// {
/// let mut mapped = RwLockWriteGuard::map(loc... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard_mapped.rs | MIT | 03969cdae7674681d1b10926e6a56fbb8908dbb8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/sync/rwlock/write_guard_mapped.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard_mapped.rs:3 | /// This operation cannot fail as the `RwLockMappedWriteGuard` passed in already
/// locked the data.
///
/// This is an associated function that needs to be
/// used as `RwLockMappedWriteGuard::try_map(...)`. A method would interfere
/// with methods of the same name on the contents of the locked d... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard_mapped.rs | MIT | 03969cdae7674681d1b10926e6a56fbb8908dbb8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/sync/rwlock/write_guard_mapped.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard_mapped.rs:4 | F: FnOnce(&mut T) -> Option<&mut U>,
{
let data = match f(&mut *this) {
Some(data) => data as *mut U,
None => return Err(this),
};
let s = this.s;
let permits_acquired = this.permits_acquired;
// NB: Forget to avoid drop impl from being called.
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard_mapped.rs | MIT | 03969cdae7674681d1b10926e6a56fbb8908dbb8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/sync/rwlock/write_guard_mapped.rs | 121 | 176 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard_mapped.rs:5 | }
impl<'a, T: ?Sized> fmt::Display for RwLockMappedWriteGuard<'a, T>
where
T: fmt::Display,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(&**self, f)
}
}
impl<'a, T: ?Sized> Drop for RwLockMappedWriteGuard<'a, T> {
fn drop(&mut self) {
self.s.release(se... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard_mapped.rs | MIT | 03969cdae7674681d1b10926e6a56fbb8908dbb8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/sync/rwlock/write_guard_mapped.rs | 161 | 176 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard_mapped.rs:1 | use crate::sync::batch_semaphore::Semaphore;
use std::fmt;
use std::marker;
use std::mem;
use std::ops;
/// RAII structure used to release the exclusive write access of a lock when
/// dropped.
///
/// This structure is created by [mapping] an [`RwLockWriteGuard`]. It is a
/// separate type from `RwLockWriteGuard` to ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard_mapped.rs | MIT | e89c8981f151a667bb676213d38b7dbeb51620e9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e89c8981f151a667bb676213d38b7dbeb51620e9/tokio/src/sync/rwlock/write_guard_mapped.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard_mapped.rs:1 | use crate::sync::batch_semaphore::Semaphore;
use std::fmt;
use std::marker;
use std::mem;
use std::ops;
/// RAII structure used to release the exclusive write access of a lock when
/// dropped.
///
/// This structure is created by [mapping] an [`RwLockWriteGuard`]. It is a
/// separate type from `RwLockWriteGuard` to ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard_mapped.rs | MIT | 0dc4769708279a076e01a66dc53ec226083c1bdb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0dc4769708279a076e01a66dc53ec226083c1bdb/tokio/src/sync/rwlock/write_guard_mapped.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard_mapped.rs:2 | /// use tokio::sync::{RwLock, RwLockWriteGuard};
///
/// #[derive(Debug, Clone, Copy, PartialEq, Eq)]
/// struct Foo(u32);
///
/// # #[tokio::main]
/// # async fn main() {
/// let lock = RwLock::new(Foo(1));
///
/// {
/// let mut mapped = RwLockWriteGuard::map(lock.write().aw... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard_mapped.rs | MIT | 0dc4769708279a076e01a66dc53ec226083c1bdb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0dc4769708279a076e01a66dc53ec226083c1bdb/tokio/src/sync/rwlock/write_guard_mapped.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard_mapped.rs:3 | /// This is an associated function that needs to be
/// used as `RwLockMappedWriteGuard::try_map(...)`. A method would interfere
/// with methods of the same name on the contents of the locked data.
///
/// This is an asynchronous version of [`RwLockWriteGuard::try_map`] from
/// the [`parking_lot` ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard_mapped.rs | MIT | 0dc4769708279a076e01a66dc53ec226083c1bdb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0dc4769708279a076e01a66dc53ec226083c1bdb/tokio/src/sync/rwlock/write_guard_mapped.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard_mapped.rs:4 | Some(data) => data as *mut U,
None => return Err(this),
};
let s = this.s;
// NB: Forget to avoid drop impl from being called.
mem::forget(this);
Ok(RwLockMappedWriteGuard {
s,
data,
marker: marker::PhantomData,
})
}
}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard_mapped.rs | MIT | 0dc4769708279a076e01a66dc53ec226083c1bdb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0dc4769708279a076e01a66dc53ec226083c1bdb/tokio/src/sync/rwlock/write_guard_mapped.rs | 121 | 171 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard_mapped.rs:5 | {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(&**self, f)
}
}
impl<'a, T: ?Sized> Drop for RwLockMappedWriteGuard<'a, T> {
fn drop(&mut self) {
self.s.release(super::MAX_READS);
}
} | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard_mapped.rs | MIT | 0dc4769708279a076e01a66dc53ec226083c1bdb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0dc4769708279a076e01a66dc53ec226083c1bdb/tokio/src/sync/rwlock/write_guard_mapped.rs | 161 | 171 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard_mapped.rs:1 | use crate::sync::batch_semaphore::Semaphore;
use std::fmt;
use std::marker;
use std::mem;
use std::ops;
/// RAII structure used to release the exclusive write access of a lock when
/// dropped.
///
/// This structure is created by [mapping] an [`RwLockWriteGuard`]. It is a
/// separate type from `RwLockWriteGuard` to ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard_mapped.rs | MIT | e3f2dcf5bc8315f01c8843259e78c8e98203a978 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e3f2dcf5bc8315f01c8843259e78c8e98203a978/tokio/src/sync/rwlock/write_guard_mapped.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard_mapped.rs:2 | /// use tokio::sync::{RwLock, RwLockWriteGuard};
///
/// #[derive(Debug, Clone, Copy, PartialEq, Eq)]
/// struct Foo(u32);
///
/// # #[tokio::main]
/// # async fn main() {
/// let lock = RwLock::new(Foo(1));
///
/// {
/// let mut mapped = RwLockWriteGuard::map(lock.write().aw... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard_mapped.rs | MIT | e3f2dcf5bc8315f01c8843259e78c8e98203a978 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e3f2dcf5bc8315f01c8843259e78c8e98203a978/tokio/src/sync/rwlock/write_guard_mapped.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/sync/rwlock/write_guard_mapped.rs:3 | /// This is an associated function that needs to be
/// used as `RwLockWriteGuard::try_map(...)`. A method would interfere with
/// methods of the same name on the contents of the locked data.
///
/// This is an asynchronous version of [`RwLockWriteGuard::try_map`] from
/// the [`parking_lot` crate]... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock/write_guard_mapped.rs | MIT | e3f2dcf5bc8315f01c8843259e78c8e98203a978 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e3f2dcf5bc8315f01c8843259e78c8e98203a978/tokio/src/sync/rwlock/write_guard_mapped.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/sync/semaphore.rs:10 | /// permit.forget();
/// }
/// }
///
/// impl Drop for TokenBucket {
/// fn drop(&mut self) {
/// // Kill the background task so it stops taking up resources when we
/// // don't need it anymore.
/// self.jh.abort();
/// }
/// }
///
/// #[tokio::main]
/// # async fn _hidden()... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/semaphore.rs | MIT | 90e20bcad372d01e9db9a4357351b19982d66783 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/90e20bcad372d01e9db9a4357351b19982d66783/tokio/src/sync/semaphore.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/sync/semaphore.rs:11 | /// This type is created by the [`acquire`] method.
///
/// [`acquire`]: crate::sync::Semaphore::acquire()
#[must_use]
#[clippy::has_significant_drop]
#[derive(Debug)]
pub struct SemaphorePermit<'a> {
sem: &'a Semaphore,
permits: u32,
}
/// An owned permit from the semaphore.
///
/// This type is created by th... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/semaphore.rs | MIT | 90e20bcad372d01e9db9a4357351b19982d66783 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/90e20bcad372d01e9db9a4357351b19982d66783/tokio/src/sync/semaphore.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/sync/semaphore.rs:12 | /// The maximum number of permits which a semaphore can hold. It is `usize::MAX >> 3`.
///
/// Exceeding this limit typically results in a panic.
pub const MAX_PERMITS: usize = super::batch_semaphore::Semaphore::MAX_PERMITS;
/// Creates a new semaphore with the initial number of permits.
///
//... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/semaphore.rs | MIT | 90e20bcad372d01e9db9a4357351b19982d66783 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/90e20bcad372d01e9db9a4357351b19982d66783/tokio/src/sync/semaphore.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/sync/semaphore.rs:13 | ///
/// When using the `tracing` [unstable feature], a `Semaphore` created with
/// `const_new` will not be instrumented. As such, it will not be visible
/// in [`tokio-console`]. Instead, [`Semaphore::new`] should be used to
/// create an instrumented object if that is needed.
///
/// # Example... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/semaphore.rs | MIT | 90e20bcad372d01e9db9a4357351b19982d66783 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/90e20bcad372d01e9db9a4357351b19982d66783/tokio/src/sync/semaphore.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/sync/semaphore.rs:14 | resource_span: tracing::Span::none(),
}
}
/// Returns the current number of available permits.
pub fn available_permits(&self) -> usize {
self.ll_sem.available_permits()
}
/// Adds `n` new permits to the semaphore.
///
/// The maximum number of permits is [`Semaphore::MAX_P... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/semaphore.rs | MIT | 90e20bcad372d01e9db9a4357351b19982d66783 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/90e20bcad372d01e9db9a4357351b19982d66783/tokio/src/sync/semaphore.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/sync/semaphore.rs:15 | ///
/// #[tokio::main]
/// async fn main() {
/// let semaphore = Semaphore::new(2);
///
/// let permit_1 = semaphore.acquire().await.unwrap();
/// assert_eq!(semaphore.available_permits(), 1);
///
/// let permit_2 = semaphore.acquire().await.unwrap();
/// assert_e... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/semaphore.rs | MIT | 90e20bcad372d01e9db9a4357351b19982d66783 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/90e20bcad372d01e9db9a4357351b19982d66783/tokio/src/sync/semaphore.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/sync/semaphore.rs:16 | /// Otherwise, this returns a [`SemaphorePermit`] representing the
/// acquired permits.
///
/// # Cancel safety
///
/// This method uses a queue to fairly distribute permits in the order they
/// were requested. Cancelling a call to `acquire_many` makes you lose your
/// place in the queue.... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/semaphore.rs | MIT | 90e20bcad372d01e9db9a4357351b19982d66783 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/90e20bcad372d01e9db9a4357351b19982d66783/tokio/src/sync/semaphore.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/sync/semaphore.rs:19 | /// The semaphore must be wrapped in an [`Arc`] to call this method.
/// If the semaphore has been closed, this returns an [`AcquireError`].
/// Otherwise, this returns a [`OwnedSemaphorePermit`] representing the
/// acquired permit.
///
/// # Cancel safety
///
/// This method uses a queue t... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/semaphore.rs | MIT | 90e20bcad372d01e9db9a4357351b19982d66783 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/90e20bcad372d01e9db9a4357351b19982d66783/tokio/src/sync/semaphore.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/sync/semaphore.rs:20 | pub async fn acquire_owned(self: Arc<Self>) -> Result<OwnedSemaphorePermit, AcquireError> {
#[cfg(all(tokio_unstable, feature = "tracing"))]
let inner = trace::async_op(
|| self.ll_sem.acquire(1),
self.resource_span.clone(),
"Semaphore::acquire_owned",
"po... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/semaphore.rs | MIT | 90e20bcad372d01e9db9a4357351b19982d66783 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/90e20bcad372d01e9db9a4357351b19982d66783/tokio/src/sync/semaphore.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/sync/semaphore.rs:21 | /// let semaphore = Arc::new(Semaphore::new(10));
/// let mut join_handles = Vec::new();
///
/// for _ in 0..5 {
/// let permit = semaphore.clone().acquire_many_owned(2).await.unwrap();
/// join_handles.push(tokio::spawn(async move {
/// // perform task...... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/semaphore.rs | MIT | 90e20bcad372d01e9db9a4357351b19982d66783 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/90e20bcad372d01e9db9a4357351b19982d66783/tokio/src/sync/semaphore.rs | 801 | 860 |
tokio-rs/tokio:tokio/src/sync/semaphore.rs:23 | }),
Err(e) => Err(e),
}
}
/// Tries to acquire `n` permits from the semaphore.
///
/// The semaphore must be wrapped in an [`Arc`] to call this method. If
/// the semaphore has been closed, this returns a [`TryAcquireError::Closed`]
/// and a [`TryAcquireError::NoPermits`] i... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/semaphore.rs | MIT | 90e20bcad372d01e9db9a4357351b19982d66783 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/90e20bcad372d01e9db9a4357351b19982d66783/tokio/src/sync/semaphore.rs | 881 | 940 |
tokio-rs/tokio:tokio/src/sync/semaphore.rs:24 | sem: self,
permits: n,
}),
Err(e) => Err(e),
}
}
/// Closes the semaphore.
///
/// This prevents the semaphore from issuing new permits and notifies all pending waiters.
///
/// # Examples
///
/// ```
/// use tokio::sync::Semaphore;
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/semaphore.rs | MIT | 90e20bcad372d01e9db9a4357351b19982d66783 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/90e20bcad372d01e9db9a4357351b19982d66783/tokio/src/sync/semaphore.rs | 921 | 980 |
tokio-rs/tokio:tokio/src/sync/semaphore.rs:25 | /// Returns true if the semaphore is closed
pub fn is_closed(&self) -> bool {
self.ll_sem.is_closed()
}
}
impl<'a> SemaphorePermit<'a> {
/// Forgets the permit **without** releasing it back to the semaphore.
/// This can be used to reduce the amount of permits available from a
/// semaphore... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/semaphore.rs | MIT | 90e20bcad372d01e9db9a4357351b19982d66783 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/90e20bcad372d01e9db9a4357351b19982d66783/tokio/src/sync/semaphore.rs | 961 | 1,020 |
tokio-rs/tokio:tokio/src/sync/semaphore.rs:26 | return None;
}
self.permits -= n;
Some(Self {
sem: self.sem,
permits: n,
})
}
/// Returns the number of permits held by `self`.
pub fn num_permits(&self) -> usize {
self.permits as usize
}
}
impl OwnedSemaphorePermit {
/// Forgets t... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/semaphore.rs | MIT | 90e20bcad372d01e9db9a4357351b19982d66783 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/90e20bcad372d01e9db9a4357351b19982d66783/tokio/src/sync/semaphore.rs | 1,001 | 1,060 |
tokio-rs/tokio:tokio/src/sync/semaphore.rs:27 | self.permits += other.permits;
other.permits = 0;
}
/// Splits `n` permits from `self` and returns a new [`OwnedSemaphorePermit`] instance that holds `n` permits.
///
/// If there are insufficient permits and it's not possible to reduce by `n`, returns `None`.
///
/// # Note
///
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/semaphore.rs | MIT | 90e20bcad372d01e9db9a4357351b19982d66783 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/90e20bcad372d01e9db9a4357351b19982d66783/tokio/src/sync/semaphore.rs | 1,041 | 1,088 |
tokio-rs/tokio:tokio/src/sync/semaphore.rs:25 | /// Returns true if the semaphore is closed
pub fn is_closed(&self) -> bool {
self.ll_sem.is_closed()
}
}
impl<'a> SemaphorePermit<'a> {
/// Forgets the permit **without** releasing it back to the semaphore.
/// This can be used to reduce the amount of permits available from a
/// semaphore... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/semaphore.rs | MIT | 224fea4f3ca116f1fb416da5acc36faa8e3e8b5d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/224fea4f3ca116f1fb416da5acc36faa8e3e8b5d/tokio/src/sync/semaphore.rs | 961 | 1,020 |
tokio-rs/tokio:tokio/src/sync/semaphore.rs:26 | self.permits -= n;
Some(Self {
sem: self.sem,
permits: n,
})
}
/// Returns the number of permits held by `self`.
pub fn num_permits(&self) -> u32 {
self.permits
}
}
impl OwnedSemaphorePermit {
/// Forgets the permit **without** releasing it back to ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/semaphore.rs | MIT | 224fea4f3ca116f1fb416da5acc36faa8e3e8b5d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/224fea4f3ca116f1fb416da5acc36faa8e3e8b5d/tokio/src/sync/semaphore.rs | 1,001 | 1,060 |
tokio-rs/tokio:tokio/src/sync/semaphore.rs:27 | }
/// Splits `n` permits from `self` and returns a new [`OwnedSemaphorePermit`] instance that holds `n` permits.
///
/// If there are insufficient permits and it's not possible to reduce by `n`, returns `None`.
///
/// # Note
///
/// It will clone the owned `Arc<Semaphore>` to construct the... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/semaphore.rs | MIT | 224fea4f3ca116f1fb416da5acc36faa8e3e8b5d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/224fea4f3ca116f1fb416da5acc36faa8e3e8b5d/tokio/src/sync/semaphore.rs | 1,041 | 1,084 |
tokio-rs/tokio:tokio/src/sync/semaphore.rs:25 | /// Returns true if the semaphore is closed
pub fn is_closed(&self) -> bool {
self.ll_sem.is_closed()
}
}
impl<'a> SemaphorePermit<'a> {
/// Forgets the permit **without** releasing it back to the semaphore.
/// This can be used to reduce the amount of permits available from a
/// semaphore... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/semaphore.rs | MIT | baad270b98acbc735f9e8baddc93ae8a18a652ce | github | async-runtime | https://github.com/tokio-rs/tokio/blob/baad270b98acbc735f9e8baddc93ae8a18a652ce/tokio/src/sync/semaphore.rs | 961 | 1,020 |
tokio-rs/tokio:tokio/src/sync/semaphore.rs:26 | }
/// Merge two [`OwnedSemaphorePermit`] instances together, consuming `other`
/// without releasing the permits it holds.
///
/// Permits held by both `self` and `other` are released when `self` drops.
///
/// # Panics
///
/// This function panics if permits from different [`Semaphore`... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/semaphore.rs | MIT | baad270b98acbc735f9e8baddc93ae8a18a652ce | github | async-runtime | https://github.com/tokio-rs/tokio/blob/baad270b98acbc735f9e8baddc93ae8a18a652ce/tokio/src/sync/semaphore.rs | 1,001 | 1,038 |
tokio-rs/tokio:tokio/src/sync/semaphore.rs:9 | /// # async fn _hidden() {}
/// # #[tokio::main(flavor = "current_thread", start_paused = true)]
/// async fn main() {
/// let capacity = 5;
/// let update_interval = Duration::from_secs_f32(1.0 / capacity as f32);
/// let bucket = TokenBucket::new(update_interval, capacity);
///
/// for _ in 0..5 {
///... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/semaphore.rs | MIT | 0fbde0e94b06536917b6686e996856a33aeb29ee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0fbde0e94b06536917b6686e996856a33aeb29ee/tokio/src/sync/semaphore.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/sync/semaphore.rs:10 | /// This type is created by the [`acquire_owned`] method.
///
/// [`acquire_owned`]: crate::sync::Semaphore::acquire_owned()
#[must_use]
#[clippy::has_significant_drop]
#[derive(Debug)]
pub struct OwnedSemaphorePermit {
sem: Arc<Semaphore>,
permits: u32,
}
#[test]
#[cfg(not(loom))]
fn bounds() {
fn check_u... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/semaphore.rs | MIT | 0fbde0e94b06536917b6686e996856a33aeb29ee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0fbde0e94b06536917b6686e996856a33aeb29ee/tokio/src/sync/semaphore.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/sync/semaphore.rs:11 | tracing::trace_span!(
parent: None,
"runtime.resource",
concrete_type = "Semaphore",
kind = "Sync",
loc.file = location.file(),
loc.line = location.line(),
loc.col = location.column(),
inherit... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/semaphore.rs | MIT | 0fbde0e94b06536917b6686e996856a33aeb29ee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0fbde0e94b06536917b6686e996856a33aeb29ee/tokio/src/sync/semaphore.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/sync/semaphore.rs:12 | ///
/// [`tokio-console`]: https://github.com/tokio-rs/console
/// [unstable feature]: crate#unstable-features
#[cfg(not(all(loom, test)))]
pub const fn const_new(permits: usize) -> Self {
Self {
ll_sem: ll::Semaphore::const_new(permits),
#[cfg(all(tokio_unstable, feature... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/semaphore.rs | MIT | 0fbde0e94b06536917b6686e996856a33aeb29ee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0fbde0e94b06536917b6686e996856a33aeb29ee/tokio/src/sync/semaphore.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/sync/semaphore.rs:13 | self.ll_sem.release(n);
}
/// Decrease a semaphore's permits by a maximum of `n`.
///
/// If there are insufficient permits and it's not possible to reduce by `n`,
/// return the number of permits that were actually reduced.
pub fn forget_permits(&self, n: usize) -> usize {
self.ll_sem.... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/semaphore.rs | MIT | 0fbde0e94b06536917b6686e996856a33aeb29ee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0fbde0e94b06536917b6686e996856a33aeb29ee/tokio/src/sync/semaphore.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/sync/semaphore.rs:14 | /// }
/// ```
///
/// [`AcquireError`]: crate::sync::AcquireError
/// [`SemaphorePermit`]: crate::sync::SemaphorePermit
pub async fn acquire(&self) -> Result<SemaphorePermit<'_>, AcquireError> {
#[cfg(all(tokio_unstable, feature = "tracing"))]
let inner = trace::async_op(
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/semaphore.rs | MIT | 0fbde0e94b06536917b6686e996856a33aeb29ee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0fbde0e94b06536917b6686e996856a33aeb29ee/tokio/src/sync/semaphore.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/sync/semaphore.rs:15 | ///
/// #[tokio::main]
/// async fn main() {
/// let semaphore = Semaphore::new(5);
///
/// let permit = semaphore.acquire_many(3).await.unwrap();
/// assert_eq!(semaphore.available_permits(), 2);
/// }
/// ```
///
/// [`AcquireError`]: crate::sync::AcquireError
/... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/semaphore.rs | MIT | 0fbde0e94b06536917b6686e996856a33aeb29ee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0fbde0e94b06536917b6686e996856a33aeb29ee/tokio/src/sync/semaphore.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/sync/semaphore.rs:16 | /// ```
/// use tokio::sync::{Semaphore, TryAcquireError};
///
/// # fn main() {
/// let semaphore = Semaphore::new(2);
///
/// let permit_1 = semaphore.try_acquire().unwrap();
/// assert_eq!(semaphore.available_permits(), 1);
///
/// let permit_2 = semaphore.try_acquire().unwrap();
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/semaphore.rs | MIT | 0fbde0e94b06536917b6686e996856a33aeb29ee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0fbde0e94b06536917b6686e996856a33aeb29ee/tokio/src/sync/semaphore.rs | 601 | 660 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.