id stringlengths 22 133 | text stringlengths 40 40.2k | arch stringclasses 1
value | syntax stringclasses 1
value | kind stringclasses 4
values | repo stringclasses 27
values | path stringlengths 5 116 | license stringclasses 6
values | commit stringlengths 40 40 | source_host stringclasses 1
value | category stringclasses 16
values | source_url stringlengths 85 196 | line_start int64 1 4.28k | line_end int64 4 4.31k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
tokio-rs/tokio:tokio/src/sync/mutex.rs:3 | Self {
c: UnsafeCell::new(t),
s: semaphore::Semaphore::new(1),
}
}
/// A future that resolves on acquiring the lock and returns the `MutexGuard`.
pub async fn lock(&self) -> MutexGuard<'_, T> {
let mut permit = semaphore::Permit::new();
poll_fn(|cx| permit.po... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/mutex.rs | MIT | 8a7e57786a5dca139f5b4261685e22991ded0859 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8a7e57786a5dca139f5b4261685e22991ded0859/tokio/src/sync/mutex.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/sync/notify.rs:1 | // Allow `unreachable_pub` warnings when sync is not enabled
// due to the usage of `Notify` within the `rt` feature set.
// When this module is compiled with `sync` enabled we will warn on
// this lint. When `rt` is enabled we use `pub(crate)` which
// triggers this warning but it is safe to ignore in this case.
#![cf... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/notify.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/sync/notify.rs:6 | #[derive(Debug)]
pub struct Notify {
// `state` uses 2 bits to store one of `EMPTY`,
// `WAITING` or `NOTIFIED`. The rest of the bits
// are used to store the number of times `notify_waiters`
// was called.
//
// Throughout the code there are two assumptions:
// - state can be transitioned *... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/notify.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/sync/notify.rs:7 | Waiter {
pointers: linked_list::Pointers::new(),
waker: UnsafeCell::new(None),
notification: AtomicNotification::none(),
_p: PhantomPinned,
}
}
}
generate_addr_of_methods! {
impl<> Waiter {
unsafe fn addr_of_pointers(self: NonNull<Self>) -> NonNul... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/notify.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/sync/notify.rs:8 | /// Store-release a notification.
/// This method should be called exactly once.
fn store_release(&self, notification: Notification) {
let data: usize = match notification {
Notification::All => NOTIFICATION_ALL,
Notification::One(NotifyOneStrategy::Fifo) => NOTIFICATION_ONE,
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/notify.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/sync/notify.rs:9 | enum Notification {
One(NotifyOneStrategy),
All,
}
/// List used in `Notify::notify_waiters`. It wraps a guarded linked list
/// and gates the access to it on `notify.waiters` mutex. It also empties
/// the list on drop.
struct NotifyWaitersList<'a> {
list: GuardedWaitList,
is_empty: bool,
notify: ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/notify.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/sync/notify.rs:10 | }
impl Drop for NotifyWaitersList<'_> {
fn drop(&mut self) {
// If the list is not empty, we unlink all waiters from it.
// We do not wake the waiters to avoid double panics.
if !self.is_empty {
let _lock_guard = self.notify.waiters.lock();
while let Some(waiter) = s... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/notify.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/sync/notify.rs:11 | /// Future returned from [`Notify::notified_owned()`].
///
/// This future is fused, so once it has completed, any future calls to poll
/// will immediately return `Poll::Ready`.
#[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct OwnedNotified {
/// The `Notify` being re... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/notify.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/sync/notify.rs:12 | const STATE_MASK: usize = (1 << NOTIFY_WAITERS_SHIFT) - 1;
const NOTIFY_WAITERS_CALLS_MASK: usize = !STATE_MASK;
/// Initial "idle" state.
const EMPTY: usize = 0;
/// One or more threads are currently waiting to be notified.
const WAITING: usize = 1;
/// Pending notification.
const NOTIFIED: usize = 2;
fn set_state... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/notify.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/sync/notify.rs:15 | /// println!("sending notification");
/// notify.notify_one();
/// # }
/// ```
pub fn notified(&self) -> Notified<'_> {
// we load the number of times notify_waiters
// was called and store that in the future.
let state = self.state.load(SeqCst);
Notified {
no... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/notify.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/sync/notify.rs:17 | /// use tokio::sync::Notify;
/// use std::sync::Arc;
///
/// # #[tokio::main(flavor = "current_thread")]
/// # async fn main() {
/// let notify = Arc::new(Notify::new());
/// let notify2 = notify.clone();
///
/// tokio::spawn(async move {
/// notify2.notified().await;
/// ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/notify.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/sync/notify.rs:18 | // If the state is `EMPTY`, transition to `NOTIFIED` and return.
while let EMPTY | NOTIFIED = get_state(curr) {
// The compare-exchange from `NOTIFIED` -> `NOTIFIED` is intended. A
// happens-before synchronization must happen between this atomic
// operation and a task calli... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/notify.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/sync/notify.rs:19 | /// ```
/// use tokio::sync::Notify;
/// use std::sync::Arc;
///
/// # #[tokio::main(flavor = "current_thread")]
/// # async fn main() {
/// let notify = Arc::new(Notify::new());
/// let notify2 = notify.clone();
///
/// let notified1 = notify.notified();
/// let notified2 = noti... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/notify.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/sync/notify.rs:20 | let new_state = set_state(inc_num_notify_waiters_calls(curr), EMPTY);
self.state.store(new_state, SeqCst);
// It is critical for `GuardedLinkedList` safety that the guard node is
// pinned in memory and is not dropped until the guarded list is dropped.
let guard = Waiter::new();
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/notify.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/sync/notify.rs:21 | }
// Release the lock before notifying.
drop(waiters);
// One of the wakers may panic, but the remaining waiters will still
// be unlinked from the list in `NotifyWaitersList` destructor.
wakers.wake_all();
// Acquire the lock again.
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/notify.rs | 801 | 860 |
tokio-rs/tokio:tokio/src/sync/notify.rs:22 | impl UnwindSafe for Notify {}
impl RefUnwindSafe for Notify {}
fn notify_locked(
waiters: &mut WaitList,
state: &AtomicUsize,
curr: usize,
strategy: NotifyOneStrategy,
) -> Option<Waker> {
match get_state(curr) {
EMPTY | NOTIFIED => {
let res = state.compare_exchange(curr, set_s... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/notify.rs | 841 | 900 |
tokio-rs/tokio:tokio/src/sync/notify.rs:26 | /// }
/// ```
///
/// [`notify_one`]: Notify::notify_one()
/// [`notify_waiters`]: Notify::notify_waiters()
pub fn enable(self: Pin<&mut Self>) -> bool {
self.poll_notified(None).is_ready()
}
fn project(self: Pin<&mut Self>) -> NotifiedProject<'_> {
unsafe {
// S... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/notify.rs | 1,001 | 1,060 |
tokio-rs/tokio:tokio/src/sync/notify.rs:27 | impl Drop for Notified<'_> {
fn drop(&mut self) {
// Safety: The type only transitions to a "Waiting" state when pinned.
unsafe { Pin::new_unchecked(self) }
.project()
.drop_notified();
}
}
// ===== impl OwnedNotified =====
impl OwnedNotified {
/// Adds this future ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/notify.rs | 1,041 | 1,100 |
tokio-rs/tokio:tokio/src/sync/notify.rs:28 | }
fn poll_notified(self: Pin<&mut Self>, waker: Option<&Waker>) -> Poll<()> {
self.project().poll_notified(waker)
}
}
impl Future for OwnedNotified {
type Output = ();
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()> {
self.poll_notified(Some(cx.waker()))
}
}
impl ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/notify.rs | 1,081 | 1,140 |
tokio-rs/tokio:tokio/src/sync/notify.rs:29 | // Check if `notify_waiters` was called before attempting to acquire
// the `NOTIFIED` state. If a broadcast occurred, we will be woken by it,
// leaving the `notify_one` permit for other waiters.
if get_num_notify_waiters_calls(curr) != *notify_waiters_calls ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/notify.rs | 1,121 | 1,180 |
tokio-rs/tokio:tokio/src/sync/notify.rs:30 | // Transition the state to WAITING.
loop {
match get_state(curr) {
EMPTY => {
// Transition to WAITING
let res = notify.state.compare_exchange(
set_... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/notify.rs | 1,161 | 1,220 |
tokio-rs/tokio:tokio/src/sync/notify.rs:31 | }
_ => unreachable!(),
}
}
let mut old_waker = None;
if waker.is_some() {
// Safety: called while locked.
//
// The use of `old_waiter`... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/notify.rs | 1,201 | 1,260 |
tokio-rs/tokio:tokio/src/sync/notify.rs:32 | return Poll::Ready(());
}
// Our waiter was not notified, implying it is still stored in a waiter
// list (guarded by `notify.waiters`). In order to access the waker
// fields, we must acquire the lock.
let mut old_wak... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/notify.rs | 1,241 | 1,300 |
tokio-rs/tokio:tokio/src/sync/notify.rs:33 | old_waker = unsafe { waiter.waker.with_mut(|waker| (*waker).take()) };
// Safety: we hold the lock, so we have an exclusive access to the list.
// The list is used in `notify_waiters`, so it must be guarded.
unsafe { waiters.remove(NonNull::from(w... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/notify.rs | 1,281 | 1,340 |
tokio-rs/tokio:tokio/src/sync/notify.rs:34 | State::Done => {
#[cfg(feature = "taskdump")]
if let Some(_waker) = waker {
std::task::ready!(crate::trace::trace_leaf());
}
return Poll::Ready(());
}
}
}
}
fn drop_notifi... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/notify.rs | 1,321 | 1,380 |
tokio-rs/tokio:tokio/src/sync/notify.rs:35 | }
// See if the node was notified but not received. In this case, if
// the notification was triggered via `notify_one`, it must be sent
// to the next waiter.
if let Some(Notification::One(strategy)) = notification {
if let Some(waker) =
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/notify.rs | 1,361 | 1,415 |
tokio-rs/tokio:tokio/src/sync/notify.rs:36 | /// waiters list.
///
/// While this guard is held, the `Notify` instance's waiter list is locked.
pub(crate) struct NotifyGuard<'a> {
guarded_notify: &'a Notify,
guarded_waiters: crate::loom::sync::MutexGuard<'a, WaitList>,
current_state: usize,
}
impl NotifyGuard<'_> {
pub(crate) fn notify_waiters(se... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/notify.rs | 1,401 | 1,415 |
tokio-rs/tokio:tokio/src/sync/notify.rs:31 | }
_ => unreachable!(),
}
}
let mut old_waker = None;
if waker.is_some() {
// Safety: called while locked.
//
// The use of `old_waiter`... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 9f132172dbb00b1f6b6bda64bb9b194382079499 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/9f132172dbb00b1f6b6bda64bb9b194382079499/tokio/src/sync/notify.rs | 1,201 | 1,260 |
tokio-rs/tokio:tokio/src/sync/notify.rs:32 | *state = State::Done;
return Poll::Ready(());
}
// Our waiter was not notified, implying it is still stored in a waiter
// list (guarded by `notify.waiters`). In order to access the waker
// fields, we must acquire ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 9f132172dbb00b1f6b6bda64bb9b194382079499 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/9f132172dbb00b1f6b6bda64bb9b194382079499/tokio/src/sync/notify.rs | 1,241 | 1,300 |
tokio-rs/tokio:tokio/src/sync/notify.rs:33 | // Safety: we hold the lock, so we can modify the waker.
old_waker = unsafe { waiter.waker.with_mut(|waker| (*waker).take()) };
// Safety: we hold the lock, so we have an exclusive access to the list.
// The list is used in `notify_waiters`, so it... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 9f132172dbb00b1f6b6bda64bb9b194382079499 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/9f132172dbb00b1f6b6bda64bb9b194382079499/tokio/src/sync/notify.rs | 1,281 | 1,340 |
tokio-rs/tokio:tokio/src/sync/notify.rs:34 | }
State::Done => {
#[cfg(feature = "taskdump")]
if let Some(waker) = waker {
let mut ctx = Context::from_waker(waker);
std::task::ready!(crate::trace::trace_leaf(&mut ctx));
}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 9f132172dbb00b1f6b6bda64bb9b194382079499 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/9f132172dbb00b1f6b6bda64bb9b194382079499/tokio/src/sync/notify.rs | 1,321 | 1,380 |
tokio-rs/tokio:tokio/src/sync/notify.rs:35 | notify_state = set_state(notify_state, EMPTY);
notify.state.store(notify_state, SeqCst);
}
// See if the node was notified but not received. In this case, if
// the notification was triggered via `notify_one`, it must be sent
// to the next waiter.
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 9f132172dbb00b1f6b6bda64bb9b194382079499 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/9f132172dbb00b1f6b6bda64bb9b194382079499/tokio/src/sync/notify.rs | 1,361 | 1,417 |
tokio-rs/tokio:tokio/src/sync/notify.rs:36 | /// A guard that provides exclusive access to a `Notify`'s internal
/// waiters list.
///
/// While this guard is held, the `Notify` instance's waiter list is locked.
pub(crate) struct NotifyGuard<'a> {
guarded_notify: &'a Notify,
guarded_waiters: crate::loom::sync::MutexGuard<'a, WaitList>,
current_state: ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 9f132172dbb00b1f6b6bda64bb9b194382079499 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/9f132172dbb00b1f6b6bda64bb9b194382079499/tokio/src/sync/notify.rs | 1,401 | 1,417 |
tokio-rs/tokio:tokio/src/sync/notify.rs:28 | }
fn poll_notified(self: Pin<&mut Self>, waker: Option<&Waker>) -> Poll<()> {
self.project().poll_notified(waker)
}
}
impl Future for OwnedNotified {
type Output = ();
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()> {
self.poll_notified(Some(cx.waker()))
}
}
impl ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 665f08b5ad15485e8dcd6c3ec5ad1bda03a2a68d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/665f08b5ad15485e8dcd6c3ec5ad1bda03a2a68d/tokio/src/sync/notify.rs | 1,081 | 1,140 |
tokio-rs/tokio:tokio/src/sync/notify.rs:29 | // Optimistically try acquiring a pending notification
let res = notify.state.compare_exchange(
set_state(curr, NOTIFIED),
set_state(curr, EMPTY),
SeqCst,
SeqCst,
);
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 665f08b5ad15485e8dcd6c3ec5ad1bda03a2a68d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/665f08b5ad15485e8dcd6c3ec5ad1bda03a2a68d/tokio/src/sync/notify.rs | 1,121 | 1,180 |
tokio-rs/tokio:tokio/src/sync/notify.rs:30 | SeqCst,
SeqCst,
);
if let Err(actual) = res {
assert_eq!(get_state(actual), NOTIFIED);
curr = actual;
} else {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 665f08b5ad15485e8dcd6c3ec5ad1bda03a2a68d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/665f08b5ad15485e8dcd6c3ec5ad1bda03a2a68d/tokio/src/sync/notify.rs | 1,161 | 1,220 |
tokio-rs/tokio:tokio/src/sync/notify.rs:31 | //
// The use of `old_waiter` here is not necessary, as the field is always
// None when we reach this line.
unsafe {
old_waker =
waiter.waker.with_mut(|v| std::mem::replace(&mut *v, waker... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 665f08b5ad15485e8dcd6c3ec5ad1bda03a2a68d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/665f08b5ad15485e8dcd6c3ec5ad1bda03a2a68d/tokio/src/sync/notify.rs | 1,201 | 1,260 |
tokio-rs/tokio:tokio/src/sync/notify.rs:32 | let mut old_waker = None;
let mut waiters = notify.waiters.lock();
// We hold the lock and notifications are set only with the lock held,
// so this can be relaxed, because the happens-before relationship is
// established through the mute... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 665f08b5ad15485e8dcd6c3ec5ad1bda03a2a68d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/665f08b5ad15485e8dcd6c3ec5ad1bda03a2a68d/tokio/src/sync/notify.rs | 1,241 | 1,300 |
tokio-rs/tokio:tokio/src/sync/notify.rs:33 | } else {
// Safety: we hold the lock, so we can modify the waker.
unsafe {
waiter.waker.with_mut(|v| {
if let Some(waker) = waker {
let should_update = match &*v {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 665f08b5ad15485e8dcd6c3ec5ad1bda03a2a68d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/665f08b5ad15485e8dcd6c3ec5ad1bda03a2a68d/tokio/src/sync/notify.rs | 1,281 | 1,340 |
tokio-rs/tokio:tokio/src/sync/notify.rs:34 | }
}
}
}
fn drop_notified(self) {
let NotifiedProject {
notify,
state,
waiter,
..
} = self;
// This is where we ensure safety. The `Notified` value is being
// dropped, which means we must ensure that the waiter... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 665f08b5ad15485e8dcd6c3ec5ad1bda03a2a68d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/665f08b5ad15485e8dcd6c3ec5ad1bda03a2a68d/tokio/src/sync/notify.rs | 1,321 | 1,380 |
tokio-rs/tokio:tokio/src/sync/notify.rs:35 | if let Some(waker) =
notify_locked(&mut waiters, ¬ify.state, notify_state, strategy)
{
drop(waiters);
waker.wake();
}
}
}
}
}
/// # Safety
///
/// `Waiter` is forced to be !Unpin.
unsafe impl linked_l... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 665f08b5ad15485e8dcd6c3ec5ad1bda03a2a68d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/665f08b5ad15485e8dcd6c3ec5ad1bda03a2a68d/tokio/src/sync/notify.rs | 1,361 | 1,409 |
tokio-rs/tokio:tokio/src/sync/notify.rs:35 | if let Some(waker) =
notify_locked(&mut waiters, ¬ify.state, notify_state, strategy)
{
drop(waiters);
waker.wake();
}
}
}
}
}
/// # Safety
///
/// `Waiter` is forced to be !Unpin.
unsafe impl linked_l... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | d1f1499f630c34c1d319acdc2cc86d7a1008c4b4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d1f1499f630c34c1d319acdc2cc86d7a1008c4b4/tokio/src/sync/notify.rs | 1,361 | 1,409 |
tokio-rs/tokio:tokio/src/sync/notify.rs:31 | //
// The use of `old_waiter` here is not necessary, as the field is always
// None when we reach this line.
unsafe {
old_waker =
waiter.waker.with_mut(|v| std::mem::replace(&mut *v, waker... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 8ccf2fb92e7568bf16318dc8f3205cad14a9bc5d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8ccf2fb92e7568bf16318dc8f3205cad14a9bc5d/tokio/src/sync/notify.rs | 1,201 | 1,260 |
tokio-rs/tokio:tokio/src/sync/notify.rs:33 | } else {
// Safety: we hold the lock, so we can modify the waker.
unsafe {
waiter.waker.with_mut(|v| {
if let Some(waker) = waker {
let should_update = match &*v {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 8ccf2fb92e7568bf16318dc8f3205cad14a9bc5d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8ccf2fb92e7568bf16318dc8f3205cad14a9bc5d/tokio/src/sync/notify.rs | 1,281 | 1,340 |
tokio-rs/tokio:tokio/src/sync/notify.rs:1 | // Allow `unreachable_pub` warnings when sync is not enabled
// due to the usage of `Notify` within the `rt` feature set.
// When this module is compiled with `sync` enabled we will warn on
// this lint. When `rt` is enabled we use `pub(crate)` which
// triggers this warning but it is safe to ignore in this case.
#![cf... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 37ca2f049c552fde50a2535de6dfc61ee6e96eed | github | async-runtime | https://github.com/tokio-rs/tokio/blob/37ca2f049c552fde50a2535de6dfc61ee6e96eed/tokio/src/sync/notify.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/sync/notify.rs:15 | /// println!("sending notification");
/// notify.notify_one();
/// }
/// ```
pub fn notified(&self) -> Notified<'_> {
// we load the number of times notify_waiters
// was called and store that in the future.
let state = self.state.load(SeqCst);
Notified {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 37ca2f049c552fde50a2535de6dfc61ee6e96eed | github | async-runtime | https://github.com/tokio-rs/tokio/blob/37ca2f049c552fde50a2535de6dfc61ee6e96eed/tokio/src/sync/notify.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/sync/notify.rs:17 | /// use tokio::sync::Notify;
/// use std::sync::Arc;
///
/// #[tokio::main]
/// async fn main() {
/// let notify = Arc::new(Notify::new());
/// let notify2 = notify.clone();
///
/// tokio::spawn(async move {
/// notify2.notified().await;
/// println!("... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 37ca2f049c552fde50a2535de6dfc61ee6e96eed | github | async-runtime | https://github.com/tokio-rs/tokio/blob/37ca2f049c552fde50a2535de6dfc61ee6e96eed/tokio/src/sync/notify.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/sync/notify.rs:18 | // If the state is `EMPTY`, transition to `NOTIFIED` and return.
while let EMPTY | NOTIFIED = get_state(curr) {
// The compare-exchange from `NOTIFIED` -> `NOTIFIED` is intended. A
// happens-before synchronization must happen between this atomic
// operation and a task calli... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 37ca2f049c552fde50a2535de6dfc61ee6e96eed | github | async-runtime | https://github.com/tokio-rs/tokio/blob/37ca2f049c552fde50a2535de6dfc61ee6e96eed/tokio/src/sync/notify.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/sync/notify.rs:19 | /// ```
/// use tokio::sync::Notify;
/// use std::sync::Arc;
///
/// #[tokio::main]
/// async fn main() {
/// let notify = Arc::new(Notify::new());
/// let notify2 = notify.clone();
///
/// let notified1 = notify.notified();
/// let notified2 = notify.notified();
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 37ca2f049c552fde50a2535de6dfc61ee6e96eed | github | async-runtime | https://github.com/tokio-rs/tokio/blob/37ca2f049c552fde50a2535de6dfc61ee6e96eed/tokio/src/sync/notify.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/sync/notify.rs:19 | /// ```
/// use tokio::sync::Notify;
/// use std::sync::Arc;
///
/// #[tokio::main]
/// async fn main() {
/// let notify = Arc::new(Notify::new());
/// let notify2 = notify.clone();
///
/// let notified1 = notify.notified();
/// let notified2 = notify.notified();
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | d545aa2601e3008ce49c8c0191b0f172ce577452 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d545aa2601e3008ce49c8c0191b0f172ce577452/tokio/src/sync/notify.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/sync/notify.rs:20 | // It is critical for `GuardedLinkedList` safety that the guard node is
// pinned in memory and is not dropped until the guarded list is dropped.
let guard = Waiter::new();
pin!(guard);
// We move all waiters to a secondary list. It uses a `GuardedLinkedList`
// underneath to al... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | d545aa2601e3008ce49c8c0191b0f172ce577452 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d545aa2601e3008ce49c8c0191b0f172ce577452/tokio/src/sync/notify.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/sync/notify.rs:21 | // Release the lock before notifying.
drop(waiters);
// One of the wakers may panic, but the remaining waiters will still
// be unlinked from the list in `NotifyWaitersList` destructor.
wakers.wake_all();
// Acquire the lock again.
waiters = self... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | d545aa2601e3008ce49c8c0191b0f172ce577452 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d545aa2601e3008ce49c8c0191b0f172ce577452/tokio/src/sync/notify.rs | 801 | 860 |
tokio-rs/tokio:tokio/src/sync/notify.rs:22 | let actual_state = get_state(actual);
assert!(actual_state == EMPTY || actual_state == NOTIFIED);
state.store(set_state(actual, NOTIFIED), SeqCst);
None
}
}
}
WAITING => {
// At this point, it is guarante... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | d545aa2601e3008ce49c8c0191b0f172ce577452 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d545aa2601e3008ce49c8c0191b0f172ce577452/tokio/src/sync/notify.rs | 841 | 900 |
tokio-rs/tokio:tokio/src/sync/notify.rs:25 | /// pub async fn recv(&self) -> T {
/// let future = self.notify_on_sent.notified();
/// tokio::pin!(future);
///
/// loop {
/// // Make sure that no wakeup is lost if we get
/// // `None` from `try_recv`.
/// future.as_mut().en... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | d545aa2601e3008ce49c8c0191b0f172ce577452 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d545aa2601e3008ce49c8c0191b0f172ce577452/tokio/src/sync/notify.rs | 961 | 1,020 |
tokio-rs/tokio:tokio/src/sync/notify.rs:26 | let me = self.get_unchecked_mut();
NotifiedProject {
notify: me.notify,
state: &mut me.state,
notify_waiters_calls: &me.notify_waiters_calls,
waiter: &me.waiter,
}
}
}
fn poll_notified(self: Pin<&mut Self>, waker: O... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | d545aa2601e3008ce49c8c0191b0f172ce577452 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d545aa2601e3008ce49c8c0191b0f172ce577452/tokio/src/sync/notify.rs | 1,001 | 1,060 |
tokio-rs/tokio:tokio/src/sync/notify.rs:27 | ///
/// [`notify_one`]: Notify::notify_one()
pub fn enable(self: Pin<&mut Self>) -> bool {
self.poll_notified(None).is_ready()
}
/// A custom `project` implementation is used in place of `pin-project-lite`
/// as a custom drop implementation is needed.
fn project(self: Pin<&mut Self>) -... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | d545aa2601e3008ce49c8c0191b0f172ce577452 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d545aa2601e3008ce49c8c0191b0f172ce577452/tokio/src/sync/notify.rs | 1,041 | 1,100 |
tokio-rs/tokio:tokio/src/sync/notify.rs:28 | fn drop(&mut self) {
// Safety: The type only transitions to a "Waiting" state when pinned.
unsafe { Pin::new_unchecked(self) }
.project()
.drop_notified();
}
}
// ===== impl NotifiedProject =====
impl NotifiedProject<'_> {
fn poll_notified(self, waker: Option<&Waker>) ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | d545aa2601e3008ce49c8c0191b0f172ce577452 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d545aa2601e3008ce49c8c0191b0f172ce577452/tokio/src/sync/notify.rs | 1,081 | 1,140 |
tokio-rs/tokio:tokio/src/sync/notify.rs:29 | let waker = waker.cloned();
// Acquire the lock and attempt to transition to the waiting
// state.
let mut waiters = notify.waiters.lock();
// Reload the state with the lock held
let mut curr = notify.state.load(SeqCst... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | d545aa2601e3008ce49c8c0191b0f172ce577452 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d545aa2601e3008ce49c8c0191b0f172ce577452/tokio/src/sync/notify.rs | 1,121 | 1,180 |
tokio-rs/tokio:tokio/src/sync/notify.rs:30 | set_state(curr, EMPTY),
SeqCst,
SeqCst,
);
match res {
Ok(_) => {
// Acquired the notification
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | d545aa2601e3008ce49c8c0191b0f172ce577452 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d545aa2601e3008ce49c8c0191b0f172ce577452/tokio/src/sync/notify.rs | 1,161 | 1,220 |
tokio-rs/tokio:tokio/src/sync/notify.rs:31 | return Poll::Pending;
}
State::Waiting => {
#[cfg(tokio_taskdump)]
if let Some(waker) = waker {
let mut ctx = Context::from_waker(waker);
std::task::ready!(crate::trace::trace_leaf(&mut ctx));
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | d545aa2601e3008ce49c8c0191b0f172ce577452 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d545aa2601e3008ce49c8c0191b0f172ce577452/tokio/src/sync/notify.rs | 1,201 | 1,260 |
tokio-rs/tokio:tokio/src/sync/notify.rs:32 | *state = State::Done;
return Poll::Ready(());
}
// Load the state with the lock held.
let curr = notify.state.load(SeqCst);
if get_num_notify_waiters_calls(curr) != *notify_waiters_calls {
/... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | d545aa2601e3008ce49c8c0191b0f172ce577452 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d545aa2601e3008ce49c8c0191b0f172ce577452/tokio/src/sync/notify.rs | 1,241 | 1,300 |
tokio-rs/tokio:tokio/src/sync/notify.rs:33 | // Drop the old waker after releasing the lock.
drop(waiters);
drop(old_waker);
return Poll::Pending;
}
// Explicit drop of the lock to indicate the scope that the
// lock is held. Becau... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | d545aa2601e3008ce49c8c0191b0f172ce577452 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d545aa2601e3008ce49c8c0191b0f172ce577452/tokio/src/sync/notify.rs | 1,281 | 1,340 |
tokio-rs/tokio:tokio/src/sync/notify.rs:34 | if matches!(*state, State::Waiting) {
let mut waiters = notify.waiters.lock();
let mut notify_state = notify.state.load(SeqCst);
// We hold the lock, so this field is not concurrently accessed by
// `notify_*` functions and we can use the relaxed ordering.
le... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | d545aa2601e3008ce49c8c0191b0f172ce577452 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d545aa2601e3008ce49c8c0191b0f172ce577452/tokio/src/sync/notify.rs | 1,321 | 1,376 |
tokio-rs/tokio:tokio/src/sync/notify.rs:35 | type Target = Waiter;
fn as_raw(handle: &NonNull<Waiter>) -> NonNull<Waiter> {
*handle
}
unsafe fn from_raw(ptr: NonNull<Waiter>) -> NonNull<Waiter> {
ptr
}
unsafe fn pointers(target: NonNull<Waiter>) -> NonNull<linked_list::Pointers<Waiter>> {
Waiter::addr_of_pointers(tar... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | d545aa2601e3008ce49c8c0191b0f172ce577452 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d545aa2601e3008ce49c8c0191b0f172ce577452/tokio/src/sync/notify.rs | 1,361 | 1,376 |
tokio-rs/tokio:tokio/src/sync/notify.rs:1 | // Allow `unreachable_pub` warnings when sync is not enabled
// due to the usage of `Notify` within the `rt` feature set.
// When this module is compiled with `sync` enabled we will warn on
// this lint. When `rt` is enabled we use `pub(crate)` which
// triggers this warning but it is safe to ignore in this case.
#![cf... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | a7896d07f1d3093524c7a190b57570dad3767c7a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a7896d07f1d3093524c7a190b57570dad3767c7a/tokio/src/sync/notify.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/sync/notify.rs:6 | pub struct Notify {
// `state` uses 2 bits to store one of `EMPTY`,
// `WAITING` or `NOTIFIED`. The rest of the bits
// are used to store the number of times `notify_waiters`
// was called.
//
// Throughout the code there are two assumptions:
// - state can be transitioned *from* `WAITING` o... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | a7896d07f1d3093524c7a190b57570dad3767c7a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a7896d07f1d3093524c7a190b57570dad3767c7a/tokio/src/sync/notify.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/sync/notify.rs:7 | pointers: linked_list::Pointers::new(),
waker: UnsafeCell::new(None),
notification: AtomicNotification::none(),
_p: PhantomPinned,
}
}
}
generate_addr_of_methods! {
impl<> Waiter {
unsafe fn addr_of_pointers(self: NonNull<Self>) -> NonNull<linked_list::Pointe... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | a7896d07f1d3093524c7a190b57570dad3767c7a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a7896d07f1d3093524c7a190b57570dad3767c7a/tokio/src/sync/notify.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/sync/notify.rs:8 | /// This method should be called exactly once.
fn store_release(&self, notification: Notification) {
let data: usize = match notification {
Notification::All => NOTIFICATION_ALL,
Notification::One(NotifyOneStrategy::Fifo) => NOTIFICATION_ONE,
Notification::One(NotifyOneSt... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | a7896d07f1d3093524c7a190b57570dad3767c7a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a7896d07f1d3093524c7a190b57570dad3767c7a/tokio/src/sync/notify.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/sync/notify.rs:9 | One(NotifyOneStrategy),
All,
}
/// List used in `Notify::notify_waiters`. It wraps a guarded linked list
/// and gates the access to it on `notify.waiters` mutex. It also empties
/// the list on drop.
struct NotifyWaitersList<'a> {
list: GuardedWaitList,
is_empty: bool,
notify: &'a Notify,
}
impl<'a> ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | a7896d07f1d3093524c7a190b57570dad3767c7a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a7896d07f1d3093524c7a190b57570dad3767c7a/tokio/src/sync/notify.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/sync/notify.rs:10 | impl Drop for NotifyWaitersList<'_> {
fn drop(&mut self) {
// If the list is not empty, we unlink all waiters from it.
// We do not wake the waiters to avoid double panics.
if !self.is_empty {
let _lock_guard = self.notify.waiters.lock();
while let Some(waiter) = self... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | a7896d07f1d3093524c7a190b57570dad3767c7a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a7896d07f1d3093524c7a190b57570dad3767c7a/tokio/src/sync/notify.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/sync/notify.rs:11 | enum State {
Init,
Waiting,
Done,
}
const NOTIFY_WAITERS_SHIFT: usize = 2;
const STATE_MASK: usize = (1 << NOTIFY_WAITERS_SHIFT) - 1;
const NOTIFY_WAITERS_CALLS_MASK: usize = !STATE_MASK;
/// Initial "idle" state.
const EMPTY: usize = 0;
/// One or more threads are currently waiting to be notified.
const... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | a7896d07f1d3093524c7a190b57570dad3767c7a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a7896d07f1d3093524c7a190b57570dad3767c7a/tokio/src/sync/notify.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/sync/notify.rs:23 | /// pub async fn recv(&self) -> T {
/// let future = self.notify_on_sent.notified();
/// tokio::pin!(future);
///
/// loop {
/// // Make sure that no wakeup is lost if we get
/// // `None` from `try_recv`.
/// future.as_mut().en... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | a7896d07f1d3093524c7a190b57570dad3767c7a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a7896d07f1d3093524c7a190b57570dad3767c7a/tokio/src/sync/notify.rs | 881 | 940 |
tokio-rs/tokio:tokio/src/sync/notify.rs:24 | is_unpin::<State>();
is_unpin::<usize>();
let me = self.get_unchecked_mut();
(
me.notify,
&mut me.state,
&me.notify_waiters_calls,
&me.waiter,
)
}
}
fn poll_notified(self: Pin<&mut Self>, wa... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | a7896d07f1d3093524c7a190b57570dad3767c7a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a7896d07f1d3093524c7a190b57570dad3767c7a/tokio/src/sync/notify.rs | 921 | 980 |
tokio-rs/tokio:tokio/src/sync/notify.rs:25 | // state.
let mut waiters = notify.waiters.lock();
// Reload the state with the lock held
let mut curr = notify.state.load(SeqCst);
// if notify_waiters has been called after the future
// was created, then we are done... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | a7896d07f1d3093524c7a190b57570dad3767c7a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a7896d07f1d3093524c7a190b57570dad3767c7a/tokio/src/sync/notify.rs | 961 | 1,020 |
tokio-rs/tokio:tokio/src/sync/notify.rs:26 | );
match res {
Ok(_) => {
// Acquired the notification
*state = State::Done;
continue 'outer_loop;
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | a7896d07f1d3093524c7a190b57570dad3767c7a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a7896d07f1d3093524c7a190b57570dad3767c7a/tokio/src/sync/notify.rs | 1,001 | 1,060 |
tokio-rs/tokio:tokio/src/sync/notify.rs:27 | State::Waiting => {
#[cfg(tokio_taskdump)]
if let Some(waker) = waker {
let mut ctx = Context::from_waker(waker);
std::task::ready!(crate::trace::trace_leaf(&mut ctx));
}
if waiter.notificati... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | a7896d07f1d3093524c7a190b57570dad3767c7a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a7896d07f1d3093524c7a190b57570dad3767c7a/tokio/src/sync/notify.rs | 1,041 | 1,100 |
tokio-rs/tokio:tokio/src/sync/notify.rs:28 | }
// Load the state with the lock held.
let curr = notify.state.load(SeqCst);
if get_num_notify_waiters_calls(curr) != *notify_waiters_calls {
// Before we add a waiter to the list we check if these numbers are
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | a7896d07f1d3093524c7a190b57570dad3767c7a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a7896d07f1d3093524c7a190b57570dad3767c7a/tokio/src/sync/notify.rs | 1,081 | 1,140 |
tokio-rs/tokio:tokio/src/sync/notify.rs:29 | return Poll::Pending;
}
// Explicit drop of the lock to indicate the scope that the
// lock is held. Because holding the lock is required to
// ensure safe access to fields not held within the lock, it
// is helpful to ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | a7896d07f1d3093524c7a190b57570dad3767c7a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a7896d07f1d3093524c7a190b57570dad3767c7a/tokio/src/sync/notify.rs | 1,121 | 1,180 |
tokio-rs/tokio:tokio/src/sync/notify.rs:30 | // This is where we ensure safety. The `Notified` value is being
// dropped, which means we must ensure that the waiter entry is no
// longer stored in the linked list.
if matches!(*state, State::Waiting) {
let mut waiters = notify.waiters.lock();
let mut notify_state = n... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | a7896d07f1d3093524c7a190b57570dad3767c7a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a7896d07f1d3093524c7a190b57570dad3767c7a/tokio/src/sync/notify.rs | 1,161 | 1,219 |
tokio-rs/tokio:tokio/src/sync/notify.rs:31 | /// `Waiter` is forced to be !Unpin.
unsafe impl linked_list::Link for Waiter {
type Handle = NonNull<Waiter>;
type Target = Waiter;
fn as_raw(handle: &NonNull<Waiter>) -> NonNull<Waiter> {
*handle
}
unsafe fn from_raw(ptr: NonNull<Waiter>) -> NonNull<Waiter> {
ptr
}
unsaf... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | a7896d07f1d3093524c7a190b57570dad3767c7a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a7896d07f1d3093524c7a190b57570dad3767c7a/tokio/src/sync/notify.rs | 1,201 | 1,219 |
tokio-rs/tokio:tokio/src/sync/notify.rs:28 | }
// Load the state with the lock held.
let curr = notify.state.load(SeqCst);
if get_num_notify_waiters_calls(curr) != *notify_waiters_calls {
// Before we add a waiter to the list we check if these numbers are
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 5dcc848fc85259e342c032b9084debfcb70aa8bb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5dcc848fc85259e342c032b9084debfcb70aa8bb/tokio/src/sync/notify.rs | 1,081 | 1,140 |
tokio-rs/tokio:tokio/src/sync/notify.rs:10 | impl Drop for NotifyWaitersList<'_> {
fn drop(&mut self) {
// If the list is not empty, we unlink all waiters from it.
// We do not wake the waiters to avoid double panics.
if !self.is_empty {
let _lock_guard = self.notify.waiters.lock();
while let Some(waiter) = self... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 11f66f43a09169b893212b854c6c49985ff2224f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/11f66f43a09169b893212b854c6c49985ff2224f/tokio/src/sync/notify.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/sync/notify.rs:11 | Init,
Waiting,
Done,
}
const NOTIFY_WAITERS_SHIFT: usize = 2;
const STATE_MASK: usize = (1 << NOTIFY_WAITERS_SHIFT) - 1;
const NOTIFY_WAITERS_CALLS_MASK: usize = !STATE_MASK;
/// Initial "idle" state.
const EMPTY: usize = 0;
/// One or more threads are currently waiting to be notified.
const WAITING: usize =... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 11f66f43a09169b893212b854c6c49985ff2224f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/11f66f43a09169b893212b854c6c49985ff2224f/tokio/src/sync/notify.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/sync/notify.rs:15 | /// use std::sync::Arc;
///
/// #[tokio::main]
/// async fn main() {
/// let notify = Arc::new(Notify::new());
/// let notify2 = notify.clone();
///
/// tokio::spawn(async move {
/// notify2.notified().await;
/// println!("received notification");
/// ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 11f66f43a09169b893212b854c6c49985ff2224f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/11f66f43a09169b893212b854c6c49985ff2224f/tokio/src/sync/notify.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/sync/notify.rs:16 | while let EMPTY | NOTIFIED = get_state(curr) {
// The compare-exchange from `NOTIFIED` -> `NOTIFIED` is intended. A
// happens-before synchronization must happen between this atomic
// operation and a task calling `notified().await`.
let new = set_state(curr, NOTIFIED);
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 11f66f43a09169b893212b854c6c49985ff2224f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/11f66f43a09169b893212b854c6c49985ff2224f/tokio/src/sync/notify.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/sync/notify.rs:17 | /// use tokio::sync::Notify;
/// use std::sync::Arc;
///
/// #[tokio::main]
/// async fn main() {
/// let notify = Arc::new(Notify::new());
/// let notify2 = notify.clone();
///
/// let notified1 = notify.notified();
/// let notified2 = notify.notified();
///
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 11f66f43a09169b893212b854c6c49985ff2224f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/11f66f43a09169b893212b854c6c49985ff2224f/tokio/src/sync/notify.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/sync/notify.rs:18 | // It is critical for `GuardedLinkedList` safety that the guard node is
// pinned in memory and is not dropped until the guarded list is dropped.
let guard = Waiter::new();
pin!(guard);
// We move all waiters to a secondary list. It uses a `GuardedLinkedList`
// underneath to al... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 11f66f43a09169b893212b854c6c49985ff2224f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/11f66f43a09169b893212b854c6c49985ff2224f/tokio/src/sync/notify.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/sync/notify.rs:19 | drop(waiters);
// One of the wakers may panic, but the remaining waiters will still
// be unlinked from the list in `NotifyWaitersList` destructor.
wakers.wake_all();
// Acquire the lock again.
waiters = self.waiters.lock();
}
// Release the... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 11f66f43a09169b893212b854c6c49985ff2224f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/11f66f43a09169b893212b854c6c49985ff2224f/tokio/src/sync/notify.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/sync/notify.rs:20 | assert!(actual_state == EMPTY || actual_state == NOTIFIED);
state.store(set_state(actual, NOTIFIED), SeqCst);
None
}
}
}
WAITING => {
// At this point, it is guaranteed that the state will not
// concurrently cha... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 11f66f43a09169b893212b854c6c49985ff2224f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/11f66f43a09169b893212b854c6c49985ff2224f/tokio/src/sync/notify.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/sync/notify.rs:23 | /// let future = self.notify_on_sent.notified();
/// tokio::pin!(future);
///
/// loop {
/// // Make sure that no wakeup is lost if we get
/// // `None` from `try_recv`.
/// future.as_mut().enable();
///
/// if let S... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 11f66f43a09169b893212b854c6c49985ff2224f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/11f66f43a09169b893212b854c6c49985ff2224f/tokio/src/sync/notify.rs | 881 | 940 |
tokio-rs/tokio:tokio/src/sync/notify.rs:24 | is_unpin::<usize>();
let me = self.get_unchecked_mut();
(
me.notify,
&mut me.state,
&me.notify_waiters_calls,
&me.waiter,
)
}
}
fn poll_notified(self: Pin<&mut Self>, waker: Option<&Waker>) -> Poll<()> ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 11f66f43a09169b893212b854c6c49985ff2224f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/11f66f43a09169b893212b854c6c49985ff2224f/tokio/src/sync/notify.rs | 921 | 980 |
tokio-rs/tokio:tokio/src/sync/notify.rs:25 | let mut waiters = notify.waiters.lock();
// Reload the state with the lock held
let mut curr = notify.state.load(SeqCst);
// if notify_waiters has been called after the future
// was created, then we are done
if get_nu... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 11f66f43a09169b893212b854c6c49985ff2224f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/11f66f43a09169b893212b854c6c49985ff2224f/tokio/src/sync/notify.rs | 961 | 1,020 |
tokio-rs/tokio:tokio/src/sync/notify.rs:26 | match res {
Ok(_) => {
// Acquired the notification
*state = State::Done;
continue 'outer_loop;
}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 11f66f43a09169b893212b854c6c49985ff2224f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/11f66f43a09169b893212b854c6c49985ff2224f/tokio/src/sync/notify.rs | 1,001 | 1,060 |
tokio-rs/tokio:tokio/src/sync/notify.rs:27 | #[cfg(tokio_taskdump)]
if let Some(waker) = waker {
let mut ctx = Context::from_waker(waker);
std::task::ready!(crate::trace::trace_leaf(&mut ctx));
}
if waiter.notification.load(Acquire).is_some() {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 11f66f43a09169b893212b854c6c49985ff2224f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/11f66f43a09169b893212b854c6c49985ff2224f/tokio/src/sync/notify.rs | 1,041 | 1,100 |
tokio-rs/tokio:tokio/src/sync/notify.rs:28 | // Load the state with the lock held.
let curr = notify.state.load(SeqCst);
if get_num_notify_waiters_calls(curr) != *notify_waiters_calls {
// Before we add a waiter to the list we check if these numbers are
// different while hol... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 11f66f43a09169b893212b854c6c49985ff2224f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/11f66f43a09169b893212b854c6c49985ff2224f/tokio/src/sync/notify.rs | 1,081 | 1,140 |
tokio-rs/tokio:tokio/src/sync/notify.rs:29 | return Poll::Pending;
}
// Explicit drop of the lock to indicate the scope that the
// lock is held. Because holding the lock is required to
// ensure safe access to fields not held within the lock, it
// is helpful to ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 11f66f43a09169b893212b854c6c49985ff2224f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/11f66f43a09169b893212b854c6c49985ff2224f/tokio/src/sync/notify.rs | 1,121 | 1,180 |
tokio-rs/tokio:tokio/src/sync/notify.rs:30 | // dropped, which means we must ensure that the waiter entry is no
// longer stored in the linked list.
if matches!(*state, State::Waiting) {
let mut waiters = notify.waiters.lock();
let mut notify_state = notify.state.load(SeqCst);
// We hold the lock, so this field... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 11f66f43a09169b893212b854c6c49985ff2224f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/11f66f43a09169b893212b854c6c49985ff2224f/tokio/src/sync/notify.rs | 1,161 | 1,218 |
tokio-rs/tokio:tokio/src/sync/notify.rs:31 | unsafe impl linked_list::Link for Waiter {
type Handle = NonNull<Waiter>;
type Target = Waiter;
fn as_raw(handle: &NonNull<Waiter>) -> NonNull<Waiter> {
*handle
}
unsafe fn from_raw(ptr: NonNull<Waiter>) -> NonNull<Waiter> {
ptr
}
unsafe fn pointers(target: NonNull<Waiter>... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 11f66f43a09169b893212b854c6c49985ff2224f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/11f66f43a09169b893212b854c6c49985ff2224f/tokio/src/sync/notify.rs | 1,201 | 1,218 |
tokio-rs/tokio:tokio/src/sync/notify.rs:26 | match res {
Ok(_) => {
// Acquired the notification
*state = State::Done;
continue 'outer_loop;
}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 9e00b266e08d263c497dc9de57d9acbc049ae69b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/9e00b266e08d263c497dc9de57d9acbc049ae69b/tokio/src/sync/notify.rs | 1,001 | 1,060 |
tokio-rs/tokio:tokio/src/sync/notify.rs:27 | #[cfg(tokio_taskdump)]
if let Some(waker) = waker {
let mut ctx = Context::from_waker(waker);
ready!(crate::trace::trace_leaf(&mut ctx));
}
if waiter.notification.load(Acquire).is_some() {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 9e00b266e08d263c497dc9de57d9acbc049ae69b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/9e00b266e08d263c497dc9de57d9acbc049ae69b/tokio/src/sync/notify.rs | 1,041 | 1,100 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.