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/notify.rs:14 | let me = self.get_unchecked_mut();
(me.notify, &mut me.state, &me.waiter)
}
}
}
impl Future for Notified<'_> {
type Output = ();
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()> {
use State::*;
let (notify, state, waiter) = self.project();
loop ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 03969cdae7674681d1b10926e6a56fbb8908dbb8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/sync/notify.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/sync/notify.rs:15 | // 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_num_notify_waiters_calls(curr) != initial_notify_waiters_calls {... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 03969cdae7674681d1b10926e6a56fbb8908dbb8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/sync/notify.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/sync/notify.rs:16 | match res {
Ok(_) => {
// Acquired the notification
*state = Done;
return Poll::Ready(());
}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 03969cdae7674681d1b10926e6a56fbb8908dbb8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/sync/notify.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/sync/notify.rs:17 | if w.notified.is_some() {
// Our waker has been notified. Reset the fields and
// remove it from the list.
w.waker = None;
w.notified = None;
*state = Done;
} else {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 03969cdae7674681d1b10926e6a56fbb8908dbb8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/sync/notify.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/sync/notify.rs:18 | // dropped, which means we must ensure that the waiter entry is no
// longer stored in the linked list.
if let Waiting = *state {
let mut waiters = notify.waiters.lock();
let mut notify_state = notify.state.load(SeqCst);
// remove the entry from the list (if not alre... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 03969cdae7674681d1b10926e6a56fbb8908dbb8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/sync/notify.rs | 681 | 736 |
tokio-rs/tokio:tokio/src/sync/notify.rs:19 | 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(mut target: NonNull<Waiter>) -> NonNull<linked_list::Pointers<Waiter>> {
NonNull::from(&mut targe... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 03969cdae7674681d1b10926e6a56fbb8908dbb8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/sync/notify.rs | 721 | 736 |
tokio-rs/tokio:tokio/src/sync/notify.rs:3 | /// }
///
/// impl<T> Channel<T> {
/// pub fn send(&self, value: T) {
/// self.values.lock().unwrap()
/// .push_back(value);
///
/// // Notify the consumer a value is available
/// self.notify.notify_one();
/// }
///
/// pub async fn recv(&self) -> T {
/// loop {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | ea19606bc459ddacca7ba5be54d93ec766ab8c25 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ea19606bc459ddacca7ba5be54d93ec766ab8c25/tokio/src/sync/notify.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/sync/notify.rs:4 | #[derive(Debug, Clone, Copy)]
enum NotificationType {
// Notification triggered by calling `notify_waiters`
AllWaiters,
// Notification triggered by calling `notify_one`
OneWaiter,
}
#[derive(Debug)]
struct Waiter {
/// Intrusive linked-list pointers
pointers: linked_list::Pointers<Waiter>,
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | ea19606bc459ddacca7ba5be54d93ec766ab8c25 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ea19606bc459ddacca7ba5be54d93ec766ab8c25/tokio/src/sync/notify.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/sync/notify.rs:5 | enum State {
Init(usize),
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.... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | ea19606bc459ddacca7ba5be54d93ec766ab8c25 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ea19606bc459ddacca7ba5be54d93ec766ab8c25/tokio/src/sync/notify.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/sync/notify.rs:8 | notify: self,
state: State::Init(state >> NOTIFY_WAITERS_SHIFT),
waiter: UnsafeCell::new(Waiter {
pointers: linked_list::Pointers::new(),
waker: None,
notified: None,
_p: PhantomPinned,
}),
}
}
/// Notif... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | ea19606bc459ddacca7ba5be54d93ec766ab8c25 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ea19606bc459ddacca7ba5be54d93ec766ab8c25/tokio/src/sync/notify.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/sync/notify.rs:9 | ///
/// println!("sending notification");
/// notify.notify_one();
/// }
/// ```
// Alias for old name in 0.x
#[cfg_attr(docsrs, doc(alias = "notify"))]
pub fn notify_one(&self) {
// Load the current state
let mut curr = self.state.load(SeqCst);
// If the sta... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | ea19606bc459ddacca7ba5be54d93ec766ab8c25 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ea19606bc459ddacca7ba5be54d93ec766ab8c25/tokio/src/sync/notify.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/sync/notify.rs:10 | /// Notifies all waiting tasks
///
/// If a task is currently waiting, that task is notified. Unlike with
/// `notify_one()`, no permit is stored to be used by the next call to
/// `notified().await`. The purpose of this method is to notify all
/// already registered waiters. Registering for notific... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | ea19606bc459ddacca7ba5be54d93ec766ab8c25 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ea19606bc459ddacca7ba5be54d93ec766ab8c25/tokio/src/sync/notify.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/sync/notify.rs:14 | let me = self.get_unchecked_mut();
(me.notify, &mut me.state, &me.waiter)
}
}
}
impl Future for Notified<'_> {
type Output = ();
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()> {
use State::*;
let (notify, state, waiter) = self.project();
loop ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 1e2e38b7cdf4c9f51a0034469c8553d995af1383 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1e2e38b7cdf4c9f51a0034469c8553d995af1383/tokio/src/sync/notify.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/sync/notify.rs:15 | // if notify_waiters has been called after the future
// was created, then we are done
if get_num_notify_waiters_calls(curr) != initial_notify_waiters_calls {
*state = Done;
return Poll::Ready(());
}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 1e2e38b7cdf4c9f51a0034469c8553d995af1383 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1e2e38b7cdf4c9f51a0034469c8553d995af1383/tokio/src/sync/notify.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/sync/notify.rs:16 | return Poll::Ready(());
}
Err(actual) => {
assert_eq!(get_state(actual), EMPTY);
curr = actual;
}
}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 1e2e38b7cdf4c9f51a0034469c8553d995af1383 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1e2e38b7cdf4c9f51a0034469c8553d995af1383/tokio/src/sync/notify.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/sync/notify.rs:17 | w.waker = None;
w.notified = None;
*state = Done;
} else {
// Update the waker, if necessary.
if !w.waker.as_ref().unwrap().will_wake(cx.waker()) {
w.waker = Some(cx.waker().c... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 1e2e38b7cdf4c9f51a0034469c8553d995af1383 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1e2e38b7cdf4c9f51a0034469c8553d995af1383/tokio/src/sync/notify.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/sync/notify.rs:18 | let mut notify_state = notify.state.load(SeqCst);
// remove the entry from the list (if not already removed)
//
// safety: the waiter is only added to `waiters` by virtue of it
// being the only `LinkedList` available to the type.
unsafe { waiters.remove(NonN... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 1e2e38b7cdf4c9f51a0034469c8553d995af1383 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1e2e38b7cdf4c9f51a0034469c8553d995af1383/tokio/src/sync/notify.rs | 681 | 732 |
tokio-rs/tokio:tokio/src/sync/notify.rs:19 | }
unsafe fn from_raw(ptr: NonNull<Waiter>) -> NonNull<Waiter> {
ptr
}
unsafe fn pointers(mut target: NonNull<Waiter>) -> NonNull<linked_list::Pointers<Waiter>> {
NonNull::from(&mut target.as_mut().pointers)
}
}
fn is_unpin<T: Unpin>() {} | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 1e2e38b7cdf4c9f51a0034469c8553d995af1383 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1e2e38b7cdf4c9f51a0034469c8553d995af1383/tokio/src/sync/notify.rs | 721 | 732 |
tokio-rs/tokio:tokio/src/sync/notify.rs:3 | ///
/// impl<T> Channel<T> {
/// pub fn send(&self, value: T) {
/// self.values.lock().unwrap()
/// .push_back(value);
///
/// // Notify the consumer a value is available
/// self.notify.notify_one();
/// }
///
/// pub async fn recv(&self) -> T {
/// loop {
/// ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 8198ef38814c45f9dc02fcbf826225b5cf32a6bb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8198ef38814c45f9dc02fcbf826225b5cf32a6bb/tokio/src/sync/notify.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/sync/notify.rs:4 | enum NotificationType {
// Notification triggered by calling `notify_waiters`
AllWaiters,
// Notification triggered by calling `notify_one`
OneWaiter,
}
#[derive(Debug)]
struct Waiter {
/// Intrusive linked-list pointers
pointers: linked_list::Pointers<Waiter>,
/// Waiting task's waker
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 8198ef38814c45f9dc02fcbf826225b5cf32a6bb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8198ef38814c45f9dc02fcbf826225b5cf32a6bb/tokio/src/sync/notify.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/sync/notify.rs:5 | Init(usize),
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: u... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 8198ef38814c45f9dc02fcbf826225b5cf32a6bb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8198ef38814c45f9dc02fcbf826225b5cf32a6bb/tokio/src/sync/notify.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/sync/notify.rs:6 | ///
/// # Examples
///
/// ```
/// use tokio::sync::Notify;
///
/// let notify = Notify::new();
/// ```
pub fn new() -> Notify {
Notify {
state: AtomicUsize::new(0),
waiters: Mutex::new(LinkedList::new()),
}
}
/// Create a new `Notify`, in... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 8198ef38814c45f9dc02fcbf826225b5cf32a6bb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8198ef38814c45f9dc02fcbf826225b5cf32a6bb/tokio/src/sync/notify.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/sync/notify.rs:8 | state: State::Init(state >> NOTIFY_WAITERS_SHIFT),
waiter: UnsafeCell::new(Waiter {
pointers: linked_list::Pointers::new(),
waker: None,
notified: None,
_p: PhantomPinned,
}),
}
}
/// Notifies a waiting task
///... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 8198ef38814c45f9dc02fcbf826225b5cf32a6bb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8198ef38814c45f9dc02fcbf826225b5cf32a6bb/tokio/src/sync/notify.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/sync/notify.rs:9 | /// println!("sending notification");
/// notify.notify_one();
/// }
/// ```
// Alias for old name in 0.x
#[cfg_attr(docsrs, doc(alias = "notify"))]
pub fn notify_one(&self) {
// Load the current state
let mut curr = self.state.load(SeqCst);
// If the state is `E... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 8198ef38814c45f9dc02fcbf826225b5cf32a6bb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8198ef38814c45f9dc02fcbf826225b5cf32a6bb/tokio/src/sync/notify.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/sync/notify.rs:10 | /// Notifies all waiting tasks
///
/// If a task is currently waiting, that task is notified. Unlike with
/// `notify_one()`, no permit is stored to be used by the next call to
/// `notified().await`. The purpose of this method is to notify all
/// already registered waiters. Registering for notific... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 8198ef38814c45f9dc02fcbf826225b5cf32a6bb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8198ef38814c45f9dc02fcbf826225b5cf32a6bb/tokio/src/sync/notify.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/sync/notify.rs:11 | // The state must be reloaded while the lock is held. The state may only
// transition out of WAITING while the lock is held.
let curr = self.state.load(SeqCst);
if let EMPTY | NOTIFIED = get_state(curr) {
// There are no waiting tasks. All we need to do is increment the
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 8198ef38814c45f9dc02fcbf826225b5cf32a6bb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8198ef38814c45f9dc02fcbf826225b5cf32a6bb/tokio/src/sync/notify.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/sync/notify.rs:12 | waker.take().unwrap().wake();
}
curr_waker = 0;
// Acquire the lock again.
waiters = self.waiters.lock();
}
// All waiters will be notified, the state must be transitioned to
// `EMPTY`. As transitioning **from** `WAITING` requires the lock to b... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 8198ef38814c45f9dc02fcbf826225b5cf32a6bb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8198ef38814c45f9dc02fcbf826225b5cf32a6bb/tokio/src/sync/notify.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/sync/notify.rs:13 | assert!(actual_state == EMPTY || actual_state == NOTIFIED);
state.store(set_state(actual, NOTIFIED), SeqCst);
return None;
}
}
}
WAITING => {
// At this point, it is guaranteed that the state will... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 8198ef38814c45f9dc02fcbf826225b5cf32a6bb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8198ef38814c45f9dc02fcbf826225b5cf32a6bb/tokio/src/sync/notify.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/sync/notify.rs:14 | /// 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>) -> (&Notify, &mut State, &UnsafeCell<Waiter>) {
unsafe {
// Safety: both `notify` and `state` are `Unpin`.
is_unpin::<&Not... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 8198ef38814c45f9dc02fcbf826225b5cf32a6bb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8198ef38814c45f9dc02fcbf826225b5cf32a6bb/tokio/src/sync/notify.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/sync/notify.rs:15 | }
// 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 | 8198ef38814c45f9dc02fcbf826225b5cf32a6bb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8198ef38814c45f9dc02fcbf826225b5cf32a6bb/tokio/src/sync/notify.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/sync/notify.rs:16 | 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 | 8198ef38814c45f9dc02fcbf826225b5cf32a6bb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8198ef38814c45f9dc02fcbf826225b5cf32a6bb/tokio/src/sync/notify.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/sync/notify.rs:17 | let waiters = notify.waiters.lock();
// Safety: called while locked
let w = unsafe { &mut *waiter.get() };
if w.notified.is_some() {
// Our waker has been notified. Reset the fields and
// remove it from the li... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 8198ef38814c45f9dc02fcbf826225b5cf32a6bb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8198ef38814c45f9dc02fcbf826225b5cf32a6bb/tokio/src/sync/notify.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/sync/notify.rs:18 | // Safety: The type only transitions to a "Waiting" state when pinned.
let (notify, state, waiter) = unsafe { Pin::new_unchecked(self).project() };
// This is where we ensure safety. The `Notified` value is being
// dropped, which means we must ensure that the waiter entry is no
// long... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 8198ef38814c45f9dc02fcbf826225b5cf32a6bb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8198ef38814c45f9dc02fcbf826225b5cf32a6bb/tokio/src/sync/notify.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/sync/notify.rs:19 | /// # Safety
///
/// `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... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 8198ef38814c45f9dc02fcbf826225b5cf32a6bb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8198ef38814c45f9dc02fcbf826225b5cf32a6bb/tokio/src/sync/notify.rs | 721 | 741 |
tokio-rs/tokio:tokio/src/sync/notify.rs:13 | assert!(actual_state == EMPTY || actual_state == NOTIFIED);
state.store(set_state(actual, NOTIFIED), SeqCst);
return None;
}
}
}
WAITING => {
// At this point, it is guaranteed that the state will... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | b521cc26895c6331c8ced6be72f8b3d9947a9fb3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b521cc26895c6331c8ced6be72f8b3d9947a9fb3/tokio/src/sync/notify.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/sync/notify.rs:14 | /// 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>) -> (&Notify, &mut State, &UnsafeCell<Waiter>) {
unsafe {
// Safety: both `notify` and `state` are `Unpin`.
is_unpin::<&Not... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | b521cc26895c6331c8ced6be72f8b3d9947a9fb3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b521cc26895c6331c8ced6be72f8b3d9947a9fb3/tokio/src/sync/notify.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/sync/notify.rs:6 | ///
/// # Examples
///
/// ```
/// use tokio::sync::Notify;
///
/// let notify = Notify::new();
/// ```
pub fn new() -> Notify {
Notify {
state: AtomicUsize::new(0),
waiters: Mutex::new(LinkedList::new()),
}
}
/// Create a new `Notify`, in... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 21de476ae7ce97d1ca502b82dad20f2ba3850769 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/21de476ae7ce97d1ca502b82dad20f2ba3850769/tokio/src/sync/notify.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/sync/notify.rs:8 | }),
}
}
/// Notifies a waiting task
///
/// If a task is currently waiting, that task is notified. Otherwise, a
/// permit is stored in this `Notify` value and the **next** call to
/// [`notified().await`] will complete immediately consuming the permit made
/// available by this cal... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 21de476ae7ce97d1ca502b82dad20f2ba3850769 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/21de476ae7ce97d1ca502b82dad20f2ba3850769/tokio/src/sync/notify.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/sync/notify.rs:9 | pub fn notify_one(&self) {
// Load the current state
let mut curr = self.state.load(SeqCst);
// 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
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 21de476ae7ce97d1ca502b82dad20f2ba3850769 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/21de476ae7ce97d1ca502b82dad20f2ba3850769/tokio/src/sync/notify.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/sync/notify.rs:10 | /// acquiring an instance of the `Notified` future via calling `notified()`.
///
/// # Examples
///
/// ```
/// use tokio::sync::Notify;
/// use std::sync::Arc;
///
/// #[tokio::main]
/// async fn main() {
/// let notify = Arc::new(Notify::new());
/// let notify2 = no... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 21de476ae7ce97d1ca502b82dad20f2ba3850769 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/21de476ae7ce97d1ca502b82dad20f2ba3850769/tokio/src/sync/notify.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/sync/notify.rs:11 | // There are no waiting tasks. All we need to do is increment the
// number of times this method was called.
atomic_inc_num_notify_waiters_calls(&self.state);
return;
}
// At this point, it is guaranteed that the state will not
// concurrently change, as hold... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 21de476ae7ce97d1ca502b82dad20f2ba3850769 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/21de476ae7ce97d1ca502b82dad20f2ba3850769/tokio/src/sync/notify.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/sync/notify.rs:12 | waiters = self.waiters.lock();
}
// All waiters will be notified, the state must be transitioned to
// `EMPTY`. As transitioning **from** `WAITING` requires the lock to be
// held, a `store` is sufficient.
let new = set_state(inc_num_notify_waiters_calls(curr), EMPTY);
s... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 21de476ae7ce97d1ca502b82dad20f2ba3850769 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/21de476ae7ce97d1ca502b82dad20f2ba3850769/tokio/src/sync/notify.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/sync/notify.rs:13 | WAITING => {
// At this point, it is guaranteed that the state will not
// concurrently change as holding the lock is required to
// transition **out** of `WAITING`.
//
// Get a pending waiter
let mut waiter = waiters.pop_ba... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 21de476ae7ce97d1ca502b82dad20f2ba3850769 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/21de476ae7ce97d1ca502b82dad20f2ba3850769/tokio/src/sync/notify.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/sync/notify.rs:14 | is_unpin::<&Notify>();
is_unpin::<AtomicUsize>();
let me = self.get_unchecked_mut();
(&me.notify, &mut me.state, &me.waiter)
}
}
}
impl Future for Notified<'_> {
type Output = ();
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()> {
use Sta... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 21de476ae7ce97d1ca502b82dad20f2ba3850769 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/21de476ae7ce97d1ca502b82dad20f2ba3850769/tokio/src/sync/notify.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/sync/notify.rs:15 | // 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_num_notify_waiters_calls(curr) != initial_notify_waiters_calls {... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 21de476ae7ce97d1ca502b82dad20f2ba3850769 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/21de476ae7ce97d1ca502b82dad20f2ba3850769/tokio/src/sync/notify.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/sync/notify.rs:16 | Ok(_) => {
// Acquired the notification
*state = Done;
return Poll::Ready(());
}
Err(actual) => {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 21de476ae7ce97d1ca502b82dad20f2ba3850769 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/21de476ae7ce97d1ca502b82dad20f2ba3850769/tokio/src/sync/notify.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/sync/notify.rs:17 | if w.notified.is_some() {
// Our waker has been notified. Reset the fields and
// remove it from the list.
w.waker = None;
w.notified = None;
*state = Done;
} else {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 21de476ae7ce97d1ca502b82dad20f2ba3850769 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/21de476ae7ce97d1ca502b82dad20f2ba3850769/tokio/src/sync/notify.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/sync/notify.rs:18 | // longer stored in the linked list.
if let Waiting = *state {
let mut waiters = notify.waiters.lock();
let mut notify_state = notify.state.load(SeqCst);
// remove the entry from the list (if not already removed)
//
// safety: the waiter is only added... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 21de476ae7ce97d1ca502b82dad20f2ba3850769 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/21de476ae7ce97d1ca502b82dad20f2ba3850769/tokio/src/sync/notify.rs | 681 | 735 |
tokio-rs/tokio:tokio/src/sync/notify.rs:19 | fn as_raw(handle: &NonNull<Waiter>) -> NonNull<Waiter> {
*handle
}
unsafe fn from_raw(ptr: NonNull<Waiter>) -> NonNull<Waiter> {
ptr
}
unsafe fn pointers(mut target: NonNull<Waiter>) -> NonNull<linked_list::Pointers<Waiter>> {
NonNull::from(&mut target.as_mut().pointers)
}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 21de476ae7ce97d1ca502b82dad20f2ba3850769 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/21de476ae7ce97d1ca502b82dad20f2ba3850769/tokio/src/sync/notify.rs | 721 | 735 |
tokio-rs/tokio:tokio/src/sync/notify.rs:4 | enum NotificationType {
// Notification triggered by calling `notify_waiters`
AllWaiters,
// Notification triggered by calling `notify_one`
OneWaiter,
}
#[derive(Debug)]
struct Waiter {
/// Intrusive linked-list pointers
pointers: linked_list::Pointers<Waiter>,
/// Waiting task's waker
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 6845a93cbf52ca8b0709918db0c8c558d6d8720e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6845a93cbf52ca8b0709918db0c8c558d6d8720e/tokio/src/sync/notify.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/sync/notify.rs:5 | Init(usize),
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: u... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | f7c181c2c49ee28d7cb0773f5cdb4bec35b5a89b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f7c181c2c49ee28d7cb0773f5cdb4bec35b5a89b/tokio/src/sync/notify.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/sync/notify.rs:6 | /// use tokio::sync::Notify;
///
/// let notify = Notify::new();
/// ```
pub fn new() -> Notify {
Notify {
state: AtomicUsize::new(0),
waiters: Mutex::new(LinkedList::new()),
}
}
/// Create a new `Notify`, initialized without a permit.
///
/// # E... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | f7c181c2c49ee28d7cb0773f5cdb4bec35b5a89b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f7c181c2c49ee28d7cb0773f5cdb4bec35b5a89b/tokio/src/sync/notify.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/sync/notify.rs:8 | /// Notifies a waiting task
///
/// If a task is currently waiting, that task is notified. Otherwise, a
/// permit is stored in this `Notify` value and the **next** call to
/// [`notified().await`] will complete immediately consuming the permit made
/// available by this call to `notify_one()`.
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | f7c181c2c49ee28d7cb0773f5cdb4bec35b5a89b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f7c181c2c49ee28d7cb0773f5cdb4bec35b5a89b/tokio/src/sync/notify.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/sync/notify.rs:9 | // 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 | f7c181c2c49ee28d7cb0773f5cdb4bec35b5a89b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f7c181c2c49ee28d7cb0773f5cdb4bec35b5a89b/tokio/src/sync/notify.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/sync/notify.rs:10 | /// ```
/// 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 | f7c181c2c49ee28d7cb0773f5cdb4bec35b5a89b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f7c181c2c49ee28d7cb0773f5cdb4bec35b5a89b/tokio/src/sync/notify.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/sync/notify.rs:11 | self.state.store(inc_num_notify_waiters_calls(curr), SeqCst);
return;
}
// At this point, it is guaranteed that the state will not
// concurrently change, as holding the lock is required to
// transition **out** of `WAITING`.
'outer: loop {
while curr_wak... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | f7c181c2c49ee28d7cb0773f5cdb4bec35b5a89b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f7c181c2c49ee28d7cb0773f5cdb4bec35b5a89b/tokio/src/sync/notify.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/sync/notify.rs:12 | // All waiters will be notified, the state must be transitioned to
// `EMPTY`. As transitioning **from** `WAITING` requires the lock to be
// held, a `store` is sufficient.
let new = set_state(inc_num_notify_waiters_calls(curr), EMPTY);
self.state.store(new, SeqCst);
// Release ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | f7c181c2c49ee28d7cb0773f5cdb4bec35b5a89b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f7c181c2c49ee28d7cb0773f5cdb4bec35b5a89b/tokio/src/sync/notify.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/sync/notify.rs:13 | // concurrently change as holding the lock is required to
// transition **out** of `WAITING`.
//
// Get a pending waiter
let mut waiter = waiters.pop_back().unwrap();
// Safety: `waiters` lock is still held.
let waiter = un... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | f7c181c2c49ee28d7cb0773f5cdb4bec35b5a89b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f7c181c2c49ee28d7cb0773f5cdb4bec35b5a89b/tokio/src/sync/notify.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/sync/notify.rs:14 | let me = self.get_unchecked_mut();
(&me.notify, &mut me.state, &me.waiter)
}
}
}
impl Future for Notified<'_> {
type Output = ();
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()> {
use State::*;
let (notify, state, waiter) = self.project();
loop... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | f7c181c2c49ee28d7cb0773f5cdb4bec35b5a89b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f7c181c2c49ee28d7cb0773f5cdb4bec35b5a89b/tokio/src/sync/notify.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/sync/notify.rs:15 | // if notify_waiters has been called after the future
// was created, then we are done
if get_num_notify_waiters_calls(curr) != initial_notify_waiters_calls {
*state = Done;
return Poll::Ready(());
}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | f7c181c2c49ee28d7cb0773f5cdb4bec35b5a89b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f7c181c2c49ee28d7cb0773f5cdb4bec35b5a89b/tokio/src/sync/notify.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/sync/notify.rs:16 | *state = Done;
return Poll::Ready(());
}
Err(actual) => {
assert_eq!(get_state(actual), EMPTY);
curr = actual;
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | f7c181c2c49ee28d7cb0773f5cdb4bec35b5a89b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f7c181c2c49ee28d7cb0773f5cdb4bec35b5a89b/tokio/src/sync/notify.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/sync/notify.rs:17 | // remove it from the list.
w.waker = None;
w.notified = None;
*state = Done;
} else {
// Update the waker, if necessary.
if !w.waker.as_ref().unwrap().will_wake(cx.waker()) {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | f7c181c2c49ee28d7cb0773f5cdb4bec35b5a89b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f7c181c2c49ee28d7cb0773f5cdb4bec35b5a89b/tokio/src/sync/notify.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/sync/notify.rs:18 | let mut waiters = notify.waiters.lock();
let mut notify_state = notify.state.load(SeqCst);
// remove the entry from the list (if not already removed)
//
// safety: the waiter is only added to `waiters` by virtue of it
// being the only `LinkedList` available ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | f7c181c2c49ee28d7cb0773f5cdb4bec35b5a89b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f7c181c2c49ee28d7cb0773f5cdb4bec35b5a89b/tokio/src/sync/notify.rs | 681 | 733 |
tokio-rs/tokio:tokio/src/sync/notify.rs:19 | *handle
}
unsafe fn from_raw(ptr: NonNull<Waiter>) -> NonNull<Waiter> {
ptr
}
unsafe fn pointers(mut target: NonNull<Waiter>) -> NonNull<linked_list::Pointers<Waiter>> {
NonNull::from(&mut target.as_mut().pointers)
}
}
fn is_unpin<T: Unpin>() {} | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | f7c181c2c49ee28d7cb0773f5cdb4bec35b5a89b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f7c181c2c49ee28d7cb0773f5cdb4bec35b5a89b/tokio/src/sync/notify.rs | 721 | 733 |
tokio-rs/tokio:tokio/src/sync/notify.rs:17 | // remove it from the list.
w.waker = None;
w.notified = None;
*state = Done;
} else {
// Update the waker, if necessary.
if !w.waker.as_ref().unwrap().will_wake(cx.waker()) {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 6fd06aaeecce21bcf31cbe485fe0060e3f07e983 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6fd06aaeecce21bcf31cbe485fe0060e3f07e983/tokio/src/sync/notify.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/sync/notify.rs:18 | let mut waiters = notify.waiters.lock();
let mut notify_state = notify.state.load(SeqCst);
// `Notify.state` may be in any of the three states (Empty, Waiting,
// Notified). It doesn't actually matter what the atomic is set to
// at this point. We hold the lock and will ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 6fd06aaeecce21bcf31cbe485fe0060e3f07e983 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6fd06aaeecce21bcf31cbe485fe0060e3f07e983/tokio/src/sync/notify.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/sync/notify.rs:19 | if let Some(NotificationType::OneWaiter) = unsafe { (*waiter.get()).notified } {
if let Some(waker) = notify_locked(&mut waiters, ¬ify.state, notify_state) {
drop(waiters);
waker.wake();
}
}
}
}
}
/// # Safety
///
/// `W... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 6fd06aaeecce21bcf31cbe485fe0060e3f07e983 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6fd06aaeecce21bcf31cbe485fe0060e3f07e983/tokio/src/sync/notify.rs | 721 | 751 |
tokio-rs/tokio:tokio/src/sync/notify.rs:9 | // 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);
let res = self.state.compare_exchange(curr, new,... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 36bcfa6b9d5b722bab5bdb68814988ded917802b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/36bcfa6b9d5b722bab5bdb68814988ded917802b/tokio/src/sync/notify.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/sync/notify.rs:10 | /// 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();
///
/// let handle = tokio::spawn... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 36bcfa6b9d5b722bab5bdb68814988ded917802b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/36bcfa6b9d5b722bab5bdb68814988ded917802b/tokio/src/sync/notify.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/sync/notify.rs:11 | }
// At this point, it is guaranteed that the state will not
// concurrently change, as holding the lock is required to
// transition **out** of `WAITING`.
'outer: loop {
while curr_waker < NUM_WAKERS {
match waiters.pop_back() {
Some(mut ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 36bcfa6b9d5b722bab5bdb68814988ded917802b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/36bcfa6b9d5b722bab5bdb68814988ded917802b/tokio/src/sync/notify.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/sync/notify.rs:12 | // `EMPTY`. As transitioning **from** `WAITING` requires the lock to be
// held, a `store` is sufficient.
let new = set_state(inc_num_notify_waiters_calls(curr), EMPTY);
self.state.store(new, SeqCst);
// Release the lock before notifying
drop(waiters);
for waker in wake... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 36bcfa6b9d5b722bab5bdb68814988ded917802b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/36bcfa6b9d5b722bab5bdb68814988ded917802b/tokio/src/sync/notify.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/sync/notify.rs:13 | //
// Get a pending waiter
let mut waiter = waiters.pop_back().unwrap();
// Safety: `waiters` lock is still held.
let waiter = unsafe { waiter.as_mut() };
assert!(waiter.notified.is_none());
waiter.notified = Some(Notific... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 36bcfa6b9d5b722bab5bdb68814988ded917802b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/36bcfa6b9d5b722bab5bdb68814988ded917802b/tokio/src/sync/notify.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/sync/notify.rs:14 | (&me.notify, &mut me.state, &me.waiter)
}
}
}
impl Future for Notified<'_> {
type Output = ();
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()> {
use State::*;
let (notify, state, waiter) = self.project();
loop {
match *state {
I... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 36bcfa6b9d5b722bab5bdb68814988ded917802b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/36bcfa6b9d5b722bab5bdb68814988ded917802b/tokio/src/sync/notify.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/sync/notify.rs:15 | // was created, then we are done
if get_num_notify_waiters_calls(curr) != initial_notify_waiters_calls {
*state = Done;
return Poll::Ready(());
}
// Transition the state to WAITING.
loop {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 36bcfa6b9d5b722bab5bdb68814988ded917802b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/36bcfa6b9d5b722bab5bdb68814988ded917802b/tokio/src/sync/notify.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/sync/notify.rs:16 | }
Err(actual) => {
assert_eq!(get_state(actual), EMPTY);
curr = actual;
}
}
}
_ ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 36bcfa6b9d5b722bab5bdb68814988ded917802b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/36bcfa6b9d5b722bab5bdb68814988ded917802b/tokio/src/sync/notify.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/sync/notify.rs:17 | w.notified = None;
*state = Done;
} else {
// Update the waker, if necessary.
if !w.waker.as_ref().unwrap().will_wake(cx.waker()) {
w.waker = Some(cx.waker().clone());
}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 36bcfa6b9d5b722bab5bdb68814988ded917802b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/36bcfa6b9d5b722bab5bdb68814988ded917802b/tokio/src/sync/notify.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/sync/notify.rs:18 | // `Notify.state` may be in any of the three states (Empty, Waiting,
// Notified). It doesn't actually matter what the atomic is set to
// at this point. We hold the lock and will ensure the atomic is in
// the correct state once the lock is dropped.
//
// Bec... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 36bcfa6b9d5b722bab5bdb68814988ded917802b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/36bcfa6b9d5b722bab5bdb68814988ded917802b/tokio/src/sync/notify.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/sync/notify.rs:19 | drop(waiters);
waker.wake();
}
}
}
}
}
/// # Safety
///
/// `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> {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | 36bcfa6b9d5b722bab5bdb68814988ded917802b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/36bcfa6b9d5b722bab5bdb68814988ded917802b/tokio/src/sync/notify.rs | 721 | 749 |
tokio-rs/tokio:tokio/src/sync/notify.rs:9 | // 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);
let res = self.state.compare_exchange(curr, new,... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | d0ebb4154748166a4ba07baa4b424a1c45efd219 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d0ebb4154748166a4ba07baa4b424a1c45efd219/tokio/src/sync/notify.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/sync/notify.rs:3 | ///
/// impl<T> Channel<T> {
/// pub fn send(&self, value: T) {
/// self.values.lock().unwrap()
/// .push_back(value);
///
/// // Notify the consumer a value is available
/// self.notify.notify_one();
/// }
///
/// pub async fn recv(&self) -> T {
/// loop {
/// ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | c90681bd8e629b5fde988b9f5be7b915e5cf8ae5 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c90681bd8e629b5fde988b9f5be7b915e5cf8ae5/tokio/src/sync/notify.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/sync/notify.rs:4 | OneWaiter,
}
#[derive(Debug)]
struct Waiter {
/// Intrusive linked-list pointers
pointers: linked_list::Pointers<Waiter>,
/// Waiting task's waker
waker: Option<Waker>,
/// `true` if the notification has been assigned to this waiter.
notified: Option<NotificationType>,
/// Should not be ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | c90681bd8e629b5fde988b9f5be7b915e5cf8ae5 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c90681bd8e629b5fde988b9f5be7b915e5cf8ae5/tokio/src/sync/notify.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/sync/notify.rs:5 | /// Initial "idle" state
const EMPTY: u8 = 0;
/// One or more threads are currently waiting to be notified.
const WAITING: u8 = 1;
/// Pending notification
const NOTIFIED: u8 = 2;
impl Notify {
/// Create a new `Notify`, initialized without a permit.
///
/// # Examples
///
/// ```
/// use tok... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | c90681bd8e629b5fde988b9f5be7b915e5cf8ae5 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c90681bd8e629b5fde988b9f5be7b915e5cf8ae5/tokio/src/sync/notify.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/sync/notify.rs:6 | state: AtomicU8::new(0),
waiters: Mutex::const_new(LinkedList::new()),
}
}
/// Wait for a notification.
///
/// Equivalent to:
///
/// ```ignore
/// async fn notified(&self);
/// ```
///
/// Each `Notify` value holds a single permit. If a permit is available ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | c90681bd8e629b5fde988b9f5be7b915e5cf8ae5 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c90681bd8e629b5fde988b9f5be7b915e5cf8ae5/tokio/src/sync/notify.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/sync/notify.rs:7 | pub fn notified(&self) -> Notified<'_> {
Notified {
notify: self,
state: State::Init,
waiter: UnsafeCell::new(Waiter {
pointers: linked_list::Pointers::new(),
waker: None,
notified: None,
_p: PhantomPinned,
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | c90681bd8e629b5fde988b9f5be7b915e5cf8ae5 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c90681bd8e629b5fde988b9f5be7b915e5cf8ae5/tokio/src/sync/notify.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/sync/notify.rs:8 | /// println!("received notification");
/// });
///
/// println!("sending notification");
/// notify.notify_one();
/// }
/// ```
pub fn notify_one(&self) {
// Load the current state
let mut curr = self.state.load(SeqCst);
// If the state is `EMPTY`... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | c90681bd8e629b5fde988b9f5be7b915e5cf8ae5 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c90681bd8e629b5fde988b9f5be7b915e5cf8ae5/tokio/src/sync/notify.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/sync/notify.rs:9 | /// Notifies all waiting tasks
pub(crate) fn notify_waiters(&self) {
// There are waiters, the lock must be acquired to notify.
let mut waiters = self.waiters.lock();
// The state must be reloaded while the lock is held. The state may only
// transition out of WAITING while the lock... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | c90681bd8e629b5fde988b9f5be7b915e5cf8ae5 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c90681bd8e629b5fde988b9f5be7b915e5cf8ae5/tokio/src/sync/notify.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/sync/notify.rs:10 | impl Default for Notify {
fn default() -> Notify {
Notify::new()
}
}
fn notify_locked(waiters: &mut WaitList, state: &AtomicU8, curr: u8) -> Option<Waker> {
loop {
match curr {
EMPTY | NOTIFIED => {
let res = state.compare_exchange(curr, NOTIFIED, SeqCst, SeqCst)... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | c90681bd8e629b5fde988b9f5be7b915e5cf8ae5 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c90681bd8e629b5fde988b9f5be7b915e5cf8ae5/tokio/src/sync/notify.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/sync/notify.rs:11 | // **from** `WAITING` requires the lock to be held, a
// `store` is sufficient.
state.store(EMPTY, SeqCst);
}
return waker;
}
_ => unreachable!(),
}
}
}
// ===== impl Notified =====
impl Notified<'_> {
///... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | c90681bd8e629b5fde988b9f5be7b915e5cf8ae5 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c90681bd8e629b5fde988b9f5be7b915e5cf8ae5/tokio/src/sync/notify.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/sync/notify.rs:12 | Init => {
// Optimistically try acquiring a pending notification
let res = notify
.state
.compare_exchange(NOTIFIED, EMPTY, SeqCst, SeqCst);
if res.is_ok() {
// Acquired the notification
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | c90681bd8e629b5fde988b9f5be7b915e5cf8ae5 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c90681bd8e629b5fde988b9f5be7b915e5cf8ae5/tokio/src/sync/notify.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/sync/notify.rs:13 | .compare_exchange(NOTIFIED, EMPTY, SeqCst, SeqCst);
match res {
Ok(_) => {
// Acquired the notification
*state = Done;
return Poll:... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | c90681bd8e629b5fde988b9f5be7b915e5cf8ae5 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c90681bd8e629b5fde988b9f5be7b915e5cf8ae5/tokio/src/sync/notify.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/sync/notify.rs:14 | // Safety: called while locked
let w = unsafe { &mut *waiter.get() };
if w.notified.is_some() {
// Our waker has been notified. Reset the fields and
// remove it from the list.
w.waker = None;
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | c90681bd8e629b5fde988b9f5be7b915e5cf8ae5 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c90681bd8e629b5fde988b9f5be7b915e5cf8ae5/tokio/src/sync/notify.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/sync/notify.rs:15 | // 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 let Waiting = *state {
let mut notify_state = WAITING;
let mut waiters = notify.waiters.lock();
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | c90681bd8e629b5fde988b9f5be7b915e5cf8ae5 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c90681bd8e629b5fde988b9f5be7b915e5cf8ae5/tokio/src/sync/notify.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/sync/notify.rs:16 | // the notification was triggered via `notify_one`, it must be sent
// to the next waiter.
//
// Safety: with the entry removed from the linked list, there can be
// no concurrent access to the entry
if let Some(NotificationType::OneWaiter) = unsafe { (*waiter... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | c90681bd8e629b5fde988b9f5be7b915e5cf8ae5 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c90681bd8e629b5fde988b9f5be7b915e5cf8ae5/tokio/src/sync/notify.rs | 601 | 636 |
tokio-rs/tokio:tokio/src/sync/notify.rs:8 | /// println!("received notification");
/// });
///
/// println!("sending notification");
/// notify.notify_one();
/// }
/// ```
pub fn notify_one(&self) {
// Load the current state
let mut curr = self.state.load(SeqCst);
// If the state is `EMPTY`... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | f25f12d57638a2928b3f738b3b1392d8773e276e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f25f12d57638a2928b3f738b3b1392d8773e276e/tokio/src/sync/notify.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/sync/notify.rs:9 | /// Notifies all waiting tasks
pub(crate) fn notify_waiters(&self) {
// There are waiters, the lock must be acquired to notify.
let mut waiters = self.waiters.lock().unwrap();
// The state must be reloaded while the lock is held. The state may only
// transition out of WAITING while... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | f25f12d57638a2928b3f738b3b1392d8773e276e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f25f12d57638a2928b3f738b3b1392d8773e276e/tokio/src/sync/notify.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/sync/notify.rs:11 | // **from** `WAITING` requires the lock to be held, a
// `store` is sufficient.
state.store(EMPTY, SeqCst);
}
return waker;
}
_ => unreachable!(),
}
}
}
// ===== impl Notified =====
impl Notified<'_> {
///... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | f25f12d57638a2928b3f738b3b1392d8773e276e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f25f12d57638a2928b3f738b3b1392d8773e276e/tokio/src/sync/notify.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/sync/notify.rs:12 | Init => {
// Optimistically try acquiring a pending notification
let res = notify
.state
.compare_exchange(NOTIFIED, EMPTY, SeqCst, SeqCst);
if res.is_ok() {
// Acquired the notification
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | f25f12d57638a2928b3f738b3b1392d8773e276e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f25f12d57638a2928b3f738b3b1392d8773e276e/tokio/src/sync/notify.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/sync/notify.rs:13 | .compare_exchange(NOTIFIED, EMPTY, SeqCst, SeqCst);
match res {
Ok(_) => {
// Acquired the notification
*state = Done;
return Poll:... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | f25f12d57638a2928b3f738b3b1392d8773e276e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f25f12d57638a2928b3f738b3b1392d8773e276e/tokio/src/sync/notify.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/sync/notify.rs:14 | // Safety: called while locked
let w = unsafe { &mut *waiter.get() };
if w.notified.is_some() {
// Our waker has been notified. Reset the fields and
// remove it from the list.
w.waker = None;
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | f25f12d57638a2928b3f738b3b1392d8773e276e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f25f12d57638a2928b3f738b3b1392d8773e276e/tokio/src/sync/notify.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/sync/notify.rs:15 | // 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 let Waiting = *state {
let mut notify_state = WAITING;
let mut waiters = notify.waiters.lock().unwra... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/notify.rs | MIT | f25f12d57638a2928b3f738b3b1392d8773e276e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f25f12d57638a2928b3f738b3b1392d8773e276e/tokio/src/sync/notify.rs | 561 | 620 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.