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:13 | pub fn try_read_owned(self: Arc<Self>) -> Result<OwnedRwLockReadGuard<T>, TryLockError> {
match self.s.try_acquire(1) {
Ok(permit) => permit,
Err(TryAcquireError::NoPermits) => return Err(TryLockError(())),
Err(TryAcquireError::Closed) => unreachable!(),
}
Ok... | 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 | 481 | 540 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:14 | unreachable!()
});
RwLockWriteGuard {
permits_acquired: self.mr,
s: &self.s,
data: self.c.get(),
marker: marker::PhantomData,
}
}
/// Locks this `RwLock` with exclusive write access, causing the current
/// task to yield until the lock... | 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 | 521 | 580 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:15 | 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 through the Arc, which means that this can never happen.
unreachable!()
});
OwnedRwLockWriteGuard {
permits_acq... | 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 | 561 | 620 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:16 | Err(TryAcquireError::Closed) => unreachable!(),
}
Ok(RwLockWriteGuard {
permits_acquired: self.mr,
s: &self.s,
data: self.c.get(),
marker: marker::PhantomData,
})
}
/// Attempts to acquire this `RwLock` with exclusive write access.
//... | 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 | 601 | 660 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:17 | /// ```
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) => unreachable!(),
... | 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 | 641 | 700 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:18 | /// Consumes the lock, returning the underlying data.
pub fn into_inner(self) -> T
where
T: Sized,
{
self.c.into_inner()
}
}
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 def... | 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 | 681 | 703 |
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 | e89c8981f151a667bb676213d38b7dbeb51620e9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e89c8981f151a667bb676213d38b7dbeb51620e9/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 | e89c8981f151a667bb676213d38b7dbeb51620e9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e89c8981f151a667bb676213d38b7dbeb51620e9/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 | e89c8981f151a667bb676213d38b7dbeb51620e9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e89c8981f151a667bb676213d38b7dbeb51620e9/tokio/src/sync/rwlock.rs | 241 | 300 |
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 | 0dc4769708279a076e01a66dc53ec226083c1bdb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0dc4769708279a076e01a66dc53ec226083c1bdb/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 | 0dc4769708279a076e01a66dc53ec226083c1bdb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0dc4769708279a076e01a66dc53ec226083c1bdb/tokio/src/sync/rwlock.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:4 | check_send::<RwLockMappedWriteGuard<'_, u32>>();
check_sync::<RwLockMappedWriteGuard<'_, u32>>();
check_unpin::<RwLockMappedWriteGuard<'_, u32>>();
check_send::<OwnedRwLockWriteGuard<u32>>();
check_sync::<OwnedRwLockWriteGuard<u32>>();
check_unpin::<OwnedRwLockWriteGuard<u32>>();
check_send::<... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 0dc4769708279a076e01a66dc53ec226083c1bdb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0dc4769708279a076e01a66dc53ec226083c1bdb/tokio/src/sync/rwlock.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:5 | 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 RwLockMappedWriteGuard<'_, T> where T: ?Sized + Send + Sync {}
unsafe impl<T, U> Sync for OwnedRwLockMap... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 0dc4769708279a076e01a66dc53ec226083c1bdb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0dc4769708279a076e01a66dc53ec226083c1bdb/tokio/src/sync/rwlock.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:6 | RwLock {
c: UnsafeCell::new(value),
s: Semaphore::new(MAX_READS),
}
}
/// Creates a new instance of an `RwLock<T>` which is unlocked.
///
/// # Examples
///
/// ```
/// use tokio::sync::RwLock;
///
/// static LOCK: RwLock<i32> = RwLock::const_new(5);
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 0dc4769708279a076e01a66dc53ec226083c1bdb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0dc4769708279a076e01a66dc53ec226083c1bdb/tokio/src/sync/rwlock.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:9 | /// // Drop the guard after the spawned task finishes.
/// drop(n);
///}
/// ```
pub async fn read_owned(self: Arc<Self>) -> OwnedRwLockReadGuard<T> {
self.s.acquire(1).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 | 0dc4769708279a076e01a66dc53ec226083c1bdb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0dc4769708279a076e01a66dc53ec226083c1bdb/tokio/src/sync/rwlock.rs | 321 | 380 |
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 v = lock.try_read_owned().unwrap();
/// assert_eq!(*v, 1);
///
/// tokio::... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 0dc4769708279a076e01a66dc53ec226083c1bdb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0dc4769708279a076e01a66dc53ec226083c1bdb/tokio/src/sync/rwlock.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:13 | /// the `RwLock` alive by holding an `Arc`.
///
/// Returns an RAII guard which will drop the write access of this `RwLock`
/// when dropped.
///
/// # Examples
///
/// ```
/// use std::sync::Arc;
/// use tokio::sync::RwLock;
///
/// #[tokio::main]
/// async fn main() {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 0dc4769708279a076e01a66dc53ec226083c1bdb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0dc4769708279a076e01a66dc53ec226083c1bdb/tokio/src/sync/rwlock.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:15 | ///
/// [`TryLockError`]: TryLockError
///
/// # 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;
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 0dc4769708279a076e01a66dc53ec226083c1bdb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0dc4769708279a076e01a66dc53ec226083c1bdb/tokio/src/sync/rwlock.rs | 561 | 620 |
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;
pub(crate) mod read_guard;
pub(crate) mod write_guard;
pub(crate) mod write_guard_mapped;
pub(crate) use read_guard::RwLockReadGuard;
pub(crate) use write_guard::RwLockWrite... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | e3f2dcf5bc8315f01c8843259e78c8e98203a978 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e3f2dcf5bc8315f01c8843259e78c8e98203a978/tokio/src/sync/rwlock.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:2 | /// required that `T` satisfies [`Send`] to be shared across threads. The RAII guards
/// returned from the locking methods implement [`Deref`](trait@std::ops::Deref)
/// (and [`DerefMut`](trait@std::ops::DerefMut)
/// for the `write` methods) to allow access to the content of the lock.
///
/// # Examples
///
/// ```
/... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | e3f2dcf5bc8315f01c8843259e78c8e98203a978 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e3f2dcf5bc8315f01c8843259e78c8e98203a978/tokio/src/sync/rwlock.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:3 | s: Semaphore,
//inner data T
c: UnsafeCell<T>,
}
#[test]
#[cfg(not(loom))]
fn bounds() {
fn check_send<T: Send>() {}
fn check_sync<T: Sync>() {}
fn check_unpin<T: Unpin>() {}
// This has to take a value, since the async fn's return type is unnameable.
fn check_send_sync_val<T: Send + Sync>... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | e3f2dcf5bc8315f01c8843259e78c8e98203a978 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e3f2dcf5bc8315f01c8843259e78c8e98203a978/tokio/src/sync/rwlock.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:4 | unsafe impl<T> Send for RwLockReadGuard<'_, T> where T: ?Sized + Sync {}
unsafe impl<T> Sync for RwLockReadGuard<'_, T> where T: ?Sized + Send + Sync {}
unsafe impl<T> Sync for RwLockWriteGuard<'_, T> where T: ?Sized + Send + Sync {}
unsafe impl<T> Sync for RwLockMappedWriteGuard<'_, T> where T: ?Sized + Send + Sync {}... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | e3f2dcf5bc8315f01c8843259e78c8e98203a978 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e3f2dcf5bc8315f01c8843259e78c8e98203a978/tokio/src/sync/rwlock.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:5 | #[cfg(all(feature = "parking_lot", not(all(loom, test))))]
#[cfg_attr(docsrs, doc(cfg(feature = "parking_lot")))]
pub const fn const_new(value: T) -> RwLock<T>
where
T: Sized,
{
RwLock {
c: UnsafeCell::new(value),
s: Semaphore::const_new(MAX_READS),
}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | e3f2dcf5bc8315f01c8843259e78c8e98203a978 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e3f2dcf5bc8315f01c8843259e78c8e98203a978/tokio/src/sync/rwlock.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:6 | ///
/// tokio::spawn(async move {
/// // While main has an active read lock, we acquire one too.
/// let r = c_lock.read().await;
/// assert_eq!(*r, 1);
/// }).await.expect("The spawned task has panicked");
///
/// // Drop the guard after the spawned task ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | e3f2dcf5bc8315f01c8843259e78c8e98203a978 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e3f2dcf5bc8315f01c8843259e78c8e98203a978/tokio/src/sync/rwlock.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:7 | /// let lock = Arc::new(RwLock::new(1));
/// let c_lock = lock.clone();
///
/// let v = lock.try_read().unwrap();
/// assert_eq!(*v, 1);
///
/// tokio::spawn(async move {
/// // While main has an active read lock, we acquire one too.
/// let n = c_lock... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | e3f2dcf5bc8315f01c8843259e78c8e98203a978 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e3f2dcf5bc8315f01c8843259e78c8e98203a978/tokio/src/sync/rwlock.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:8 | ///
/// ```
/// use tokio::sync::RwLock;
///
/// #[tokio::main]
/// async fn main() {
/// let lock = RwLock::new(1);
///
/// let mut n = lock.write().await;
/// *n = 2;
///}
/// ```
pub async fn write(&self) -> RwLockWriteGuard<'_, T> {
self.s.acquire(MAX_RE... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | e3f2dcf5bc8315f01c8843259e78c8e98203a978 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e3f2dcf5bc8315f01c8843259e78c8e98203a978/tokio/src/sync/rwlock.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:9 | /// let rw = RwLock::new(1);
///
/// let v = rw.read().await;
/// assert_eq!(*v, 1);
///
/// assert!(rw.try_write().is_err());
/// }
/// ```
pub fn try_write(&self) -> Result<RwLockWriteGuard<'_, T>, TryLockError> {
match self.s.try_acquire(MAX_READS as u32) {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | e3f2dcf5bc8315f01c8843259e78c8e98203a978 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e3f2dcf5bc8315f01c8843259e78c8e98203a978/tokio/src/sync/rwlock.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:10 | unsafe {
// Safety: This is https://github.com/rust-lang/rust/pull/76936
&mut *self.c.get()
}
}
/// Consumes the lock, returning the underlying data.
pub fn into_inner(self) -> T
where
T: Sized,
{
self.c.into_inner()
}
}
impl<T> From<T> for RwLoc... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | e3f2dcf5bc8315f01c8843259e78c8e98203a978 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e3f2dcf5bc8315f01c8843259e78c8e98203a978/tokio/src/sync/rwlock.rs | 361 | 389 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:3 | }
/// RAII structure used to release the shared read access of a lock when
/// dropped.
///
/// This structure is created by the [`read`] method on
/// [`RwLock`].
///
/// [`read`]: method@RwLock::read
/// [`RwLock`]: struct@RwLock
pub struct RwLockReadGuard<'a, T: ?Sized> {
s: &'a Semaphore,
data: *const T,
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 225e8ea05f2dbc056250d2572fb9363123ee35ef | github | async-runtime | https://github.com/tokio-rs/tokio/blob/225e8ea05f2dbc056250d2572fb9363123ee35ef/tokio/src/sync/rwlock.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:4 | /// # #[tokio::main]
/// # async fn main() {
/// let lock = RwLock::new(Foo(1));
///
/// let guard = lock.read().await;
/// let guard = RwLockReadGuard::map(guard, |f| &f.0);
///
/// assert_eq!(1, *guard);
/// # }
/// ```
#[inline]
pub fn map<F, U: ?Sized>(this: Self, f: F) -... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 225e8ea05f2dbc056250d2572fb9363123ee35ef | github | async-runtime | https://github.com/tokio-rs/tokio/blob/225e8ea05f2dbc056250d2572fb9363123ee35ef/tokio/src/sync/rwlock.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:5 | /// [`RwLockReadGuard::try_map`]: https://docs.rs/lock_api/latest/lock_api/struct.RwLockReadGuard.html#method.try_map
/// [`parking_lot` crate]: https://crates.io/crates/parking_lot
///
/// # Examples
///
/// ```
/// use tokio::sync::{RwLock, RwLockReadGuard};
///
/// #[derive(Debug, Clo... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 225e8ea05f2dbc056250d2572fb9363123ee35ef | github | async-runtime | https://github.com/tokio-rs/tokio/blob/225e8ea05f2dbc056250d2572fb9363123ee35ef/tokio/src/sync/rwlock.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:6 | impl<'a, T: ?Sized> fmt::Debug for RwLockReadGuard<'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 RwLockReadGuard<'a, T>
where
T: fmt::Display,
{
fn fmt(&self, f: &mut fmt::Formatt... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 225e8ea05f2dbc056250d2572fb9363123ee35ef | github | async-runtime | https://github.com/tokio-rs/tokio/blob/225e8ea05f2dbc056250d2572fb9363123ee35ef/tokio/src/sync/rwlock.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:7 | /// 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.rs | MIT | 225e8ea05f2dbc056250d2572fb9363123ee35ef | github | async-runtime | https://github.com/tokio-rs/tokio/blob/225e8ea05f2dbc056250d2572fb9363123ee35ef/tokio/src/sync/rwlock.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:8 | // Release all but one of the permits held by the write guard
s.release(MAX_READS - 1);
// NB: Forget to avoid drop impl from being called.
mem::forget(self);
RwLockReadGuard {
s,
data,
marker: marker::PhantomData,
}
}
}
impl<'a, T: ?Sized... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 225e8ea05f2dbc056250d2572fb9363123ee35ef | github | async-runtime | https://github.com/tokio-rs/tokio/blob/225e8ea05f2dbc056250d2572fb9363123ee35ef/tokio/src/sync/rwlock.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:9 | fn check_sync<T: Sync>() {}
fn check_unpin<T: Unpin>() {}
// This has to take a value, since the async fn's return type is unnameable.
fn check_send_sync_val<T: Send + Sync>(_t: T) {}
check_send::<RwLock<u32>>();
check_sync::<RwLock<u32>>();
check_unpin::<RwLock<u32>>();
check_send::<RwLoc... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 225e8ea05f2dbc056250d2572fb9363123ee35ef | github | async-runtime | https://github.com/tokio-rs/tokio/blob/225e8ea05f2dbc056250d2572fb9363123ee35ef/tokio/src/sync/rwlock.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:10 | /// Creates a new instance of an `RwLock<T>` which is unlocked.
///
/// # Examples
///
/// ```
/// use tokio::sync::RwLock;
///
/// let lock = RwLock::new(5);
/// ```
pub fn new(value: T) -> RwLock<T>
where
T: Sized,
{
RwLock {
c: UnsafeCell::new(v... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 225e8ea05f2dbc056250d2572fb9363123ee35ef | github | async-runtime | https://github.com/tokio-rs/tokio/blob/225e8ea05f2dbc056250d2572fb9363123ee35ef/tokio/src/sync/rwlock.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:12 | pub async fn read(&self) -> RwLockReadGuard<'_, T> {
self.s.acquire(1).await.unwrap_or_else(|_| {
// The semaphore was closed. but, we never explicitly close it, and we have a
// handle to it through the Arc, which means that this can never happen.
unreachable!()
});
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 225e8ea05f2dbc056250d2572fb9363123ee35ef | github | async-runtime | https://github.com/tokio-rs/tokio/blob/225e8ea05f2dbc056250d2572fb9363123ee35ef/tokio/src/sync/rwlock.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:13 | ///
/// // 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(TryLockE... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 225e8ea05f2dbc056250d2572fb9363123ee35ef | github | async-runtime | https://github.com/tokio-rs/tokio/blob/225e8ea05f2dbc056250d2572fb9363123ee35ef/tokio/src/sync/rwlock.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:14 | /// ```
pub async fn write(&self) -> RwLockWriteGuard<'_, T> {
self.s.acquire(MAX_READS as u32).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 | 225e8ea05f2dbc056250d2572fb9363123ee35ef | github | async-runtime | https://github.com/tokio-rs/tokio/blob/225e8ea05f2dbc056250d2572fb9363123ee35ef/tokio/src/sync/rwlock.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:15 | Err(TryAcquireError::NoPermits) => return Err(TryLockError(())),
Err(TryAcquireError::Closed) => unreachable!(),
}
Ok(RwLockWriteGuard {
s: &self.s,
data: self.c.get(),
marker: marker::PhantomData,
})
}
/// Returns a mutable reference to ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 225e8ea05f2dbc056250d2572fb9363123ee35ef | github | async-runtime | https://github.com/tokio-rs/tokio/blob/225e8ea05f2dbc056250d2572fb9363123ee35ef/tokio/src/sync/rwlock.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:16 | self.c.into_inner()
}
}
impl<T: ?Sized> ops::Deref for RwLockReadGuard<'_, T> {
type Target = T;
fn deref(&self) -> &T {
unsafe { &*self.data }
}
}
impl<T: ?Sized> ops::Deref for RwLockWriteGuard<'_, T> {
type Target = T;
fn deref(&self) -> &T {
unsafe { &*self.data }
}
}... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 225e8ea05f2dbc056250d2572fb9363123ee35ef | github | async-runtime | https://github.com/tokio-rs/tokio/blob/225e8ea05f2dbc056250d2572fb9363123ee35ef/tokio/src/sync/rwlock.rs | 601 | 640 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:6 | impl<'a, T: ?Sized> fmt::Debug for RwLockReadGuard<'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 RwLockReadGuard<'a, T>
where
T: fmt::Display,
{
fn fmt(&self, f: &mut fmt::Formatt... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | ecc32d1dca2317e555d8a6b29009cf19ef8f53e8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ecc32d1dca2317e555d8a6b29009cf19ef8f53e8/tokio/src/sync/rwlock.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:7 | /// 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.rs | MIT | ecc32d1dca2317e555d8a6b29009cf19ef8f53e8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ecc32d1dca2317e555d8a6b29009cf19ef8f53e8/tokio/src/sync/rwlock.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:10 | /// Creates a new instance of an `RwLock<T>` which is unlocked.
///
/// # Examples
///
/// ```
/// use tokio::sync::RwLock;
///
/// let lock = RwLock::new(5);
/// ```
pub fn new(value: T) -> RwLock<T>
where
T: Sized,
{
RwLock {
c: UnsafeCell::new(v... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | ecc32d1dca2317e555d8a6b29009cf19ef8f53e8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ecc32d1dca2317e555d8a6b29009cf19ef8f53e8/tokio/src/sync/rwlock.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:12 | marker: marker::PhantomData,
}
}
/// 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.
///
/// [`T... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | ecc32d1dca2317e555d8a6b29009cf19ef8f53e8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ecc32d1dca2317e555d8a6b29009cf19ef8f53e8/tokio/src/sync/rwlock.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:13 | Err(TryAcquireError::Closed) => unreachable!(),
}
Ok(RwLockReadGuard {
s: &self.s,
data: self.c.get(),
marker: marker::PhantomData,
})
}
/// Locks this rwlock with exclusive write access, causing the current task
/// to yield until the lock has b... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | ecc32d1dca2317e555d8a6b29009cf19ef8f53e8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ecc32d1dca2317e555d8a6b29009cf19ef8f53e8/tokio/src/sync/rwlock.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:14 | data: self.c.get(),
marker: marker::PhantomData,
}
}
/// 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
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | ecc32d1dca2317e555d8a6b29009cf19ef8f53e8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ecc32d1dca2317e555d8a6b29009cf19ef8f53e8/tokio/src/sync/rwlock.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:15 | }
/// 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 | ecc32d1dca2317e555d8a6b29009cf19ef8f53e8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ecc32d1dca2317e555d8a6b29009cf19ef8f53e8/tokio/src/sync/rwlock.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:16 | }
}
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<T> From<T> for RwLo... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | ecc32d1dca2317e555d8a6b29009cf19ef8f53e8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ecc32d1dca2317e555d8a6b29009cf19ef8f53e8/tokio/src/sync/rwlock.rs | 601 | 631 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:3 | /// RAII structure used to release the shared read access of a lock when
/// dropped.
///
/// This structure is created by the [`read`] method on
/// [`RwLock`].
///
/// [`read`]: method@RwLock::read
/// [`RwLock`]: struct@RwLock
pub struct RwLockReadGuard<'a, T: ?Sized> {
s: &'a Semaphore,
data: *const T,
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | fe2664a4e11df3f7938d5e6fc244a565906bcb46 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fe2664a4e11df3f7938d5e6fc244a565906bcb46/tokio/src/sync/rwlock.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:4 | /// # async fn main() {
/// let lock = RwLock::new(Foo(1));
///
/// let guard = lock.read().await;
/// let guard = RwLockReadGuard::map(guard, |f| &f.0);
///
/// assert_eq!(1, *guard);
/// # }
/// ```
#[inline]
pub fn map<F, U: ?Sized>(this: Self, f: F) -> RwLockReadGuard<'a, U>
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | fe2664a4e11df3f7938d5e6fc244a565906bcb46 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fe2664a4e11df3f7938d5e6fc244a565906bcb46/tokio/src/sync/rwlock.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:5 | /// [`parking_lot` crate]: https://crates.io/crates/parking_lot
///
/// # Examples
///
/// ```
/// use tokio::sync::{RwLock, RwLockReadGuard};
///
/// #[derive(Debug, Clone, Copy, PartialEq, Eq)]
/// struct Foo(u32);
///
/// # #[tokio::main]
/// # async fn main() {
/// le... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | fe2664a4e11df3f7938d5e6fc244a565906bcb46 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fe2664a4e11df3f7938d5e6fc244a565906bcb46/tokio/src/sync/rwlock.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:6 | impl<'a, T: ?Sized> fmt::Debug for RwLockReadGuard<'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 RwLockReadGuard<'a, T>
where
T: fmt::Display,
{
fn fmt(&self, f: &mut fmt::Formatt... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | fe2664a4e11df3f7938d5e6fc244a565906bcb46 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fe2664a4e11df3f7938d5e6fc244a565906bcb46/tokio/src/sync/rwlock.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:7 | /// 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
/// in line.
///
/// Returns an RAII guard which will drop the rea... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | fe2664a4e11df3f7938d5e6fc244a565906bcb46 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fe2664a4e11df3f7938d5e6fc244a565906bcb46/tokio/src/sync/rwlock.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:8 | s.release(MAX_READS - 1);
// NB: Forget to avoid drop impl from being called.
mem::forget(self);
RwLockReadGuard {
s,
data,
marker: marker::PhantomData,
}
}
}
impl<'a, T: ?Sized> fmt::Debug for RwLockWriteGuard<'a, T>
where
T: fmt::Debug,
{
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | fe2664a4e11df3f7938d5e6fc244a565906bcb46 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fe2664a4e11df3f7938d5e6fc244a565906bcb46/tokio/src/sync/rwlock.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:9 | fn check_unpin<T: Unpin>() {}
// This has to take a value, since the async fn's return type is unnameable.
fn check_send_sync_val<T: Send + Sync>(_t: T) {}
check_send::<RwLock<u32>>();
check_sync::<RwLock<u32>>();
check_unpin::<RwLock<u32>>();
check_send::<RwLockReadGuard<'_, u32>>();
chec... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | fe2664a4e11df3f7938d5e6fc244a565906bcb46 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fe2664a4e11df3f7938d5e6fc244a565906bcb46/tokio/src/sync/rwlock.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:10 | ///
/// # Examples
///
/// ```
/// use tokio::sync::RwLock;
///
/// let lock = RwLock::new(5);
/// ```
pub fn new(value: T) -> RwLock<T>
where
T: Sized,
{
RwLock {
c: UnsafeCell::new(value),
s: Semaphore::new(MAX_READS),
}
}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | fe2664a4e11df3f7938d5e6fc244a565906bcb46 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fe2664a4e11df3f7938d5e6fc244a565906bcb46/tokio/src/sync/rwlock.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:12 | }
}
/// Locks this rwlock with exclusive write access, causing the current task
/// to yield until the lock has been acquired.
///
/// This function will not return while other writers or other readers
/// currently have access to the lock.
///
/// Returns an RAII guard which will drop ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | fe2664a4e11df3f7938d5e6fc244a565906bcb46 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fe2664a4e11df3f7938d5e6fc244a565906bcb46/tokio/src/sync/rwlock.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:13 | /// 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;
///
/// fn main() {
/// let mut lock = RwLock::new(1);
///
/... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | fe2664a4e11df3f7938d5e6fc244a565906bcb46 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fe2664a4e11df3f7938d5e6fc244a565906bcb46/tokio/src/sync/rwlock.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:14 | 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<T> From<T> for RwLock<T> {
fn from(s: T) -> Self {
Self::new(s)
}
}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | fe2664a4e11df3f7938d5e6fc244a565906bcb46 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fe2664a4e11df3f7938d5e6fc244a565906bcb46/tokio/src/sync/rwlock.rs | 521 | 547 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:6 | impl<'a, T: ?Sized> fmt::Debug for RwLockReadGuard<'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 RwLockReadGuard<'a, T>
where
T: fmt::Display,
{
fn fmt(&self, f: &mut fmt::Formatt... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | e804f88d60071f0d89db85aaa4a073857904b545 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e804f88d60071f0d89db85aaa4a073857904b545/tokio/src/sync/rwlock.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:7 | ///
/// 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::map(..)`. A method would interfere with methods of
/// the same name on the contents of the locked data.
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | e804f88d60071f0d89db85aaa4a073857904b545 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e804f88d60071f0d89db85aaa4a073857904b545/tokio/src/sync/rwlock.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:8 | let s = this.s;
// NB: Forget to avoid drop impl from being called.
mem::forget(this);
RwLockWriteGuard {
s,
data,
marker: marker::PhantomData,
}
}
/// Attempts to make a new [`RwLockWriteGuard`] for a component of
/// the locked data. Th... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | e804f88d60071f0d89db85aaa4a073857904b545 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e804f88d60071f0d89db85aaa4a073857904b545/tokio/src/sync/rwlock.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:9 | /// let guard = lock.write().await;
/// let mut guard = RwLockWriteGuard::try_map(guard, |f| Some(&mut f.0)).expect("should not fail");
/// *guard = 2;
/// }
///
/// assert_eq!(Foo(2), *lock.read().await);
/// # }
/// ```
#[inline]
pub fn try_map<F, U: ?Sized>(mut this: S... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | e804f88d60071f0d89db85aaa4a073857904b545 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e804f88d60071f0d89db85aaa4a073857904b545/tokio/src/sync/rwlock.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:10 | /// # 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 handle = tokio::spawn(async move {
/// ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | e804f88d60071f0d89db85aaa4a073857904b545 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e804f88d60071f0d89db85aaa4a073857904b545/tokio/src/sync/rwlock.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:11 | 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 RwLockWriteGuard<'a, T>
where
T: fmt::Display,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(&**sel... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | e804f88d60071f0d89db85aaa4a073857904b545 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e804f88d60071f0d89db85aaa4a073857904b545/tokio/src/sync/rwlock.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:12 | check_send::<RwLockWriteGuard<'_, u32>>();
check_sync::<RwLockWriteGuard<'_, u32>>();
check_unpin::<RwLockWriteGuard<'_, u32>>();
let rwlock = RwLock::new(0);
check_send_sync_val(rwlock.read());
check_send_sync_val(rwlock.write());
}
// As long as T: Send + Sync, it's fine to send and share RwLock... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | e804f88d60071f0d89db85aaa4a073857904b545 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e804f88d60071f0d89db85aaa4a073857904b545/tokio/src/sync/rwlock.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:13 | RwLock {
c: UnsafeCell::new(value),
s: Semaphore::new(MAX_READS),
}
}
/// Creates a new instance of an `RwLock<T>` which is unlocked.
///
/// # Examples
///
/// ```
/// use tokio::sync::RwLock;
///
/// static LOCK: RwLock<i32> = RwLock::const_new(5);
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | e804f88d60071f0d89db85aaa4a073857904b545 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e804f88d60071f0d89db85aaa4a073857904b545/tokio/src/sync/rwlock.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:14 | /// #[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::spawn(async move {
/// // While main has an active read lock, we acqui... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | e804f88d60071f0d89db85aaa4a073857904b545 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e804f88d60071f0d89db85aaa4a073857904b545/tokio/src/sync/rwlock.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:15 | /// # Examples
///
/// ```
/// use tokio::sync::RwLock;
///
/// #[tokio::main]
/// async fn main() {
/// let lock = RwLock::new(1);
///
/// let mut n = lock.write().await;
/// *n = 2;
///}
/// ```
pub async fn write(&self) -> RwLockWriteGuard<'_, T> {
se... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | e804f88d60071f0d89db85aaa4a073857904b545 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e804f88d60071f0d89db85aaa4a073857904b545/tokio/src/sync/rwlock.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:16 | /// *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()
}
}
/// Consumes the lock, returning the underlying data.
pub fn into_inner(self) -> T
wher... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | e804f88d60071f0d89db85aaa4a073857904b545 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e804f88d60071f0d89db85aaa4a073857904b545/tokio/src/sync/rwlock.rs | 601 | 655 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:17 | 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 | e804f88d60071f0d89db85aaa4a073857904b545 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e804f88d60071f0d89db85aaa4a073857904b545/tokio/src/sync/rwlock.rs | 641 | 655 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:9 | /// let guard = lock.write().await;
/// let mut guard = RwLockWriteGuard::try_map(guard, |f| Some(&mut f.0)).expect("should not fail");
/// *guard = 2;
/// }
///
/// assert_eq!(Foo(2), *lock.read().await);
/// # }
/// ```
#[inline]
pub fn try_map<F, U: ?Sized>(mut this: S... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 0f70530ee7cda68b68f2f8131b5866cfa937ee1f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0f70530ee7cda68b68f2f8131b5866cfa937ee1f/tokio/src/sync/rwlock.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:10 | /// # 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 handle = tokio::spawn(async move {
/// ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 0f70530ee7cda68b68f2f8131b5866cfa937ee1f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0f70530ee7cda68b68f2f8131b5866cfa937ee1f/tokio/src/sync/rwlock.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:11 | impl<'a, T: ?Sized> fmt::Debug for RwLockWriteGuard<'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 RwLockWriteGuard<'a, T>
where
T: fmt::Display,
{
fn fmt(&self, f: &mut fmt::Forma... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 0f70530ee7cda68b68f2f8131b5866cfa937ee1f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0f70530ee7cda68b68f2f8131b5866cfa937ee1f/tokio/src/sync/rwlock.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:12 | check_send::<RwLockWriteGuard<'_, u32>>();
check_sync::<RwLockWriteGuard<'_, u32>>();
check_unpin::<RwLockWriteGuard<'_, u32>>();
let rwlock = RwLock::new(0);
check_send_sync_val(rwlock.read());
check_send_sync_val(rwlock.write());
}
// As long as T: Send + Sync, it's fine to send and share RwLock... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 0f70530ee7cda68b68f2f8131b5866cfa937ee1f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0f70530ee7cda68b68f2f8131b5866cfa937ee1f/tokio/src/sync/rwlock.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:13 | {
RwLock {
c: UnsafeCell::new(value),
s: Semaphore::new(MAX_READS),
}
}
/// Creates a new instance of an `RwLock<T>` which is unlocked.
///
/// # Examples
///
/// ```
/// use tokio::sync::RwLock;
///
/// static LOCK: RwLock<i32> = RwLock::cons... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 0f70530ee7cda68b68f2f8131b5866cfa937ee1f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0f70530ee7cda68b68f2f8131b5866cfa937ee1f/tokio/src/sync/rwlock.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:14 | ///
/// #[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::spawn(async move {
/// // While main has an active read lock, ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 0f70530ee7cda68b68f2f8131b5866cfa937ee1f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0f70530ee7cda68b68f2f8131b5866cfa937ee1f/tokio/src/sync/rwlock.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:15 | ///
/// # Examples
///
/// ```
/// use tokio::sync::RwLock;
///
/// #[tokio::main]
/// async fn main() {
/// let lock = RwLock::new(1);
///
/// let mut n = lock.write().await;
/// *n = 2;
///}
/// ```
pub async fn write(&self) -> RwLockWriteGuard<'_, T> {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 0f70530ee7cda68b68f2f8131b5866cfa937ee1f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0f70530ee7cda68b68f2f8131b5866cfa937ee1f/tokio/src/sync/rwlock.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:16 | /// 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()
}
}
/// Consumes the lock, returning the underlying data.
p... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 0f70530ee7cda68b68f2f8131b5866cfa937ee1f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0f70530ee7cda68b68f2f8131b5866cfa937ee1f/tokio/src/sync/rwlock.rs | 601 | 656 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:17 | }
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 | 0f70530ee7cda68b68f2f8131b5866cfa937ee1f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0f70530ee7cda68b68f2f8131b5866cfa937ee1f/tokio/src/sync/rwlock.rs | 641 | 656 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:15 | ///
/// # Examples
///
/// ```
/// use tokio::sync::RwLock;
///
/// #[tokio::main]
/// async fn main() {
/// let lock = RwLock::new(1);
///
/// let mut n = lock.write().await;
/// *n = 2;
///}
/// ```
pub async fn write(&self) -> RwLockWriteGuard<'_, T> {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 8d2e3bc575f51815ae7319f1e43fe6c7d664e6e4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8d2e3bc575f51815ae7319f1e43fe6c7d664e6e4/tokio/src/sync/rwlock.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:16 | unsafe { &*self.data }
}
}
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 }
}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | 8d2e3bc575f51815ae7319f1e43fe6c7d664e6e4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8d2e3bc575f51815ae7319f1e43fe6c7d664e6e4/tokio/src/sync/rwlock.rs | 601 | 632 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:12 | check_send::<RwLockWriteGuard<'_, u32>>();
check_sync::<RwLockWriteGuard<'_, u32>>();
check_unpin::<RwLockWriteGuard<'_, u32>>();
let rwlock = RwLock::new(0);
check_send_sync_val(rwlock.read());
check_send_sync_val(rwlock.write());
}
// As long as T: Send + Sync, it's fine to send and share RwLock... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | c5a9ede157691ac5ca15283735bd666c6b016188 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c5a9ede157691ac5ca15283735bd666c6b016188/tokio/src/sync/rwlock.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:13 | {
RwLock {
c: UnsafeCell::new(value),
s: Semaphore::new(MAX_READS),
}
}
/// 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 more writers ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | c5a9ede157691ac5ca15283735bd666c6b016188 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c5a9ede157691ac5ca15283735bd666c6b016188/tokio/src/sync/rwlock.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:14 | // The semaphore was closed. but, we never explicitly close it, and we have a
// handle to it through the Arc, which means that this can never happen.
unreachable!()
});
RwLockReadGuard {
s: &self.s,
data: self.c.get(),
marker: marker::PhantomD... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | c5a9ede157691ac5ca15283735bd666c6b016188 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c5a9ede157691ac5ca15283735bd666c6b016188/tokio/src/sync/rwlock.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:15 | s: &self.s,
data: self.c.get(),
marker: marker::PhantomData,
}
}
/// Consumes the lock, returning the underlying data.
pub fn into_inner(self) -> T
where
T: Sized,
{
self.c.into_inner()
}
}
impl<T: ?Sized> ops::Deref for RwLockReadGuard<'_, T> {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | c5a9ede157691ac5ca15283735bd666c6b016188 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c5a9ede157691ac5ca15283735bd666c6b016188/tokio/src/sync/rwlock.rs | 561 | 611 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:16 | }
}
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 | c5a9ede157691ac5ca15283735bd666c6b016188 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c5a9ede157691ac5ca15283735bd666c6b016188/tokio/src/sync/rwlock.rs | 601 | 611 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:9 | /// let guard = lock.write().await;
/// let mut guard = RwLockWriteGuard::try_map(guard, |f| Some(&mut f.0)).expect("should not fail");
/// *guard = 2;
/// }
///
/// assert_eq!(Foo(2), *lock.read().await);
/// # }
/// ```
#[inline]
pub fn try_map<F, U: ?Sized>(mut this: S... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | ce0af8f7a188c9b8b8b4dcc3847674fd0afbe769 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ce0af8f7a188c9b8b8b4dcc3847674fd0afbe769/tokio/src/sync/rwlock.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:10 | {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(&**self, f)
}
}
impl<'a, T: ?Sized> Drop for RwLockWriteGuard<'a, T> {
fn drop(&mut self) {
self.s.release(MAX_READS);
}
}
#[test]
#[cfg(not(loom))]
fn bounds() {
fn check_send<T: Send>() {}
fn check... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | ce0af8f7a188c9b8b8b4dcc3847674fd0afbe769 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ce0af8f7a188c9b8b8b4dcc3847674fd0afbe769/tokio/src/sync/rwlock.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:11 | // RwLock<T>.
unsafe impl<T> Send for RwLock<T> where T: ?Sized + Send {}
unsafe impl<T> Sync for RwLock<T> where T: ?Sized + Send + Sync {}
// NB: These impls need to be explicit since we're storing a raw pointer.
// Safety: Stores a raw pointer to `T`, so if `T` is `Sync`, the lock guard over
// `T` is `Send`.
unsafe... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | ce0af8f7a188c9b8b8b4dcc3847674fd0afbe769 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ce0af8f7a188c9b8b8b4dcc3847674fd0afbe769/tokio/src/sync/rwlock.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:13 | /// to yield until the lock has been acquired.
///
/// This function will not return while other writers or other readers
/// currently have access to the lock.
///
/// Returns an RAII guard which will drop the write access of this rwlock
/// when dropped.
///
/// # Examples
///
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | ce0af8f7a188c9b8b8b4dcc3847674fd0afbe769 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ce0af8f7a188c9b8b8b4dcc3847674fd0afbe769/tokio/src/sync/rwlock.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:14 | }
}
impl<T: ?Sized> ops::Deref for RwLockReadGuard<'_, T> {
type Target = T;
fn deref(&self) -> &T {
unsafe { &*self.data }
}
}
impl<T: ?Sized> ops::Deref for RwLockWriteGuard<'_, T> {
type Target = T;
fn deref(&self) -> &T {
unsafe { &*self.data }
}
}
impl<T: ?Sized> ops::D... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | ce0af8f7a188c9b8b8b4dcc3847674fd0afbe769 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ce0af8f7a188c9b8b8b4dcc3847674fd0afbe769/tokio/src/sync/rwlock.rs | 521 | 559 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:3 | ///
/// This structure is created by the [`read`] method on
/// [`RwLock`].
///
/// [`read`]: method@RwLock::read
#[derive(Debug)]
pub struct RwLockReadGuard<'a, T: ?Sized> {
permit: ReleasingPermit<'a, T>,
lock: &'a RwLock<T>,
}
/// RAII structure used to release the exclusive write access of a lock when
/// ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | c344aac9252c34fcce196200a99529734b5cb9e8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c344aac9252c34fcce196200a99529734b5cb9e8/tokio/src/sync/rwlock.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:4 | }
impl<T: ?Sized> Drop for ReleasingPermit<'_, T> {
fn drop(&mut self) {
self.lock.s.release(self.num_permits as usize);
}
}
#[test]
#[cfg(not(loom))]
fn bounds() {
fn check_send<T: Send>() {}
fn check_sync<T: Sync>() {}
fn check_unpin<T: Unpin>() {}
// This has to take a value, since ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | c344aac9252c34fcce196200a99529734b5cb9e8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c344aac9252c34fcce196200a99529734b5cb9e8/tokio/src/sync/rwlock.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:5 | impl<T: ?Sized> RwLock<T> {
/// Creates a new instance of an `RwLock<T>` which is unlocked.
///
/// # Examples
///
/// ```
/// use tokio::sync::RwLock;
///
/// let lock = RwLock::new(5);
/// ```
pub fn new(value: T) -> RwLock<T>
where
T: Sized,
{
RwLock {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | c344aac9252c34fcce196200a99529734b5cb9e8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c344aac9252c34fcce196200a99529734b5cb9e8/tokio/src/sync/rwlock.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:6 | ///
/// tokio::spawn(async move {
/// // While main has an active read lock, we acquire one too.
/// let r = c_lock.read().await;
/// assert_eq!(*r, 1);
/// }).await.expect("The spawned task has paniced");
///
/// // Drop the guard after the spawned task f... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | c344aac9252c34fcce196200a99529734b5cb9e8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c344aac9252c34fcce196200a99529734b5cb9e8/tokio/src/sync/rwlock.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:7 | ///}
/// ```
pub async fn write(&self) -> RwLockWriteGuard<'_, T> {
let permit = ReleasingPermit::acquire(self, MAX_READS as u16)
.await
.unwrap_or_else(|_| {
// The semaphore was closed. but, we never explicitly close it, and we have a
// handle t... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | c344aac9252c34fcce196200a99529734b5cb9e8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c344aac9252c34fcce196200a99529734b5cb9e8/tokio/src/sync/rwlock.rs | 241 | 299 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:8 | fn deref_mut(&mut self) -> &mut T {
unsafe { &mut *self.lock.c.get() }
}
}
impl<T> From<T> for RwLock<T> {
fn from(s: T) -> Self {
Self::new(s)
}
}
impl<T> 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 | c344aac9252c34fcce196200a99529734b5cb9e8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c344aac9252c34fcce196200a99529734b5cb9e8/tokio/src/sync/rwlock.rs | 281 | 299 |
tokio-rs/tokio:tokio/src/sync/rwlock.rs:3 | ///
/// This structure is created by the [`read`] method on
/// [`RwLock`].
///
/// [`read`]: method@RwLock::read
#[derive(Debug)]
pub struct RwLockReadGuard<'a, T: ?Sized> {
permit: ReleasingPermit<'a, T>,
lock: &'a RwLock<T>,
}
/// RAII structure used to release the exclusive write access of a lock when
/// ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/rwlock.rs | MIT | d2f81b506a469481ab0b62aaeaf48fc8c60e4c66 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d2f81b506a469481ab0b62aaeaf48fc8c60e4c66/tokio/src/sync/rwlock.rs | 81 | 140 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.