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.rs:9 | c: UnsafeCell::new(value),
s,
#[cfg(all(tokio_unstable, feature = "tracing"))]
resource_span,
}
}
/// Creates a new instance of an `RwLock<T>` which is unlocked.
///
/// # Examples
///
/// ```
/// use tokio::sync::RwLock;
///
/// static LO... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 11b88075440f1b141e4a18c7d506df0fc0eceb71 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/11b88075440f1b141e4a18c7d506df0fc0eceb71/tokio/src/sync/rwlock.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:10 | /// ```
#[cfg(all(feature = "parking_lot", not(all(loom, test))))]
#[cfg_attr(docsrs, doc(cfg(feature = "parking_lot")))]
pub const fn const_with_max_readers(value: T, mut max_reads: u32) -> RwLock<T>
where
T: Sized,
{
max_reads &= MAX_READS;
RwLock {
mr: max_read... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 11b88075440f1b141e4a18c7d506df0fc0eceb71 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/11b88075440f1b141e4a18c7d506df0fc0eceb71/tokio/src/sync/rwlock.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:11 | /// ```
/// use std::sync::Arc;
/// use tokio::sync::RwLock;
///
/// #[tokio::main]
/// async fn main() {
/// let lock = Arc::new(RwLock::new(1));
/// let c_lock = lock.clone();
///
/// let n = lock.read().await;
/// assert_eq!(*n, 1);
///
/// tokio::s... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 11b88075440f1b141e4a18c7d506df0fc0eceb71 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/11b88075440f1b141e4a18c7d506df0fc0eceb71/tokio/src/sync/rwlock.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:12 | let acquire_fut = trace::async_op(
move || acquire_fut,
self.resource_span.clone(),
"RwLock::read",
"poll",
false,
);
#[allow(clippy::let_and_return)] // this lint triggers when disabling tracing
let guard = acquire_fut.await;
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 11b88075440f1b141e4a18c7d506df0fc0eceb71 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/11b88075440f1b141e4a18c7d506df0fc0eceb71/tokio/src/sync/rwlock.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:15 | /// assert_eq!(*r, 1);
/// }).await.expect("The spawned task has panicked");
///
/// // Drop the guard after the spawned task finishes.
/// drop(n);
///}
/// ```
pub async fn read_owned(self: Arc<Self>) -> OwnedRwLockReadGuard<T> {
#[cfg(all(tokio_unstable, featur... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 11b88075440f1b141e4a18c7d506df0fc0eceb71 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/11b88075440f1b141e4a18c7d506df0fc0eceb71/tokio/src/sync/rwlock.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:16 | guard.resource_span.in_scope(|| {
tracing::trace!(
target: "runtime::resource::state_update",
current_readers = 1,
current_readers.op = "add",
)
});
guard
}
/// Attempts to acquire this `RwLock` with shared read access.
///
//... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 11b88075440f1b141e4a18c7d506df0fc0eceb71 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/11b88075440f1b141e4a18c7d506df0fc0eceb71/tokio/src/sync/rwlock.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:17 | /// drop(v);
/// }
/// ```
pub fn try_read(&self) -> Result<RwLockReadGuard<'_, T>, TryLockError> {
match self.s.try_acquire(1) {
Ok(permit) => permit,
Err(TryAcquireError::NoPermits) => return Err(TryLockError(())),
Err(TryAcquireError::Closed) => unreachable... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 11b88075440f1b141e4a18c7d506df0fc0eceb71 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/11b88075440f1b141e4a18c7d506df0fc0eceb71/tokio/src/sync/rwlock.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:18 | /// as it keeps the `RwLock` alive by holding an `Arc`.
///
/// [`TryLockError`]: TryLockError
///
/// # Examples
///
/// ```
/// use std::sync::Arc;
/// use tokio::sync::RwLock;
///
/// #[tokio::main]
/// async fn main() {
/// let lock = Arc::new(RwLock::new(1));
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 11b88075440f1b141e4a18c7d506df0fc0eceb71 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/11b88075440f1b141e4a18c7d506df0fc0eceb71/tokio/src/sync/rwlock.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:19 | _p: PhantomData,
};
#[cfg(all(tokio_unstable, feature = "tracing"))]
guard.resource_span.in_scope(|| {
tracing::trace!(
target: "runtime::resource::state_update",
current_readers = 1,
current_readers.op = "add",
)
});
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 11b88075440f1b141e4a18c7d506df0fc0eceb71 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/11b88075440f1b141e4a18c7d506df0fc0eceb71/tokio/src/sync/rwlock.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:20 | /// *n = 2;
///}
/// ```
pub async fn write(&self) -> RwLockWriteGuard<'_, T> {
let acquire_fut = async {
self.s.acquire(self.mr).await.unwrap_or_else(|_| {
// The semaphore was closed. but, we never explicitly close it, and we have a
// handle to it thr... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 11b88075440f1b141e4a18c7d506df0fc0eceb71 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/11b88075440f1b141e4a18c7d506df0fc0eceb71/tokio/src/sync/rwlock.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:23 | ///
/// # Examples
///
/// ```
/// use std::sync::Arc;
/// use tokio::sync::RwLock;
///
/// #[tokio::main]
/// async fn main() {
/// let lock = Arc::new(RwLock::new(1));
///
/// let mut n = lock.write_owned().await;
/// *n = 2;
///}
/// ```
pub async fn ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 11b88075440f1b141e4a18c7d506df0fc0eceb71 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/11b88075440f1b141e4a18c7d506df0fc0eceb71/tokio/src/sync/rwlock.rs | 881 | 940 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:24 | "RwLock::write_owned",
"poll",
false,
);
#[allow(clippy::let_and_return)] // this lint triggers when disabling tracing
let guard = acquire_fut.await;
#[cfg(all(tokio_unstable, feature = "tracing"))]
guard.resource_span.in_scope(|| {
tracing::... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 11b88075440f1b141e4a18c7d506df0fc0eceb71 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/11b88075440f1b141e4a18c7d506df0fc0eceb71/tokio/src/sync/rwlock.rs | 921 | 980 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:25 | /// assert!(rw.try_write().is_err());
/// }
/// ```
pub fn try_write(&self) -> Result<RwLockWriteGuard<'_, T>, TryLockError> {
match self.s.try_acquire(self.mr) {
Ok(permit) => permit,
Err(TryAcquireError::NoPermits) => return Err(TryLockError(())),
Err(TryAcq... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 11b88075440f1b141e4a18c7d506df0fc0eceb71 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/11b88075440f1b141e4a18c7d506df0fc0eceb71/tokio/src/sync/rwlock.rs | 961 | 1,020 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:26 | /// call this method, and the guard will live for the `'static` lifetime,
/// as it keeps the `RwLock` alive by holding an `Arc`.
///
/// [`TryLockError`]: TryLockError
///
/// # Examples
///
/// ```
/// use std::sync::Arc;
/// use tokio::sync::RwLock;
///
/// #[tokio::main]
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 11b88075440f1b141e4a18c7d506df0fc0eceb71 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/11b88075440f1b141e4a18c7d506df0fc0eceb71/tokio/src/sync/rwlock.rs | 1,001 | 1,060 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:27 | target: "runtime::resource::state_update",
write_locked = true,
write_locked.op = "override",
)
});
Ok(guard)
}
/// Returns a mutable reference to the underlying data.
///
/// Since this call borrows the `RwLock` mutably, no actual locking needs to
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 11b88075440f1b141e4a18c7d506df0fc0eceb71 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/11b88075440f1b141e4a18c7d506df0fc0eceb71/tokio/src/sync/rwlock.rs | 1,041 | 1,100 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:28 | }
impl<T> From<T> for RwLock<T> {
fn from(s: T) -> Self {
Self::new(s)
}
}
impl<T: ?Sized> Default for RwLock<T>
where
T: Default,
{
fn default() -> Self {
Self::new(T::default())
}
}
impl<T: ?Sized> std::fmt::Debug for RwLock<T>
where
T: std::fmt::Debug,
{
fn fmt(&self, f... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 11b88075440f1b141e4a18c7d506df0fc0eceb71 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/11b88075440f1b141e4a18c7d506df0fc0eceb71/tokio/src/sync/rwlock.rs | 1,081 | 1,110 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:3 | ///
/// [`Mutex`]: struct@super::Mutex
/// [`RwLock`]: struct@RwLock
/// [`RwLockReadGuard`]: struct@RwLockReadGuard
/// [`RwLockWriteGuard`]: struct@RwLockWriteGuard
/// [`Send`]: trait@std::marker::Send
/// [_write-preferring_]: https://en.wikipedia.org/wiki/Readers%E2%80%93writer_lock#Priority_policies
#[derive(Debu... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 24aac0add3547803b571e9d5c6d6c3ecbd09bb5b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/24aac0add3547803b571e9d5c6d6c3ecbd09bb5b/tokio/src/sync/rwlock.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:4 | check_sync::<OwnedRwLockReadGuard<u32, i32>>();
check_unpin::<OwnedRwLockReadGuard<u32, i32>>();
check_send::<RwLockWriteGuard<'_, u32>>();
check_sync::<RwLockWriteGuard<'_, u32>>();
check_unpin::<RwLockWriteGuard<'_, u32>>();
check_send::<RwLockMappedWriteGuard<'_, u32>>();
check_sync::<RwLoc... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 24aac0add3547803b571e9d5c6d6c3ecbd09bb5b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/24aac0add3547803b571e9d5c6d6c3ecbd09bb5b/tokio/src/sync/rwlock.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:5 | T: ?Sized + Send + Sync,
U: ?Sized + Sync,
{
}
unsafe impl<T, U> Sync for OwnedRwLockReadGuard<T, U>
where
T: ?Sized + Send + Sync,
U: ?Sized + Send + Sync,
{
}
unsafe impl<T> Sync for RwLockWriteGuard<'_, T> where T: ?Sized + Send + Sync {}
unsafe impl<T> Sync for OwnedRwLockWriteGuard<T> where T: ?Sized +... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 24aac0add3547803b571e9d5c6d6c3ecbd09bb5b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/24aac0add3547803b571e9d5c6d6c3ecbd09bb5b/tokio/src/sync/rwlock.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:6 | ///
/// let lock = RwLock::new(5);
/// ```
#[track_caller]
pub fn new(value: T) -> RwLock<T>
where
T: Sized,
{
#[cfg(all(tokio_unstable, feature = "tracing"))]
let resource_span = {
let location = std::panic::Location::caller();
let resource_span =... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 24aac0add3547803b571e9d5c6d6c3ecbd09bb5b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/24aac0add3547803b571e9d5c6d6c3ecbd09bb5b/tokio/src/sync/rwlock.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:7 | #[cfg(all(tokio_unstable, feature = "tracing"))]
let s = resource_span.in_scope(|| Semaphore::new(MAX_READS as usize));
#[cfg(any(not(tokio_unstable), not(feature = "tracing")))]
let s = Semaphore::new(MAX_READS as usize);
RwLock {
mr: MAX_READS,
c: UnsafeCell::... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 24aac0add3547803b571e9d5c6d6c3ecbd09bb5b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/24aac0add3547803b571e9d5c6d6c3ecbd09bb5b/tokio/src/sync/rwlock.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:8 | #[cfg(all(tokio_unstable, feature = "tracing"))]
let resource_span = {
let location = std::panic::Location::caller();
let resource_span = tracing::trace_span!(
"runtime.resource",
concrete_type = "RwLock",
kind = "Sync",
lo... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 24aac0add3547803b571e9d5c6d6c3ecbd09bb5b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/24aac0add3547803b571e9d5c6d6c3ecbd09bb5b/tokio/src/sync/rwlock.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:9 | mr: max_reads,
c: UnsafeCell::new(value),
s,
#[cfg(all(tokio_unstable, feature = "tracing"))]
resource_span,
}
}
/// Creates a new instance of an `RwLock<T>` which is unlocked.
///
/// # Examples
///
/// ```
/// use tokio::sync::RwLock... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 24aac0add3547803b571e9d5c6d6c3ecbd09bb5b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/24aac0add3547803b571e9d5c6d6c3ecbd09bb5b/tokio/src/sync/rwlock.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:10 | /// static LOCK: RwLock<i32> = RwLock::const_with_max_readers(5, 1024);
/// ```
#[cfg(all(feature = "parking_lot", not(all(loom, test))))]
#[cfg_attr(docsrs, doc(cfg(feature = "parking_lot")))]
pub const fn const_with_max_readers(value: T, mut max_reads: u32) -> RwLock<T>
where
T: Sized,
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 24aac0add3547803b571e9d5c6d6c3ecbd09bb5b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/24aac0add3547803b571e9d5c6d6c3ecbd09bb5b/tokio/src/sync/rwlock.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:11 | ///
/// ```
/// use std::sync::Arc;
/// use tokio::sync::RwLock;
///
/// #[tokio::main]
/// async fn main() {
/// let lock = Arc::new(RwLock::new(1));
/// let c_lock = lock.clone();
///
/// let n = lock.read().await;
/// assert_eq!(*n, 1);
///
/// ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 24aac0add3547803b571e9d5c6d6c3ecbd09bb5b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/24aac0add3547803b571e9d5c6d6c3ecbd09bb5b/tokio/src/sync/rwlock.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:12 | #[cfg(all(tokio_unstable, feature = "tracing"))]
let acquire_fut = trace::async_op(
move || acquire_fut,
self.resource_span.clone(),
"RwLock::read",
"poll",
false,
);
#[allow(clippy::let_and_return)] // this lint triggers when disablin... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 24aac0add3547803b571e9d5c6d6c3ecbd09bb5b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/24aac0add3547803b571e9d5c6d6c3ecbd09bb5b/tokio/src/sync/rwlock.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:15 | /// let r = c_lock.read_owned().await;
/// assert_eq!(*r, 1);
/// }).await.expect("The spawned task has panicked");
///
/// // Drop the guard after the spawned task finishes.
/// drop(n);
///}
/// ```
pub async fn read_owned(self: Arc<Self>) -> OwnedRwLockRead... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 24aac0add3547803b571e9d5c6d6c3ecbd09bb5b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/24aac0add3547803b571e9d5c6d6c3ecbd09bb5b/tokio/src/sync/rwlock.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:16 | #[cfg(all(tokio_unstable, feature = "tracing"))]
guard.resource_span.in_scope(|| {
tracing::trace!(
target: "runtime::resource::state_update",
current_readers = 1,
current_readers.op = "add",
)
});
guard
}
/// Attempts to acqu... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 24aac0add3547803b571e9d5c6d6c3ecbd09bb5b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/24aac0add3547803b571e9d5c6d6c3ecbd09bb5b/tokio/src/sync/rwlock.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:17 | /// // Drop the guard when spawned task finishes.
/// drop(v);
/// }
/// ```
pub fn try_read(&self) -> Result<RwLockReadGuard<'_, T>, TryLockError> {
match self.s.try_acquire(1) {
Ok(permit) => permit,
Err(TryAcquireError::NoPermits) => return Err(TryLockError(())... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 24aac0add3547803b571e9d5c6d6c3ecbd09bb5b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/24aac0add3547803b571e9d5c6d6c3ecbd09bb5b/tokio/src/sync/rwlock.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:18 | /// call this method, and the guard will live for the `'static` lifetime,
/// as it keeps the `RwLock` alive by holding an `Arc`.
///
/// [`TryLockError`]: TryLockError
///
/// # Examples
///
/// ```
/// use std::sync::Arc;
/// use tokio::sync::RwLock;
///
/// #[tokio::main]
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 24aac0add3547803b571e9d5c6d6c3ecbd09bb5b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/24aac0add3547803b571e9d5c6d6c3ecbd09bb5b/tokio/src/sync/rwlock.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:19 | lock: self,
_p: PhantomData,
};
#[cfg(all(tokio_unstable, feature = "tracing"))]
guard.resource_span.in_scope(|| {
tracing::trace!(
target: "runtime::resource::state_update",
current_readers = 1,
current_readers.op = "add",
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 24aac0add3547803b571e9d5c6d6c3ecbd09bb5b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/24aac0add3547803b571e9d5c6d6c3ecbd09bb5b/tokio/src/sync/rwlock.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:20 | /// let mut n = lock.write().await;
/// *n = 2;
///}
/// ```
pub async fn write(&self) -> RwLockWriteGuard<'_, T> {
let acquire_fut = async {
self.s.acquire(self.mr).await.unwrap_or_else(|_| {
// The semaphore was closed. but, we never explicitly close it, and we ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 24aac0add3547803b571e9d5c6d6c3ecbd09bb5b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/24aac0add3547803b571e9d5c6d6c3ecbd09bb5b/tokio/src/sync/rwlock.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:23 | /// place in the queue.
///
/// # Examples
///
/// ```
/// use std::sync::Arc;
/// use tokio::sync::RwLock;
///
/// #[tokio::main]
/// async fn main() {
/// let lock = Arc::new(RwLock::new(1));
///
/// let mut n = lock.write_owned().await;
/// *n = 2;
///}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 24aac0add3547803b571e9d5c6d6c3ecbd09bb5b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/24aac0add3547803b571e9d5c6d6c3ecbd09bb5b/tokio/src/sync/rwlock.rs | 881 | 940 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:24 | resource_span,
"RwLock::write_owned",
"poll",
false,
);
#[allow(clippy::let_and_return)] // this lint triggers when disabling tracing
let guard = acquire_fut.await;
#[cfg(all(tokio_unstable, feature = "tracing"))]
guard.resource_span.in_scope... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 24aac0add3547803b571e9d5c6d6c3ecbd09bb5b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/24aac0add3547803b571e9d5c6d6c3ecbd09bb5b/tokio/src/sync/rwlock.rs | 921 | 980 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:25 | ///
/// assert!(rw.try_write().is_err());
/// }
/// ```
pub fn try_write(&self) -> Result<RwLockWriteGuard<'_, T>, TryLockError> {
match self.s.try_acquire(self.mr) {
Ok(permit) => permit,
Err(TryAcquireError::NoPermits) => return Err(TryLockError(())),
Er... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 24aac0add3547803b571e9d5c6d6c3ecbd09bb5b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/24aac0add3547803b571e9d5c6d6c3ecbd09bb5b/tokio/src/sync/rwlock.rs | 961 | 1,020 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:26 | /// borrowing it. Therefore, the `RwLock` must be wrapped in an `Arc` to
/// call this method, and the guard will live for the `'static` lifetime,
/// as it keeps the `RwLock` alive by holding an `Arc`.
///
/// [`TryLockError`]: TryLockError
///
/// # Examples
///
/// ```
/// use std... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 24aac0add3547803b571e9d5c6d6c3ecbd09bb5b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/24aac0add3547803b571e9d5c6d6c3ecbd09bb5b/tokio/src/sync/rwlock.rs | 1,001 | 1,060 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:27 | tracing::trace!(
target: "runtime::resource::state_update",
write_locked = true,
write_locked.op = "override",
)
});
Ok(guard)
}
/// Returns a mutable reference to the underlying data.
///
/// Since this call borrows the `RwLock` mutably,... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 24aac0add3547803b571e9d5c6d6c3ecbd09bb5b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/24aac0add3547803b571e9d5c6d6c3ecbd09bb5b/tokio/src/sync/rwlock.rs | 1,041 | 1,097 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:28 | }
}
impl<T> From<T> for RwLock<T> {
fn from(s: T) -> Self {
Self::new(s)
}
}
impl<T: ?Sized> Default for RwLock<T>
where
T: Default,
{
fn default() -> Self {
Self::new(T::default())
}
} | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 24aac0add3547803b571e9d5c6d6c3ecbd09bb5b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/24aac0add3547803b571e9d5c6d6c3ecbd09bb5b/tokio/src/sync/rwlock.rs | 1,081 | 1,097 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:1 | use crate::sync::batch_semaphore::{Semaphore, TryAcquireError};
use crate::sync::mutex::TryLockError;
#[cfg(all(tokio_unstable, feature = "tracing"))]
use crate::util::trace;
use std::cell::UnsafeCell;
use std::marker;
use std::marker::PhantomData;
use std::mem::ManuallyDrop;
use std::sync::Arc;
pub(crate) mod owned_r... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 4daeea8cad1ce8e67946bc0e17d499ab304b5ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4daeea8cad1ce8e67946bc0e17d499ab304b5ca2/tokio/src/sync/rwlock.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:3 | /// ```
///
/// [`Mutex`]: struct@super::Mutex
/// [`RwLock`]: struct@RwLock
/// [`RwLockReadGuard`]: struct@RwLockReadGuard
/// [`RwLockWriteGuard`]: struct@RwLockWriteGuard
/// [`Send`]: trait@std::marker::Send
/// [_write-preferring_]: https://en.wikipedia.org/wiki/Readers%E2%80%93writer_lock#Priority_policies
#[der... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 4daeea8cad1ce8e67946bc0e17d499ab304b5ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4daeea8cad1ce8e67946bc0e17d499ab304b5ca2/tokio/src/sync/rwlock.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:4 | check_send::<OwnedRwLockReadGuard<u32, i32>>();
check_sync::<OwnedRwLockReadGuard<u32, i32>>();
check_unpin::<OwnedRwLockReadGuard<u32, i32>>();
check_send::<RwLockWriteGuard<'_, u32>>();
check_sync::<RwLockWriteGuard<'_, u32>>();
check_unpin::<RwLockWriteGuard<'_, u32>>();
check_send::<RwLock... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 4daeea8cad1ce8e67946bc0e17d499ab304b5ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4daeea8cad1ce8e67946bc0e17d499ab304b5ca2/tokio/src/sync/rwlock.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:5 | where
T: ?Sized + Send + Sync,
U: ?Sized + Sync,
{
}
unsafe impl<T, U> Sync for OwnedRwLockReadGuard<T, U>
where
T: ?Sized + Send + Sync,
U: ?Sized + Send + Sync,
{
}
unsafe impl<T> Sync for RwLockWriteGuard<'_, T> where T: ?Sized + Send + Sync {}
unsafe impl<T> Sync for OwnedRwLockWriteGuard<T> where T... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 4daeea8cad1ce8e67946bc0e17d499ab304b5ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4daeea8cad1ce8e67946bc0e17d499ab304b5ca2/tokio/src/sync/rwlock.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:6 | /// use tokio::sync::RwLock;
///
/// let lock = RwLock::new(5);
/// ```
#[track_caller]
pub fn new(value: T) -> RwLock<T>
where
T: Sized,
{
#[cfg(all(tokio_unstable, feature = "tracing"))]
let resource_span = {
let location = std::panic::Location::caller()... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 4daeea8cad1ce8e67946bc0e17d499ab304b5ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4daeea8cad1ce8e67946bc0e17d499ab304b5ca2/tokio/src/sync/rwlock.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:7 | #[cfg(all(tokio_unstable, feature = "tracing"))]
let s = resource_span.in_scope(|| Semaphore::new(MAX_READS as usize));
#[cfg(any(not(tokio_unstable), not(feature = "tracing")))]
let s = Semaphore::new(MAX_READS as usize);
RwLock {
mr: MAX_READS,
c: UnsafeCell::... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 4daeea8cad1ce8e67946bc0e17d499ab304b5ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4daeea8cad1ce8e67946bc0e17d499ab304b5ca2/tokio/src/sync/rwlock.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:8 | #[cfg(all(tokio_unstable, feature = "tracing"))]
let resource_span = {
let location = std::panic::Location::caller();
let resource_span = tracing::trace_span!(
"runtime.resource",
concrete_type = "RwLock",
kind = "Sync",
lo... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 4daeea8cad1ce8e67946bc0e17d499ab304b5ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4daeea8cad1ce8e67946bc0e17d499ab304b5ca2/tokio/src/sync/rwlock.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:9 | RwLock {
mr: max_reads,
c: UnsafeCell::new(value),
s,
#[cfg(all(tokio_unstable, feature = "tracing"))]
resource_span,
}
}
/// Creates a new instance of an `RwLock<T>` which is unlocked.
///
/// # Examples
///
/// ```
/// us... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 4daeea8cad1ce8e67946bc0e17d499ab304b5ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4daeea8cad1ce8e67946bc0e17d499ab304b5ca2/tokio/src/sync/rwlock.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:10 | ///
/// static LOCK: RwLock<i32> = RwLock::const_with_max_readers(5, 1024);
/// ```
#[cfg(all(feature = "parking_lot", not(all(loom, test))))]
#[cfg_attr(docsrs, doc(cfg(feature = "parking_lot")))]
pub const fn const_with_max_readers(value: T, mut max_reads: u32) -> RwLock<T>
where
T: Si... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 4daeea8cad1ce8e67946bc0e17d499ab304b5ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4daeea8cad1ce8e67946bc0e17d499ab304b5ca2/tokio/src/sync/rwlock.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:11 | /// # Examples
///
/// ```
/// use std::sync::Arc;
/// use tokio::sync::RwLock;
///
/// #[tokio::main]
/// async fn main() {
/// let lock = Arc::new(RwLock::new(1));
/// let c_lock = lock.clone();
///
/// let n = lock.read().await;
/// assert_eq!(*n, 1);
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 4daeea8cad1ce8e67946bc0e17d499ab304b5ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4daeea8cad1ce8e67946bc0e17d499ab304b5ca2/tokio/src/sync/rwlock.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:12 | unreachable!()
});
#[cfg(all(tokio_unstable, feature = "tracing"))]
self.resource_span.in_scope(|| {
tracing::trace!(
target: "runtime::resource::state_update",
current_readers = 1,
current_readers.op = "add",
)
});
Rw... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 4daeea8cad1ce8e67946bc0e17d499ab304b5ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4daeea8cad1ce8e67946bc0e17d499ab304b5ca2/tokio/src/sync/rwlock.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:15 | ///
/// // Drop the guard after the spawned task finishes.
/// drop(n);
///}
/// ```
pub async fn read_owned(self: Arc<Self>) -> OwnedRwLockReadGuard<T> {
#[cfg(all(tokio_unstable, feature = "tracing"))]
let inner = trace::async_op(
|| self.s.acquire(1),
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 4daeea8cad1ce8e67946bc0e17d499ab304b5ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4daeea8cad1ce8e67946bc0e17d499ab304b5ca2/tokio/src/sync/rwlock.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:16 | #[cfg(all(tokio_unstable, feature = "tracing"))]
resource_span,
}
}
/// Attempts to acquire this `RwLock` with shared read access.
///
/// If the access couldn't be acquired immediately, returns [`TryLockError`].
/// Otherwise, an RAII guard is returned which will release read a... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 4daeea8cad1ce8e67946bc0e17d499ab304b5ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4daeea8cad1ce8e67946bc0e17d499ab304b5ca2/tokio/src/sync/rwlock.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:17 | Err(TryAcquireError::NoPermits) => return Err(TryLockError(())),
Err(TryAcquireError::Closed) => unreachable!(),
}
#[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.rs | MIT | 4daeea8cad1ce8e67946bc0e17d499ab304b5ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4daeea8cad1ce8e67946bc0e17d499ab304b5ca2/tokio/src/sync/rwlock.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:18 | /// use tokio::sync::RwLock;
///
/// #[tokio::main]
/// async fn main() {
/// let lock = Arc::new(RwLock::new(1));
/// let c_lock = lock.clone();
///
/// let v = lock.try_read_owned().unwrap();
/// assert_eq!(*v, 1);
///
/// tokio::spawn(async move {
/// ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 4daeea8cad1ce8e67946bc0e17d499ab304b5ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4daeea8cad1ce8e67946bc0e17d499ab304b5ca2/tokio/src/sync/rwlock.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:19 | data: self.c.get(),
lock: ManuallyDrop::new(self),
_p: PhantomData,
#[cfg(all(tokio_unstable, feature = "tracing"))]
resource_span,
})
}
/// Locks this `RwLock` with exclusive write access, causing the current
/// task to yield until the lock has been... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 4daeea8cad1ce8e67946bc0e17d499ab304b5ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4daeea8cad1ce8e67946bc0e17d499ab304b5ca2/tokio/src/sync/rwlock.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:20 | self.resource_span.clone(),
"RwLock::write",
"poll",
false,
);
#[cfg(not(all(tokio_unstable, feature = "tracing")))]
let inner = self.s.acquire(self.mr);
inner.await.unwrap_or_else(|_| {
// The semaphore was closed. but, we never explicit... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 4daeea8cad1ce8e67946bc0e17d499ab304b5ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4daeea8cad1ce8e67946bc0e17d499ab304b5ca2/tokio/src/sync/rwlock.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:22 | /// assert_eq!(*read_lock, 2);
/// }
/// ```
#[track_caller]
#[cfg(feature = "sync")]
pub fn blocking_write(&self) -> RwLockWriteGuard<'_, T> {
crate::future::block_on(self.write())
}
/// Locks this `RwLock` with exclusive write access, causing the current
/// task to yield ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 4daeea8cad1ce8e67946bc0e17d499ab304b5ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4daeea8cad1ce8e67946bc0e17d499ab304b5ca2/tokio/src/sync/rwlock.rs | 841 | 900 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:23 | /// let mut n = lock.write_owned().await;
/// *n = 2;
///}
/// ```
pub async fn write_owned(self: Arc<Self>) -> OwnedRwLockWriteGuard<T> {
#[cfg(all(tokio_unstable, feature = "tracing"))]
let inner = trace::async_op(
|| self.s.acquire(self.mr),
self.resource_s... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 4daeea8cad1ce8e67946bc0e17d499ab304b5ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4daeea8cad1ce8e67946bc0e17d499ab304b5ca2/tokio/src/sync/rwlock.rs | 881 | 940 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:24 | #[cfg(all(tokio_unstable, feature = "tracing"))]
resource_span,
}
}
/// Attempts to acquire this `RwLock` with exclusive write access.
///
/// If the access couldn't be acquired immediately, returns [`TryLockError`].
/// Otherwise, an RAII guard is returned which will release wr... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 4daeea8cad1ce8e67946bc0e17d499ab304b5ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4daeea8cad1ce8e67946bc0e17d499ab304b5ca2/tokio/src/sync/rwlock.rs | 921 | 980 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:25 | write_locked.op = "override",
)
});
Ok(RwLockWriteGuard {
permits_acquired: self.mr,
s: &self.s,
data: self.c.get(),
marker: marker::PhantomData,
#[cfg(all(tokio_unstable, feature = "tracing"))]
resource_span: self.reso... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 4daeea8cad1ce8e67946bc0e17d499ab304b5ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4daeea8cad1ce8e67946bc0e17d499ab304b5ca2/tokio/src/sync/rwlock.rs | 961 | 1,020 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:26 | ///
/// assert!(rw.try_write_owned().is_err());
/// }
/// ```
pub fn try_write_owned(self: Arc<Self>) -> Result<OwnedRwLockWriteGuard<T>, TryLockError> {
match self.s.try_acquire(self.mr) {
Ok(permit) => permit,
Err(TryAcquireError::NoPermits) => return Err(TryLockErr... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 4daeea8cad1ce8e67946bc0e17d499ab304b5ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4daeea8cad1ce8e67946bc0e17d499ab304b5ca2/tokio/src/sync/rwlock.rs | 1,001 | 1,060 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:27 | /// ```
/// use tokio::sync::RwLock;
///
/// fn main() {
/// let mut lock = RwLock::new(1);
///
/// let n = lock.get_mut();
/// *n = 2;
/// }
/// ```
pub fn get_mut(&mut self) -> &mut T {
unsafe {
// Safety: This is https://github.com/rust-lang/rus... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 4daeea8cad1ce8e67946bc0e17d499ab304b5ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4daeea8cad1ce8e67946bc0e17d499ab304b5ca2/tokio/src/sync/rwlock.rs | 1,041 | 1,080 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:15 | /// // Drop the guard after the spawned task finishes.
/// drop(n);
///}
/// ```
pub async fn read_owned(self: Arc<Self>) -> OwnedRwLockReadGuard<T> {
#[cfg(all(tokio_unstable, feature = "tracing"))]
let inner = trace::async_op(
|| self.s.acquire(1),
self.... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 5af9e0db2bfe7cba9c1e25611743724863dcbd2a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5af9e0db2bfe7cba9c1e25611743724863dcbd2a/tokio/src/sync/rwlock.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:16 | resource_span,
}
}
/// Attempts to acquire this `RwLock` with shared read access.
///
/// If the access couldn't be acquired immediately, returns [`TryLockError`].
/// Otherwise, an RAII guard is returned which will release read access
/// when dropped.
///
/// [`TryLockError`]:... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 5af9e0db2bfe7cba9c1e25611743724863dcbd2a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5af9e0db2bfe7cba9c1e25611743724863dcbd2a/tokio/src/sync/rwlock.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:17 | Err(TryAcquireError::Closed) => unreachable!(),
}
#[cfg(all(tokio_unstable, feature = "tracing"))]
self.resource_span.in_scope(|| {
tracing::trace!(
target: "runtime::resource::state_update",
current_readers = 1,
current_readers.op = "add",
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 5af9e0db2bfe7cba9c1e25611743724863dcbd2a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5af9e0db2bfe7cba9c1e25611743724863dcbd2a/tokio/src/sync/rwlock.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:18 | ///
/// #[tokio::main]
/// async fn main() {
/// let lock = Arc::new(RwLock::new(1));
/// let c_lock = lock.clone();
///
/// let v = lock.try_read_owned().unwrap();
/// assert_eq!(*v, 1);
///
/// tokio::spawn(async move {
/// // While main has an activ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 5af9e0db2bfe7cba9c1e25611743724863dcbd2a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5af9e0db2bfe7cba9c1e25611743724863dcbd2a/tokio/src/sync/rwlock.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:19 | lock: ManuallyDrop::new(self),
_p: PhantomData,
#[cfg(all(tokio_unstable, feature = "tracing"))]
resource_span,
})
}
/// Locks this `RwLock` with exclusive write access, causing the current
/// task to yield until the lock has been acquired.
///
/// The c... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 5af9e0db2bfe7cba9c1e25611743724863dcbd2a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5af9e0db2bfe7cba9c1e25611743724863dcbd2a/tokio/src/sync/rwlock.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:20 | "RwLock::write",
"poll",
false,
);
#[cfg(not(all(tokio_unstable, feature = "tracing")))]
let inner = self.s.acquire(self.mr);
inner.await.unwrap_or_else(|_| {
// The semaphore was closed. but, we never explicitly close it, and we have a
/... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 5af9e0db2bfe7cba9c1e25611743724863dcbd2a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5af9e0db2bfe7cba9c1e25611743724863dcbd2a/tokio/src/sync/rwlock.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:22 | /// }
/// ```
#[cfg(feature = "sync")]
pub fn blocking_write(&self) -> RwLockWriteGuard<'_, T> {
crate::future::block_on(self.write())
}
/// Locks this `RwLock` with exclusive write access, causing the current
/// task to yield until the lock has been acquired.
///
/// The calli... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 5af9e0db2bfe7cba9c1e25611743724863dcbd2a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5af9e0db2bfe7cba9c1e25611743724863dcbd2a/tokio/src/sync/rwlock.rs | 841 | 900 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:23 | ///}
/// ```
pub async fn write_owned(self: Arc<Self>) -> OwnedRwLockWriteGuard<T> {
#[cfg(all(tokio_unstable, feature = "tracing"))]
let inner = trace::async_op(
|| self.s.acquire(self.mr),
self.resource_span.clone(),
"RwLock::write_owned",
"poll"... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 5af9e0db2bfe7cba9c1e25611743724863dcbd2a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5af9e0db2bfe7cba9c1e25611743724863dcbd2a/tokio/src/sync/rwlock.rs | 881 | 940 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:24 | }
}
/// Attempts to acquire this `RwLock` with exclusive write access.
///
/// If the access couldn't be acquired immediately, returns [`TryLockError`].
/// Otherwise, an RAII guard is returned which will release write access
/// when dropped.
///
/// [`TryLockError`]: TryLockError
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 5af9e0db2bfe7cba9c1e25611743724863dcbd2a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5af9e0db2bfe7cba9c1e25611743724863dcbd2a/tokio/src/sync/rwlock.rs | 921 | 980 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:25 | });
Ok(RwLockWriteGuard {
permits_acquired: self.mr,
s: &self.s,
data: self.c.get(),
marker: marker::PhantomData,
#[cfg(all(tokio_unstable, feature = "tracing"))]
resource_span: self.resource_span.clone(),
})
}
/// Attempt... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 5af9e0db2bfe7cba9c1e25611743724863dcbd2a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5af9e0db2bfe7cba9c1e25611743724863dcbd2a/tokio/src/sync/rwlock.rs | 961 | 1,020 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:26 | /// }
/// ```
pub fn try_write_owned(self: Arc<Self>) -> Result<OwnedRwLockWriteGuard<T>, TryLockError> {
match self.s.try_acquire(self.mr) {
Ok(permit) => permit,
Err(TryAcquireError::NoPermits) => return Err(TryLockError(())),
Err(TryAcquireError::Closed) => unreach... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 5af9e0db2bfe7cba9c1e25611743724863dcbd2a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5af9e0db2bfe7cba9c1e25611743724863dcbd2a/tokio/src/sync/rwlock.rs | 1,001 | 1,060 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:27 | ///
/// fn main() {
/// let mut lock = RwLock::new(1);
///
/// let n = lock.get_mut();
/// *n = 2;
/// }
/// ```
pub fn get_mut(&mut self) -> &mut T {
unsafe {
// Safety: This is https://github.com/rust-lang/rust/pull/76936
&mut *self.c.get()
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 5af9e0db2bfe7cba9c1e25611743724863dcbd2a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5af9e0db2bfe7cba9c1e25611743724863dcbd2a/tokio/src/sync/rwlock.rs | 1,041 | 1,078 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:11 | /// # Examples
///
/// ```
/// use std::sync::Arc;
/// use tokio::sync::RwLock;
///
/// #[tokio::main]
/// async fn main() {
/// let lock = Arc::new(RwLock::new(1));
/// let c_lock = lock.clone();
///
/// let n = lock.read().await;
/// assert_eq!(*n, 1);
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 4e3268d222423e874f5bbfa67e20f773da3c025f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4e3268d222423e874f5bbfa67e20f773da3c025f/tokio/src/sync/rwlock.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:12 | unreachable!()
});
#[cfg(all(tokio_unstable, feature = "tracing"))]
self.resource_span.in_scope(|| {
tracing::trace!(
target: "runtime::resource::state_update",
current_readers = 1,
current_readers.op = "add",
)
});
Rw... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 4e3268d222423e874f5bbfa67e20f773da3c025f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4e3268d222423e874f5bbfa67e20f773da3c025f/tokio/src/sync/rwlock.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:13 | /// when dropped.
///
/// # Cancel safety
///
/// This method uses a queue to fairly distribute locks in the order they
/// were requested. Cancelling a call to `read_owned` makes you lose your
/// place in the queue.
///
/// # Examples
///
/// ```
/// use std::sync::Arc;
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 4e3268d222423e874f5bbfa67e20f773da3c025f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4e3268d222423e874f5bbfa67e20f773da3c025f/tokio/src/sync/rwlock.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:14 | );
#[cfg(not(all(tokio_unstable, feature = "tracing")))]
let inner = self.s.acquire(1);
inner.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... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 4e3268d222423e874f5bbfa67e20f773da3c025f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4e3268d222423e874f5bbfa67e20f773da3c025f/tokio/src/sync/rwlock.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:15 | /// # Examples
///
/// ```
/// use std::sync::Arc;
/// use tokio::sync::RwLock;
///
/// #[tokio::main]
/// async fn main() {
/// let lock = Arc::new(RwLock::new(1));
/// let c_lock = lock.clone();
///
/// let v = lock.try_read().unwrap();
/// assert_eq!(*v... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 4e3268d222423e874f5bbfa67e20f773da3c025f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4e3268d222423e874f5bbfa67e20f773da3c025f/tokio/src/sync/rwlock.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:16 | Ok(RwLockReadGuard {
s: &self.s,
data: self.c.get(),
marker: marker::PhantomData,
#[cfg(all(tokio_unstable, feature = "tracing"))]
resource_span: self.resource_span.clone(),
})
}
/// Attempts to acquire this `RwLock` with shared read access.
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 4e3268d222423e874f5bbfa67e20f773da3c025f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4e3268d222423e874f5bbfa67e20f773da3c025f/tokio/src/sync/rwlock.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:17 | /// assert_eq!(*n, 1);
/// }).await.expect("The spawned task has panicked");
///
/// // Drop the guard when spawned task finishes.
/// drop(v);
/// }
/// ```
pub fn try_read_owned(self: Arc<Self>) -> Result<OwnedRwLockReadGuard<T>, TryLockError> {
match self.s.try... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 4e3268d222423e874f5bbfa67e20f773da3c025f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4e3268d222423e874f5bbfa67e20f773da3c025f/tokio/src/sync/rwlock.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:18 | ///
/// Returns an RAII guard which will drop the write access of this `RwLock`
/// when dropped.
///
/// # Cancel safety
///
/// This method uses a queue to fairly distribute locks in the order they
/// were requested. Cancelling a call to `write` makes you lose your place
/// in the qu... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 4e3268d222423e874f5bbfa67e20f773da3c025f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4e3268d222423e874f5bbfa67e20f773da3c025f/tokio/src/sync/rwlock.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:19 | });
#[cfg(all(tokio_unstable, feature = "tracing"))]
self.resource_span.in_scope(|| {
tracing::trace!(
target: "runtime::resource::state_update",
write_locked = true,
write_locked.op = "override",
)
});
RwLockWriteGuard {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 4e3268d222423e874f5bbfa67e20f773da3c025f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4e3268d222423e874f5bbfa67e20f773da3c025f/tokio/src/sync/rwlock.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:20 | /// place in the queue.
///
/// # Examples
///
/// ```
/// use std::sync::Arc;
/// use tokio::sync::RwLock;
///
/// #[tokio::main]
/// async fn main() {
/// let lock = Arc::new(RwLock::new(1));
///
/// let mut n = lock.write_owned().await;
/// *n = 2;
///}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 4e3268d222423e874f5bbfa67e20f773da3c025f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4e3268d222423e874f5bbfa67e20f773da3c025f/tokio/src/sync/rwlock.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:21 | write_locked.op = "override",
)
});
#[cfg(all(tokio_unstable, feature = "tracing"))]
let resource_span = self.resource_span.clone();
OwnedRwLockWriteGuard {
permits_acquired: self.mr,
data: self.c.get(),
lock: ManuallyDrop::new(self),
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 4e3268d222423e874f5bbfa67e20f773da3c025f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4e3268d222423e874f5bbfa67e20f773da3c025f/tokio/src/sync/rwlock.rs | 801 | 860 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:22 | pub fn try_write(&self) -> Result<RwLockWriteGuard<'_, T>, TryLockError> {
match self.s.try_acquire(self.mr) {
Ok(permit) => permit,
Err(TryAcquireError::NoPermits) => return Err(TryLockError(())),
Err(TryAcquireError::Closed) => unreachable!(),
}
#[cfg(all(t... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 4e3268d222423e874f5bbfa67e20f773da3c025f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4e3268d222423e874f5bbfa67e20f773da3c025f/tokio/src/sync/rwlock.rs | 841 | 900 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:23 | /// # Examples
///
/// ```
/// use std::sync::Arc;
/// use tokio::sync::RwLock;
///
/// #[tokio::main]
/// async fn main() {
/// let rw = Arc::new(RwLock::new(1));
///
/// let v = Arc::clone(&rw).read_owned().await;
/// assert_eq!(*v, 1);
///
/// asser... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 4e3268d222423e874f5bbfa67e20f773da3c025f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4e3268d222423e874f5bbfa67e20f773da3c025f/tokio/src/sync/rwlock.rs | 881 | 940 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:24 | #[cfg(all(tokio_unstable, feature = "tracing"))]
resource_span,
})
}
/// Returns a mutable reference to the underlying data.
///
/// Since this call borrows the `RwLock` mutably, no actual locking needs to
/// take place -- the mutable borrow statically guarantees no locks exist... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 4e3268d222423e874f5bbfa67e20f773da3c025f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4e3268d222423e874f5bbfa67e20f773da3c025f/tokio/src/sync/rwlock.rs | 921 | 972 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:25 | Self::new(s)
}
}
impl<T: ?Sized> Default for RwLock<T>
where
T: Default,
{
fn default() -> Self {
Self::new(T::default())
}
} | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 4e3268d222423e874f5bbfa67e20f773da3c025f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4e3268d222423e874f5bbfa67e20f773da3c025f/tokio/src/sync/rwlock.rs | 961 | 972 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:1 | use crate::sync::batch_semaphore::{Semaphore, TryAcquireError};
use crate::sync::mutex::TryLockError;
use std::cell::UnsafeCell;
use std::marker;
use std::marker::PhantomData;
use std::mem::ManuallyDrop;
use std::sync::Arc;
pub(crate) mod owned_read_guard;
pub(crate) mod owned_write_guard;
pub(crate) mod owned_write_g... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | b521cc26895c6331c8ced6be72f8b3d9947a9fb3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b521cc26895c6331c8ced6be72f8b3d9947a9fb3/tokio/src/sync/rwlock.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:3 | /// [`Mutex`]: struct@super::Mutex
/// [`RwLock`]: struct@RwLock
/// [`RwLockReadGuard`]: struct@RwLockReadGuard
/// [`RwLockWriteGuard`]: struct@RwLockWriteGuard
/// [`Send`]: trait@std::marker::Send
/// [_write-preferring_]: https://en.wikipedia.org/wiki/Readers%E2%80%93writer_lock#Priority_policies
#[derive(Debug)]
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | b521cc26895c6331c8ced6be72f8b3d9947a9fb3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b521cc26895c6331c8ced6be72f8b3d9947a9fb3/tokio/src/sync/rwlock.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:4 | check_sync::<RwLockWriteGuard<'_, u32>>();
check_unpin::<RwLockWriteGuard<'_, u32>>();
check_send::<RwLockMappedWriteGuard<'_, u32>>();
check_sync::<RwLockMappedWriteGuard<'_, u32>>();
check_unpin::<RwLockMappedWriteGuard<'_, u32>>();
check_send::<OwnedRwLockWriteGuard<u32>>();
check_sync::<Ow... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | b521cc26895c6331c8ced6be72f8b3d9947a9fb3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b521cc26895c6331c8ced6be72f8b3d9947a9fb3/tokio/src/sync/rwlock.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:5 | unsafe impl<T, U> Sync for OwnedRwLockReadGuard<T, U>
where
T: ?Sized + Send + Sync,
U: ?Sized + Send + Sync,
{
}
unsafe impl<T> Sync for RwLockWriteGuard<'_, T> where T: ?Sized + Send + Sync {}
unsafe impl<T> Sync for OwnedRwLockWriteGuard<T> where T: ?Sized + Send + Sync {}
unsafe impl<T> Sync for RwLockMappe... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | b521cc26895c6331c8ced6be72f8b3d9947a9fb3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b521cc26895c6331c8ced6be72f8b3d9947a9fb3/tokio/src/sync/rwlock.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:6 | where
T: Sized,
{
RwLock {
mr: MAX_READS,
c: UnsafeCell::new(value),
s: Semaphore::new(MAX_READS as usize),
}
}
/// Creates a new instance of an `RwLock<T>` which is unlocked
/// and allows a maximum of `max_reads` concurrent readers.
///
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | b521cc26895c6331c8ced6be72f8b3d9947a9fb3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b521cc26895c6331c8ced6be72f8b3d9947a9fb3/tokio/src/sync/rwlock.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:7 | /// Creates a new instance of an `RwLock<T>` which is unlocked.
///
/// # Examples
///
/// ```
/// use tokio::sync::RwLock;
///
/// static LOCK: RwLock<i32> = RwLock::const_new(5);
/// ```
#[cfg(all(feature = "parking_lot", not(all(loom, test))))]
#[cfg_attr(docsrs, doc(cfg(featu... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | b521cc26895c6331c8ced6be72f8b3d9947a9fb3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b521cc26895c6331c8ced6be72f8b3d9947a9fb3/tokio/src/sync/rwlock.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:11 | });
OwnedRwLockReadGuard {
data: self.c.get(),
lock: ManuallyDrop::new(self),
_p: PhantomData,
}
}
/// Attempts to acquire this `RwLock` with shared read access.
///
/// If the access couldn't be acquired immediately, returns [`TryLockError`].
///... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | b521cc26895c6331c8ced6be72f8b3d9947a9fb3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b521cc26895c6331c8ced6be72f8b3d9947a9fb3/tokio/src/sync/rwlock.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:12 | pub fn try_read(&self) -> Result<RwLockReadGuard<'_, T>, TryLockError> {
match self.s.try_acquire(1) {
Ok(permit) => permit,
Err(TryAcquireError::NoPermits) => return Err(TryLockError(())),
Err(TryAcquireError::Closed) => unreachable!(),
}
Ok(RwLockReadGuard ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | b521cc26895c6331c8ced6be72f8b3d9947a9fb3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b521cc26895c6331c8ced6be72f8b3d9947a9fb3/tokio/src/sync/rwlock.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:13 | /// assert_eq!(*v, 1);
///
/// tokio::spawn(async move {
/// // While main has an active read lock, we acquire one too.
/// let n = c_lock.read_owned().await;
/// assert_eq!(*n, 1);
/// }).await.expect("The spawned task has panicked");
///
/// // D... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | b521cc26895c6331c8ced6be72f8b3d9947a9fb3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b521cc26895c6331c8ced6be72f8b3d9947a9fb3/tokio/src/sync/rwlock.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:17 | ///
/// This method is identical to [`RwLock::try_write`], except that the
/// returned guard references the `RwLock` with an [`Arc`] rather than by
/// borrowing it. Therefore, the `RwLock` must be wrapped in an `Arc` to
/// call this method, and the guard will live for the `'static` lifetime,
/// ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | b521cc26895c6331c8ced6be72f8b3d9947a9fb3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b521cc26895c6331c8ced6be72f8b3d9947a9fb3/tokio/src/sync/rwlock.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:18 | /// Returns a mutable reference to the underlying data.
///
/// Since this call borrows the `RwLock` mutably, no actual locking needs to
/// take place -- the mutable borrow statically guarantees no locks exist.
///
/// # Examples
///
/// ```
/// use tokio::sync::RwLock;
///
/// ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | b521cc26895c6331c8ced6be72f8b3d9947a9fb3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b521cc26895c6331c8ced6be72f8b3d9947a9fb3/tokio/src/sync/rwlock.rs | 681 | 727 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:8 | mr: max_reads,
c: UnsafeCell::new(value),
s: Semaphore::const_new(max_reads as usize),
}
}
/// Locks this `RwLock` with shared read access, causing the current task
/// to yield until the lock has been acquired.
///
/// The calling task will yield until there are no ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | a5ee2f0d3d78daa01e2c6c12d22b82474dc5c32a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a5ee2f0d3d78daa01e2c6c12d22b82474dc5c32a/tokio/src/sync/rwlock.rs | 281 | 340 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.