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/batch_semaphore.rs:14 | }
}
/// Assign permits to the waiter.
///
/// Returns `true` if the waiter should be removed from the queue
fn assign_permits(&self, n: &mut usize) -> bool {
let mut curr = self.state.load(Acquire);
loop {
let assign = cmp::min(curr, *n);
let next = curr - as... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | 8955ed5f8525d3585d99e762452978edb69a73ad | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8955ed5f8525d3585d99e762452978edb69a73ad/tokio/src/sync/batch_semaphore.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:15 | let (node, semaphore, needed, queued) = self.project();
// First, ensure the current task has enough budget to proceed.
#[cfg(all(tokio_unstable, feature = "tracing"))]
let coop = ready!(trace_poll_op!(
"poll_acquire",
crate::runtime::coop::poll_proceed(cx),
));
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | 8955ed5f8525d3585d99e762452978edb69a73ad | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8955ed5f8525d3585d99e762452978edb69a73ad/tokio/src/sync/batch_semaphore.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:16 | num_permits,
queued: false,
};
#[cfg(all(tokio_unstable, feature = "tracing"))]
return semaphore.resource_span.in_scope(|| {
let async_op_span =
tracing::trace_span!("runtime.resource.async_op", source = "Acquire::new");
let async_op_poll_span... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | 8955ed5f8525d3585d99e762452978edb69a73ad | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8955ed5f8525d3585d99e762452978edb69a73ad/tokio/src/sync/batch_semaphore.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:17 | fn is_unpin<T: Unpin>() {}
unsafe {
// Safety: all fields other than `node` are `Unpin`
is_unpin::<&Semaphore>();
is_unpin::<&mut bool>();
is_unpin::<u32>();
let this = self.get_unchecked_mut();
(
Pin::new_unchecked(&mut t... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | 8955ed5f8525d3585d99e762452978edb69a73ad | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8955ed5f8525d3585d99e762452978edb69a73ad/tokio/src/sync/batch_semaphore.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:18 | }
}
}
// Safety: the `Acquire` future is not `Sync` automatically because it contains
// a `Waiter`, which, in turn, contains an `UnsafeCell`. However, the
// `UnsafeCell` is only accessed when the future is borrowed mutably (either in
// `poll` or in `drop`). Therefore, it is safe (although not particularly
// _u... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | 8955ed5f8525d3585d99e762452978edb69a73ad | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8955ed5f8525d3585d99e762452978edb69a73ad/tokio/src/sync/batch_semaphore.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:19 | matches!(self, TryAcquireError::NoPermits)
}
}
impl fmt::Display for TryAcquireError {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
TryAcquireError::Closed => write!(fmt, "semaphore closed"),
TryAcquireError::NoPermits => write!(fmt, "no permits avai... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | 8955ed5f8525d3585d99e762452978edb69a73ad | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8955ed5f8525d3585d99e762452978edb69a73ad/tokio/src/sync/batch_semaphore.rs | 721 | 754 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:5 | permits.op = "override",
)
});
resource_span
};
Self {
permits: AtomicUsize::new(permits << Self::PERMIT_SHIFT),
waiters: Mutex::new(Waitlist {
queue: LinkedList::new(),
closed: false,
}),
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | efe3ab679a05f3da3fcc511a44120239830254f2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/efe3ab679a05f3da3fcc511a44120239830254f2/tokio/src/sync/batch_semaphore.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:6 | queue: LinkedList::new(),
closed: true,
}),
#[cfg(all(tokio_unstable, feature = "tracing"))]
resource_span: tracing::Span::none(),
}
}
/// Returns the current number of available permits.
pub(crate) fn available_permits(&self) -> usize {
s... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | efe3ab679a05f3da3fcc511a44120239830254f2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/efe3ab679a05f3da3fcc511a44120239830254f2/tokio/src/sync/batch_semaphore.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:7 | if let Some(waker) = waker {
waker.wake();
}
}
}
/// Returns true if the semaphore is closed.
pub(crate) fn is_closed(&self) -> bool {
self.permits.load(Acquire) & Self::CLOSED == Self::CLOSED
}
pub(crate) fn try_acquire(&self, num_permits: u32) -> Resul... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | efe3ab679a05f3da3fcc511a44120239830254f2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/efe3ab679a05f3da3fcc511a44120239830254f2/tokio/src/sync/batch_semaphore.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:8 | }
pub(crate) fn acquire(&self, num_permits: u32) -> Acquire<'_> {
Acquire::new(self, num_permits)
}
/// Release `rem` permits to the semaphore's wait list, starting from the
/// end of the queue.
///
/// If `rem` exceeds the number of permits needed by the wait list, the
/// remain... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | efe3ab679a05f3da3fcc511a44120239830254f2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/efe3ab679a05f3da3fcc511a44120239830254f2/tokio/src/sync/batch_semaphore.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:9 | if rem > 0 && is_empty {
let permits = rem;
assert!(
permits <= Self::MAX_PERMITS,
"cannot add more than MAX_PERMITS permits ({})",
Self::MAX_PERMITS
);
let prev = self.permits.fetch_add(rem << Se... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | efe3ab679a05f3da3fcc511a44120239830254f2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/efe3ab679a05f3da3fcc511a44120239830254f2/tokio/src/sync/batch_semaphore.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:10 | num_permits: u32,
node: Pin<&mut Waiter>,
queued: bool,
) -> Poll<Result<(), AcquireError>> {
let mut acquired = 0;
let needed = if queued {
node.state.load(Acquire) << Self::PERMIT_SHIFT
} else {
(num_permits as usize) << Self::PERMIT_SHIFT
}... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | efe3ab679a05f3da3fcc511a44120239830254f2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/efe3ab679a05f3da3fcc511a44120239830254f2/tokio/src/sync/batch_semaphore.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:11 | // acquire the lock, we might miss additional permits being
// added while waiting for the lock.
lock = Some(self.waiters.lock());
}
match self.permits.compare_exchange(curr, next, AcqRel, Acquire) {
Ok(_) => {
acquired += acq;... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | efe3ab679a05f3da3fcc511a44120239830254f2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/efe3ab679a05f3da3fcc511a44120239830254f2/tokio/src/sync/batch_semaphore.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:12 | self.resource_span.in_scope(|| {
tracing::trace!(
target: "runtime::resource::state_update",
permits = acquired,
permits.op = "sub",
)
});
if node.assign_permits(&mut acquired) {
self.add_permits_locked(acquired, waiter... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | efe3ab679a05f3da3fcc511a44120239830254f2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/efe3ab679a05f3da3fcc511a44120239830254f2/tokio/src/sync/batch_semaphore.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:13 | drop(old_waker);
Pending
}
}
impl fmt::Debug for Semaphore {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_struct("Semaphore")
.field("permits", &self.available_permits())
.finish()
}
}
impl Waiter {
fn new(
num_permits: u32,
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | efe3ab679a05f3da3fcc511a44120239830254f2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/efe3ab679a05f3da3fcc511a44120239830254f2/tokio/src/sync/batch_semaphore.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:14 | #[cfg(all(tokio_unstable, feature = "tracing"))]
self.ctx.async_op_span.in_scope(|| {
tracing::trace!(
target: "runtime::resource::async_op::state_update",
permits_obtained = assign,
permits.o... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | efe3ab679a05f3da3fcc511a44120239830254f2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/efe3ab679a05f3da3fcc511a44120239830254f2/tokio/src/sync/batch_semaphore.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:15 | Pending => {
*queued = true;
Pending
}
Ready(r) => {
coop.made_progress();
r?;
*queued = false;
Ready(Ok(()))
}
};
#[cfg(all(tokio_unstable, feature = "tracing"))]
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | efe3ab679a05f3da3fcc511a44120239830254f2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/efe3ab679a05f3da3fcc511a44120239830254f2/tokio/src/sync/batch_semaphore.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:16 | tracing::trace!(
target: "runtime::resource::async_op::state_update",
permits_obtained = 0usize,
permits.op = "override",
);
tracing::trace_span!("runtime.resource.async_op.poll")
});
let ctx = trace::A... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | efe3ab679a05f3da3fcc511a44120239830254f2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/efe3ab679a05f3da3fcc511a44120239830254f2/tokio/src/sync/batch_semaphore.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:17 | )
}
}
}
impl Drop for Acquire<'_> {
fn drop(&mut self) {
// If the future is completed, there is no node in the wait list, so we
// can skip acquiring the lock.
if !self.queued {
return;
}
// This is where we ensure safety. The future is being droppe... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | efe3ab679a05f3da3fcc511a44120239830254f2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/efe3ab679a05f3da3fcc511a44120239830254f2/tokio/src/sync/batch_semaphore.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:5 | permits.op = "override",
)
});
resource_span
};
Self {
permits: AtomicUsize::new(permits << Self::PERMIT_SHIFT),
waiters: Mutex::new(Waitlist {
queue: LinkedList::new(),
closed: false,
}),
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | b7290910f7e471f0119ecd717af3a20a2f37fb09 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b7290910f7e471f0119ecd717af3a20a2f37fb09/tokio/src/sync/batch_semaphore.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:6 | /// Returns the current number of available permits.
pub(crate) fn available_permits(&self) -> usize {
self.permits.load(Acquire) >> Self::PERMIT_SHIFT
}
/// Adds `added` new permits to the semaphore.
///
/// The maximum number of permits is `usize::MAX >> 3`, and this function will panic i... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | b7290910f7e471f0119ecd717af3a20a2f37fb09 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b7290910f7e471f0119ecd717af3a20a2f37fb09/tokio/src/sync/batch_semaphore.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:7 | self.permits.load(Acquire) & Self::CLOSED == Self::CLOSED
}
pub(crate) fn try_acquire(&self, num_permits: u32) -> Result<(), TryAcquireError> {
assert!(
num_permits as usize <= Self::MAX_PERMITS,
"a semaphore may not have more than MAX_PERMITS permits ({})",
Self::MA... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | b7290910f7e471f0119ecd717af3a20a2f37fb09 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b7290910f7e471f0119ecd717af3a20a2f37fb09/tokio/src/sync/batch_semaphore.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:8 | ///
/// If `rem` exceeds the number of permits needed by the wait list, the
/// remainder are assigned back to the semaphore.
fn add_permits_locked(&self, mut rem: usize, waiters: MutexGuard<'_, Waitlist>) {
let mut wakers = WakeList::new();
let mut lock = Some(waiters);
let mut is_e... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | b7290910f7e471f0119ecd717af3a20a2f37fb09 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b7290910f7e471f0119ecd717af3a20a2f37fb09/tokio/src/sync/batch_semaphore.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:9 | let prev = prev >> Self::PERMIT_SHIFT;
assert!(
prev + permits <= Self::MAX_PERMITS,
"number of added permits ({}) would overflow MAX_PERMITS ({})",
rem,
Self::MAX_PERMITS
);
// add remaining... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | b7290910f7e471f0119ecd717af3a20a2f37fb09 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b7290910f7e471f0119ecd717af3a20a2f37fb09/tokio/src/sync/batch_semaphore.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:10 | } else {
(num_permits as usize) << Self::PERMIT_SHIFT
};
let mut lock = None;
// First, try to take the requested number of permits from the
// semaphore.
let mut curr = self.permits.load(Acquire);
let mut waiters = loop {
// Has the semaphore clo... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | b7290910f7e471f0119ecd717af3a20a2f37fb09 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b7290910f7e471f0119ecd717af3a20a2f37fb09/tokio/src/sync/batch_semaphore.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:11 | if remaining == 0 {
if !queued {
#[cfg(all(tokio_unstable, feature = "tracing"))]
self.resource_span.in_scope(|| {
tracing::trace!(
target: "runtime::resource::state_update... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | b7290910f7e471f0119ecd717af3a20a2f37fb09 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b7290910f7e471f0119ecd717af3a20a2f37fb09/tokio/src/sync/batch_semaphore.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:12 | if node.assign_permits(&mut acquired) {
self.add_permits_locked(acquired, waiters);
return Ready(Ok(()));
}
assert_eq!(acquired, 0);
let mut old_waker = None;
// Otherwise, register the waker & enqueue the node.
node.waker.with_mut(|waker| {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | b7290910f7e471f0119ecd717af3a20a2f37fb09 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b7290910f7e471f0119ecd717af3a20a2f37fb09/tokio/src/sync/batch_semaphore.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:13 | fmt.debug_struct("Semaphore")
.field("permits", &self.available_permits())
.finish()
}
}
impl Waiter {
fn new(
num_permits: u32,
#[cfg(all(tokio_unstable, feature = "tracing"))] ctx: trace::AsyncOpTracingCtx,
) -> Self {
Waiter {
waker: UnsafeCell... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | b7290910f7e471f0119ecd717af3a20a2f37fb09 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b7290910f7e471f0119ecd717af3a20a2f37fb09/tokio/src/sync/batch_semaphore.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:14 | return next == 0;
}
Err(actual) => curr = actual,
}
}
}
}
impl Future for Acquire<'_> {
type Output = Result<(), AcquireError>;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
#[cfg(all(tokio_unstable, feature = "traci... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | b7290910f7e471f0119ecd717af3a20a2f37fb09 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b7290910f7e471f0119ecd717af3a20a2f37fb09/tokio/src/sync/batch_semaphore.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:15 | Ready(Ok(()))
}
};
#[cfg(all(tokio_unstable, feature = "tracing"))]
return trace_poll_op!("poll_acquire", result);
#[cfg(not(all(tokio_unstable, feature = "tracing")))]
return result;
}
}
impl<'a> Acquire<'a> {
fn new(semaphore: &'a Semaphore, num_permits: ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | b7290910f7e471f0119ecd717af3a20a2f37fb09 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b7290910f7e471f0119ecd717af3a20a2f37fb09/tokio/src/sync/batch_semaphore.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:16 | });
let ctx = trace::AsyncOpTracingCtx {
async_op_span,
async_op_poll_span,
resource_span: semaphore.resource_span.clone(),
};
Self {
node: Waiter::new(num_permits, ctx),
semaphore,
num_... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | b7290910f7e471f0119ecd717af3a20a2f37fb09 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b7290910f7e471f0119ecd717af3a20a2f37fb09/tokio/src/sync/batch_semaphore.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:17 | // can skip acquiring the lock.
if !self.queued {
return;
}
// This is where we ensure safety. The future is being dropped,
// which means we must ensure that the waiter entry is no longer stored
// in the linked list.
let mut waiters = self.semaphore.waiters... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | b7290910f7e471f0119ecd717af3a20a2f37fb09 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b7290910f7e471f0119ecd717af3a20a2f37fb09/tokio/src/sync/batch_semaphore.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:18 | }
}
impl std::error::Error for AcquireError {}
// ===== impl TryAcquireError =====
impl TryAcquireError {
/// Returns `true` if the error was caused by a closed semaphore.
#[allow(dead_code)] // may be used later!
pub(crate) fn is_closed(&self) -> bool {
matches!(self, TryAcquireError::Closed)
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | b7290910f7e471f0119ecd717af3a20a2f37fb09 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b7290910f7e471f0119ecd717af3a20a2f37fb09/tokio/src/sync/batch_semaphore.rs | 681 | 732 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:19 | fn as_raw(handle: &Self::Handle) -> 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(target)
}
} | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | b7290910f7e471f0119ecd717af3a20a2f37fb09 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b7290910f7e471f0119ecd717af3a20a2f37fb09/tokio/src/sync/batch_semaphore.rs | 721 | 732 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:7 | self.permits.load(Acquire) & Self::CLOSED == Self::CLOSED
}
pub(crate) fn try_acquire(&self, num_permits: u32) -> Result<(), TryAcquireError> {
assert!(
num_permits as usize <= Self::MAX_PERMITS,
"a semaphore may not have more than MAX_PERMITS permits ({})",
Self::MA... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | 901f6d26c6aefd25a8f180e7a12ea8ed3c88ace2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/901f6d26c6aefd25a8f180e7a12ea8ed3c88ace2/tokio/src/sync/batch_semaphore.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:11 | if remaining == 0 {
if !queued {
#[cfg(all(tokio_unstable, feature = "tracing"))]
self.resource_span.in_scope(|| {
tracing::trace!(
target: "runtime::resource::state_update... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | fc9518b62714daac9a38b46c698b94ac5d5b1ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fc9518b62714daac9a38b46c698b94ac5d5b1ca2/tokio/src/sync/batch_semaphore.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:12 | if node.assign_permits(&mut acquired) {
self.add_permits_locked(acquired, waiters);
return Ready(Ok(()));
}
assert_eq!(acquired, 0);
// Otherwise, register the waker & enqueue the node.
node.waker.with_mut(|waker| {
// Safety: the wait list is locked... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | fc9518b62714daac9a38b46c698b94ac5d5b1ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fc9518b62714daac9a38b46c698b94ac5d5b1ca2/tokio/src/sync/batch_semaphore.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:13 | }
}
impl Waiter {
fn new(
num_permits: u32,
#[cfg(all(tokio_unstable, feature = "tracing"))] ctx: trace::AsyncOpTracingCtx,
) -> Self {
Waiter {
waker: UnsafeCell::new(None),
state: AtomicUsize::new(num_permits as usize),
pointers: linked_list::Pointe... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | fc9518b62714daac9a38b46c698b94ac5d5b1ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fc9518b62714daac9a38b46c698b94ac5d5b1ca2/tokio/src/sync/batch_semaphore.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:14 | }
}
}
}
impl Future for Acquire<'_> {
type Output = Result<(), AcquireError>;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
#[cfg(all(tokio_unstable, feature = "tracing"))]
let _resource_span = self.node.ctx.resource_span.clone().entered();
#[c... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | fc9518b62714daac9a38b46c698b94ac5d5b1ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fc9518b62714daac9a38b46c698b94ac5d5b1ca2/tokio/src/sync/batch_semaphore.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:15 | #[cfg(all(tokio_unstable, feature = "tracing"))]
return trace_poll_op!("poll_acquire", result);
#[cfg(not(all(tokio_unstable, feature = "tracing")))]
return result;
}
}
impl<'a> Acquire<'a> {
fn new(semaphore: &'a Semaphore, num_permits: u32) -> Self {
#[cfg(any(not(tokio_unsta... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | fc9518b62714daac9a38b46c698b94ac5d5b1ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fc9518b62714daac9a38b46c698b94ac5d5b1ca2/tokio/src/sync/batch_semaphore.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:16 | async_op_span,
async_op_poll_span,
resource_span: semaphore.resource_span.clone(),
};
Self {
node: Waiter::new(num_permits, ctx),
semaphore,
num_permits,
queued: false,
}
});
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | fc9518b62714daac9a38b46c698b94ac5d5b1ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fc9518b62714daac9a38b46c698b94ac5d5b1ca2/tokio/src/sync/batch_semaphore.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:17 | }
// This is where we ensure safety. The future is being dropped,
// which means we must ensure that the waiter entry is no longer stored
// in the linked list.
let mut waiters = self.semaphore.waiters.lock();
// remove the entry from the list
let node = NonNull::from(&... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | fc9518b62714daac9a38b46c698b94ac5d5b1ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fc9518b62714daac9a38b46c698b94ac5d5b1ca2/tokio/src/sync/batch_semaphore.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:18 | impl std::error::Error for AcquireError {}
// ===== impl TryAcquireError =====
impl TryAcquireError {
/// Returns `true` if the error was caused by a closed semaphore.
#[allow(dead_code)] // may be used later!
pub(crate) fn is_closed(&self) -> bool {
matches!(self, TryAcquireError::Closed)
}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | fc9518b62714daac9a38b46c698b94ac5d5b1ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fc9518b62714daac9a38b46c698b94ac5d5b1ca2/tokio/src/sync/batch_semaphore.rs | 681 | 729 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:1 | #![cfg_attr(not(feature = "sync"), allow(unreachable_pub, dead_code))]
//! # Implementation Details.
//!
//! The semaphore is implemented using an intrusive linked list of waiters. An
//! atomic counter tracks the number of available permits. If the semaphore does
//! not contain the required number of permits, the tas... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | a051ed726f3b99b077e8c9ef8ef1df2ab2943213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a051ed726f3b99b077e8c9ef8ef1df2ab2943213/tokio/src/sync/batch_semaphore.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:2 | resource_span: tracing::Span,
}
struct Waitlist {
queue: LinkedList<Waiter, <Waiter as linked_list::Link>::Target>,
closed: bool,
}
/// Error returned from the [`Semaphore::try_acquire`] function.
///
/// [`Semaphore::try_acquire`]: crate::sync::Semaphore::try_acquire
#[derive(Debug, PartialEq)]
pub enum TryA... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | a051ed726f3b99b077e8c9ef8ef1df2ab2943213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a051ed726f3b99b077e8c9ef8ef1df2ab2943213/tokio/src/sync/batch_semaphore.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:14 | }
}
}
}
impl Future for Acquire<'_> {
type Output = Result<(), AcquireError>;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
#[cfg(all(tokio_unstable, feature = "tracing"))]
let _resource_span = self.node.ctx.resource_span.clone().entered();
#[c... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | 6f048ca954aa5f285f1cf6310d447e7c079c1c3d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6f048ca954aa5f285f1cf6310d447e7c079c1c3d/tokio/src/sync/batch_semaphore.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:3 | /// The current state of the waiter.
///
/// This is either the number of remaining permits required by
/// the waiter, or a flag indicating that the waiter is not yet queued.
state: AtomicUsize,
/// The waker to notify the task awaiting permits.
///
/// # Safety
///
/// This may on... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | dee26c92ddb32e23acb0c1587e775ddab29e07f9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/dee26c92ddb32e23acb0c1587e775ddab29e07f9/tokio/src/sync/batch_semaphore.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:4 | /// avoid a breaking change if additional flags need to be added in the
/// future.
pub(crate) const MAX_PERMITS: usize = std::usize::MAX >> 3;
const CLOSED: usize = 1;
// The least-significant bit in the number of permits is reserved to use
// as a flag indicating that the semaphore has been closed... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | dee26c92ddb32e23acb0c1587e775ddab29e07f9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/dee26c92ddb32e23acb0c1587e775ddab29e07f9/tokio/src/sync/batch_semaphore.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:5 | waiters: Mutex::new(Waitlist {
queue: LinkedList::new(),
closed: false,
}),
#[cfg(all(tokio_unstable, feature = "tracing"))]
resource_span,
}
}
/// Creates a new semaphore with the initial number of permits.
///
/// Maximum num... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | dee26c92ddb32e23acb0c1587e775ddab29e07f9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/dee26c92ddb32e23acb0c1587e775ddab29e07f9/tokio/src/sync/batch_semaphore.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:6 | pub(crate) fn release(&self, added: usize) {
if added == 0 {
return;
}
// Assign permits to the wait queue
self.add_permits_locked(added, self.waiters.lock());
}
/// Closes the semaphore. This prevents the semaphore from issuing new
/// permits and notifies all ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | dee26c92ddb32e23acb0c1587e775ddab29e07f9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/dee26c92ddb32e23acb0c1587e775ddab29e07f9/tokio/src/sync/batch_semaphore.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:7 | );
let num_permits = (num_permits as usize) << Self::PERMIT_SHIFT;
let mut curr = self.permits.load(Acquire);
loop {
// Has the semaphore closed?
if curr & Self::CLOSED == Self::CLOSED {
return Err(TryAcquireError::Closed);
}
// Ar... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | dee26c92ddb32e23acb0c1587e775ddab29e07f9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/dee26c92ddb32e23acb0c1587e775ddab29e07f9/tokio/src/sync/batch_semaphore.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:8 | let mut waiters = lock.take().unwrap_or_else(|| self.waiters.lock());
'inner: while wakers.can_push() {
// Was the waiter assigned enough permits to wake it?
match waiters.queue.last() {
Some(waiter) => {
if !waiter.assign_permits(&... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | dee26c92ddb32e23acb0c1587e775ddab29e07f9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/dee26c92ddb32e23acb0c1587e775ddab29e07f9/tokio/src/sync/batch_semaphore.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:9 | // add remaining permits back
#[cfg(all(tokio_unstable, feature = "tracing"))]
self.resource_span.in_scope(|| {
tracing::trace!(
target: "runtime::resource::state_update",
permits = rem,
permits.op = "add",
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | dee26c92ddb32e23acb0c1587e775ddab29e07f9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/dee26c92ddb32e23acb0c1587e775ddab29e07f9/tokio/src/sync/batch_semaphore.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:10 | let mut waiters = loop {
// Has the semaphore closed?
if curr & Self::CLOSED > 0 {
return Ready(Err(AcquireError::closed()));
}
let mut remaining = 0;
let total = curr
.checked_add(acquired)
.expect("number of p... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | dee26c92ddb32e23acb0c1587e775ddab29e07f9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/dee26c92ddb32e23acb0c1587e775ddab29e07f9/tokio/src/sync/batch_semaphore.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:11 | );
tracing::trace!(
target: "runtime::resource::async_op::state_update",
permits_obtained = acquired,
permits.op = "add",
)
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | dee26c92ddb32e23acb0c1587e775ddab29e07f9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/dee26c92ddb32e23acb0c1587e775ddab29e07f9/tokio/src/sync/batch_semaphore.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:12 | node.waker.with_mut(|waker| {
// Safety: the wait list is locked, so we may modify the waker.
let waker = unsafe { &mut *waker };
// Do we need to register the new waker?
if waker
.as_ref()
.map(|waker| !waker.will_wake(cx.waker()))
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | dee26c92ddb32e23acb0c1587e775ddab29e07f9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/dee26c92ddb32e23acb0c1587e775ddab29e07f9/tokio/src/sync/batch_semaphore.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:13 | Waiter {
waker: UnsafeCell::new(None),
state: AtomicUsize::new(num_permits as usize),
pointers: linked_list::Pointers::new(),
#[cfg(all(tokio_unstable, feature = "tracing"))]
ctx,
_p: PhantomPinned,
}
}
/// Assign permits to the wa... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | dee26c92ddb32e23acb0c1587e775ddab29e07f9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/dee26c92ddb32e23acb0c1587e775ddab29e07f9/tokio/src/sync/batch_semaphore.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:14 | fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
#[cfg(all(tokio_unstable, feature = "tracing"))]
let _resource_span = self.node.ctx.resource_span.clone().entered();
#[cfg(all(tokio_unstable, feature = "tracing"))]
let _async_op_span = self.node.ctx.async_op_sp... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | dee26c92ddb32e23acb0c1587e775ddab29e07f9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/dee26c92ddb32e23acb0c1587e775ddab29e07f9/tokio/src/sync/batch_semaphore.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:15 | impl<'a> Acquire<'a> {
fn new(semaphore: &'a Semaphore, num_permits: u32) -> Self {
#[cfg(any(not(tokio_unstable), not(feature = "tracing")))]
return Self {
node: Waiter::new(num_permits),
semaphore,
num_permits,
queued: false,
};
#[cf... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | dee26c92ddb32e23acb0c1587e775ddab29e07f9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/dee26c92ddb32e23acb0c1587e775ddab29e07f9/tokio/src/sync/batch_semaphore.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:16 | num_permits,
queued: false,
}
});
}
fn project(self: Pin<&mut Self>) -> (Pin<&mut Waiter>, &Semaphore, u32, &mut bool) {
fn is_unpin<T: Unpin>() {}
unsafe {
// Safety: all fields other than `node` are `Unpin`
is_unpin::<&Semaphore>();... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | dee26c92ddb32e23acb0c1587e775ddab29e07f9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/dee26c92ddb32e23acb0c1587e775ddab29e07f9/tokio/src/sync/batch_semaphore.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:17 | let node = NonNull::from(&mut self.node);
// Safety: we have locked the wait list.
unsafe { waiters.queue.remove(node) };
let acquired_permits = self.num_permits as usize - self.node.state.load(Acquire);
if acquired_permits > 0 {
self.semaphore.add_permits_locked(acquired_pe... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | dee26c92ddb32e23acb0c1587e775ddab29e07f9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/dee26c92ddb32e23acb0c1587e775ddab29e07f9/tokio/src/sync/batch_semaphore.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:18 | matches!(self, TryAcquireError::Closed)
}
/// Returns `true` if the error was caused by calling `try_acquire` on a
/// semaphore with no available permits.
#[allow(dead_code)] // may be used later!
pub(crate) fn is_no_permits(&self) -> bool {
matches!(self, TryAcquireError::NoPermits)
}... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | dee26c92ddb32e23acb0c1587e775ddab29e07f9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/dee26c92ddb32e23acb0c1587e775ddab29e07f9/tokio/src/sync/batch_semaphore.rs | 681 | 727 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:15 | impl<'a> Acquire<'a> {
fn new(semaphore: &'a Semaphore, num_permits: u32) -> Self {
#[cfg(any(not(tokio_unstable), not(feature = "tracing")))]
return Self {
node: Waiter::new(num_permits),
semaphore,
num_permits,
queued: false,
};
#[cf... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | 4e3268d222423e874f5bbfa67e20f773da3c025f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4e3268d222423e874f5bbfa67e20f773da3c025f/tokio/src/sync/batch_semaphore.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:1 | #![cfg_attr(not(feature = "sync"), allow(unreachable_pub, dead_code))]
//! # Implementation Details.
//!
//! The semaphore is implemented using an intrusive linked list of waiters. An
//! atomic counter tracks the number of available permits. If the semaphore does
//! not contain the required number of permits, the tas... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | 03969cdae7674681d1b10926e6a56fbb8908dbb8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/sync/batch_semaphore.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:2 | queue: LinkedList<Waiter, <Waiter as linked_list::Link>::Target>,
closed: bool,
}
/// Error returned from the [`Semaphore::try_acquire`] function.
///
/// [`Semaphore::try_acquire`]: crate::sync::Semaphore::try_acquire
#[derive(Debug, PartialEq)]
pub enum TryAcquireError {
/// The semaphore has been [closed] a... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | 03969cdae7674681d1b10926e6a56fbb8908dbb8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/sync/batch_semaphore.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:3 | state: AtomicUsize,
/// The waker to notify the task awaiting permits.
///
/// # Safety
///
/// This may only be accessed while the wait queue is locked.
waker: UnsafeCell<Option<Waker>>,
/// Intrusive linked-list pointers.
///
/// # Safety
///
/// This may only be accessed... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | 03969cdae7674681d1b10926e6a56fbb8908dbb8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/sync/batch_semaphore.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:4 | const PERMIT_SHIFT: usize = 1;
/// Creates a new semaphore with the initial number of permits
///
/// Maximum number of permits on 32-bit platforms is `1<<29`.
pub(crate) fn new(permits: usize) -> Self {
assert!(
permits <= Self::MAX_PERMITS,
"a semaphore may not have mo... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | 03969cdae7674681d1b10926e6a56fbb8908dbb8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/sync/batch_semaphore.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:5 | /// Returns the current number of available permits.
pub(crate) fn available_permits(&self) -> usize {
self.permits.load(Acquire) >> Self::PERMIT_SHIFT
}
/// Adds `added` new permits to the semaphore.
///
/// The maximum number of permits is `usize::MAX >> 3`, and this function will panic i... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | 03969cdae7674681d1b10926e6a56fbb8908dbb8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/sync/batch_semaphore.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:6 | pub(crate) fn is_closed(&self) -> bool {
self.permits.load(Acquire) & Self::CLOSED == Self::CLOSED
}
pub(crate) fn try_acquire(&self, num_permits: u32) -> Result<(), TryAcquireError> {
assert!(
num_permits as usize <= Self::MAX_PERMITS,
"a semaphore may not have more tha... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | 03969cdae7674681d1b10926e6a56fbb8908dbb8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/sync/batch_semaphore.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:7 | /// remainder are assigned back to the semaphore.
fn add_permits_locked(&self, mut rem: usize, waiters: MutexGuard<'_, Waitlist>) {
let mut wakers = WakeList::new();
let mut lock = Some(waiters);
let mut is_empty = false;
while rem > 0 {
let mut waiters = lock.take().unwr... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | 03969cdae7674681d1b10926e6a56fbb8908dbb8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/sync/batch_semaphore.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:8 | prev + permits <= Self::MAX_PERMITS,
"number of added permits ({}) would overflow MAX_PERMITS ({})",
rem,
Self::MAX_PERMITS
);
rem = 0;
}
drop(waiters); // release the lock
wakers.wake_all()... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | 03969cdae7674681d1b10926e6a56fbb8908dbb8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/sync/batch_semaphore.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:9 | let mut remaining = 0;
let total = curr
.checked_add(acquired)
.expect("number of permits must not overflow");
let (next, acq) = if total >= needed {
let next = curr - (needed - acquired);
(next, needed >> Self::PERMIT_SHIFT)
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | 03969cdae7674681d1b10926e6a56fbb8908dbb8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/sync/batch_semaphore.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:10 | if waiters.closed {
return Ready(Err(AcquireError::closed()));
}
if node.assign_permits(&mut acquired) {
self.add_permits_locked(acquired, waiters);
return Ready(Ok(()));
}
assert_eq!(acquired, 0);
// Otherwise, register the waker & enqueue ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | 03969cdae7674681d1b10926e6a56fbb8908dbb8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/sync/batch_semaphore.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:11 | fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_struct("Semaphore")
.field("permits", &self.available_permits())
.finish()
}
}
impl Waiter {
fn new(num_permits: u32) -> Self {
Waiter {
waker: UnsafeCell::new(None),
state: At... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | 03969cdae7674681d1b10926e6a56fbb8908dbb8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/sync/batch_semaphore.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:12 | // First, ensure the current task has enough budget to proceed.
let coop = ready!(crate::coop::poll_proceed(cx));
let (node, semaphore, needed, queued) = self.project();
match semaphore.poll_acquire(cx, needed, node, *queued) {
Pending => {
*queued = true;
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | 03969cdae7674681d1b10926e6a56fbb8908dbb8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/sync/batch_semaphore.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:13 | (
Pin::new_unchecked(&mut this.node),
this.semaphore,
this.num_permits,
&mut this.queued,
)
}
}
}
impl Drop for Acquire<'_> {
fn drop(&mut self) {
// If the future is completed, there is no node in the wait list, so we
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | 03969cdae7674681d1b10926e6a56fbb8908dbb8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/sync/batch_semaphore.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:14 | unsafe impl Sync for Acquire<'_> {}
// ===== impl AcquireError ====
impl AcquireError {
fn closed() -> AcquireError {
AcquireError(())
}
}
impl fmt::Display for AcquireError {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(fmt, "semaphore closed")
}
}
impl std::e... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | 03969cdae7674681d1b10926e6a56fbb8908dbb8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/sync/batch_semaphore.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:15 | }
}
}
impl std::error::Error for TryAcquireError {}
/// # Safety
///
/// `Waiter` is forced to be !Unpin.
unsafe impl linked_list::Link for Waiter {
// XXX: ideally, we would be able to use `Pin` here, to enforce the
// invariant that list entries may not move while in the list. However, we
// can't d... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | 03969cdae7674681d1b10926e6a56fbb8908dbb8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/sync/batch_semaphore.rs | 561 | 591 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:1 | #![cfg_attr(not(feature = "sync"), allow(unreachable_pub, dead_code))]
//! # Implementation Details
//!
//! The semaphore is implemented using an intrusive linked list of waiters. An
//! atomic counter tracks the number of available permits. If the semaphore does
//! not contain the required number of permits, the task... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | 1e2e38b7cdf4c9f51a0034469c8553d995af1383 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1e2e38b7cdf4c9f51a0034469c8553d995af1383/tokio/src/sync/batch_semaphore.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:4 | const PERMIT_SHIFT: usize = 1;
/// Creates a new semaphore with the initial number of permits
///
/// Maximum number of permits on 32-bit platforms is `1<<29`.
pub(crate) fn new(permits: usize) -> Self {
assert!(
permits <= Self::MAX_PERMITS,
"a semaphore may not have mo... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | 1e2e38b7cdf4c9f51a0034469c8553d995af1383 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1e2e38b7cdf4c9f51a0034469c8553d995af1383/tokio/src/sync/batch_semaphore.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:5 | /// Returns the current number of available permits
pub(crate) fn available_permits(&self) -> usize {
self.permits.load(Acquire) >> Self::PERMIT_SHIFT
}
/// Adds `added` new permits to the semaphore.
///
/// The maximum number of permits is `usize::MAX >> 3`, and this function will panic if... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | 1e2e38b7cdf4c9f51a0034469c8553d995af1383 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1e2e38b7cdf4c9f51a0034469c8553d995af1383/tokio/src/sync/batch_semaphore.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:1 | #![cfg_attr(not(feature = "sync"), allow(unreachable_pub, dead_code))]
//! # Implementation Details
//!
//! The semaphore is implemented using an intrusive linked list of waiters. An
//! atomic counter tracks the number of available permits. If the semaphore does
//! not contain the required number of permits, the task... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | 8198ef38814c45f9dc02fcbf826225b5cf32a6bb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8198ef38814c45f9dc02fcbf826225b5cf32a6bb/tokio/src/sync/batch_semaphore.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:2 | closed: bool,
}
/// Error returned from the [`Semaphore::try_acquire`] function.
///
/// [`Semaphore::try_acquire`]: crate::sync::Semaphore::try_acquire
#[derive(Debug, PartialEq)]
pub enum TryAcquireError {
/// The semaphore has been [closed] and cannot issue new permits.
///
/// [closed]: crate::sync::Se... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | 8198ef38814c45f9dc02fcbf826225b5cf32a6bb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8198ef38814c45f9dc02fcbf826225b5cf32a6bb/tokio/src/sync/batch_semaphore.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:3 | /// The waker to notify the task awaiting permits.
///
/// # Safety
///
/// This may only be accessed while the wait queue is locked.
waker: UnsafeCell<Option<Waker>>,
/// Intrusive linked-list pointers.
///
/// # Safety
///
/// This may only be accessed while the wait queue is ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | 8198ef38814c45f9dc02fcbf826225b5cf32a6bb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8198ef38814c45f9dc02fcbf826225b5cf32a6bb/tokio/src/sync/batch_semaphore.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:4 | /// Creates a new semaphore with the initial number of permits
///
/// Maximum number of permits on 32-bit platforms is `1<<29`.
pub(crate) fn new(permits: usize) -> Self {
assert!(
permits <= Self::MAX_PERMITS,
"a semaphore may not have more than MAX_PERMITS permits ({})",
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | 8198ef38814c45f9dc02fcbf826225b5cf32a6bb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8198ef38814c45f9dc02fcbf826225b5cf32a6bb/tokio/src/sync/batch_semaphore.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:5 | /// Returns the current number of available permits
pub(crate) fn available_permits(&self) -> usize {
self.permits.load(Acquire) >> Self::PERMIT_SHIFT
}
/// Adds `added` new permits to the semaphore.
///
/// The maximum number of permits is `usize::MAX >> 3`, and this function will panic if... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | 8198ef38814c45f9dc02fcbf826225b5cf32a6bb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8198ef38814c45f9dc02fcbf826225b5cf32a6bb/tokio/src/sync/batch_semaphore.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:6 | self.permits.load(Acquire) & Self::CLOSED == Self::CLOSED
}
pub(crate) fn try_acquire(&self, num_permits: u32) -> Result<(), TryAcquireError> {
assert!(
num_permits as usize <= Self::MAX_PERMITS,
"a semaphore may not have more than MAX_PERMITS permits ({})",
Self::MA... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | 8198ef38814c45f9dc02fcbf826225b5cf32a6bb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8198ef38814c45f9dc02fcbf826225b5cf32a6bb/tokio/src/sync/batch_semaphore.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:7 | fn add_permits_locked(&self, mut rem: usize, waiters: MutexGuard<'_, Waitlist>) {
let mut wakers: [Option<Waker>; 8] = Default::default();
let mut lock = Some(waiters);
let mut is_empty = false;
while rem > 0 {
let mut waiters = lock.take().unwrap_or_else(|| self.waiters.lock... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | 8198ef38814c45f9dc02fcbf826225b5cf32a6bb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8198ef38814c45f9dc02fcbf826225b5cf32a6bb/tokio/src/sync/batch_semaphore.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:8 | rem = 0;
}
drop(waiters); // release the lock
wakers
.iter_mut()
.filter_map(Option::take)
.for_each(Waker::wake);
}
assert_eq!(rem, 0);
}
fn poll_acquire(
&self,
cx: &mut Context<'_>,
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | 8198ef38814c45f9dc02fcbf826225b5cf32a6bb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8198ef38814c45f9dc02fcbf826225b5cf32a6bb/tokio/src/sync/batch_semaphore.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:9 | let total = curr
.checked_add(acquired)
.expect("number of permits must not overflow");
let (next, acq) = if total >= needed {
let next = curr - (needed - acquired);
(next, needed >> Self::PERMIT_SHIFT)
} else {
rema... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | 8198ef38814c45f9dc02fcbf826225b5cf32a6bb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8198ef38814c45f9dc02fcbf826225b5cf32a6bb/tokio/src/sync/batch_semaphore.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:10 | }
if node.assign_permits(&mut acquired) {
self.add_permits_locked(acquired, waiters);
return Ready(Ok(()));
}
assert_eq!(acquired, 0);
// Otherwise, register the waker & enqueue the node.
node.waker.with_mut(|waker| {
// Safety: the wait lis... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | 8198ef38814c45f9dc02fcbf826225b5cf32a6bb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8198ef38814c45f9dc02fcbf826225b5cf32a6bb/tokio/src/sync/batch_semaphore.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:11 | .field("permits", &self.available_permits())
.finish()
}
}
impl Waiter {
fn new(num_permits: u32) -> Self {
Waiter {
waker: UnsafeCell::new(None),
state: AtomicUsize::new(num_permits as usize),
pointers: linked_list::Pointers::new(),
_p: Phant... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | 8198ef38814c45f9dc02fcbf826225b5cf32a6bb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8198ef38814c45f9dc02fcbf826225b5cf32a6bb/tokio/src/sync/batch_semaphore.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:12 | let (node, semaphore, needed, queued) = self.project();
match semaphore.poll_acquire(cx, needed, node, *queued) {
Pending => {
*queued = true;
Pending
}
Ready(r) => {
coop.made_progress();
r?;
*q... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | 8198ef38814c45f9dc02fcbf826225b5cf32a6bb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8198ef38814c45f9dc02fcbf826225b5cf32a6bb/tokio/src/sync/batch_semaphore.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:13 | this.semaphore,
this.num_permits,
&mut this.queued,
)
}
}
}
impl Drop for Acquire<'_> {
fn drop(&mut self) {
// If the future is completed, there is no node in the wait list, so we
// can skip acquiring the lock.
if !self.queued {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | 8198ef38814c45f9dc02fcbf826225b5cf32a6bb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8198ef38814c45f9dc02fcbf826225b5cf32a6bb/tokio/src/sync/batch_semaphore.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:14 | // ===== impl AcquireError ====
impl AcquireError {
fn closed() -> AcquireError {
AcquireError(())
}
}
impl fmt::Display for AcquireError {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(fmt, "semaphore closed")
}
}
impl std::error::Error for AcquireError {}
// =... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | 8198ef38814c45f9dc02fcbf826225b5cf32a6bb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8198ef38814c45f9dc02fcbf826225b5cf32a6bb/tokio/src/sync/batch_semaphore.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:15 | }
impl std::error::Error for TryAcquireError {}
/// # Safety
///
/// `Waiter` is forced to be !Unpin.
unsafe impl linked_list::Link for Waiter {
// XXX: ideally, we would be able to use `Pin` here, to enforce the
// invariant that list entries may not move while in the list. However, we
// can't do this c... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | 8198ef38814c45f9dc02fcbf826225b5cf32a6bb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8198ef38814c45f9dc02fcbf826225b5cf32a6bb/tokio/src/sync/batch_semaphore.rs | 561 | 589 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:12 | let (node, semaphore, needed, queued) = self.project();
match semaphore.poll_acquire(cx, needed, node, *queued) {
Pending => {
*queued = true;
Pending
}
Ready(r) => {
coop.made_progress();
r?;
*q... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | e89c8981f151a667bb676213d38b7dbeb51620e9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e89c8981f151a667bb676213d38b7dbeb51620e9/tokio/src/sync/batch_semaphore.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:13 | &this.semaphore,
this.num_permits,
&mut this.queued,
)
}
}
}
impl Drop for Acquire<'_> {
fn drop(&mut self) {
// If the future is completed, there is no node in the wait list, so we
// can skip acquiring the lock.
if !self.queued {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | e89c8981f151a667bb676213d38b7dbeb51620e9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e89c8981f151a667bb676213d38b7dbeb51620e9/tokio/src/sync/batch_semaphore.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:7 | fn add_permits_locked(&self, mut rem: usize, waiters: MutexGuard<'_, Waitlist>) {
let mut wakers: [Option<Waker>; 8] = Default::default();
let mut lock = Some(waiters);
let mut is_empty = false;
while rem > 0 {
let mut waiters = lock.take().unwrap_or_else(|| self.waiters.lock... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | ce0e9c67cfe61c7a91a284331ecc53fa01c32879 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ce0e9c67cfe61c7a91a284331ecc53fa01c32879/tokio/src/sync/batch_semaphore.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:8 | }
drop(waiters); // release the lock
wakers
.iter_mut()
.filter_map(Option::take)
.for_each(Waker::wake);
}
assert_eq!(rem, 0);
}
fn poll_acquire(
&self,
cx: &mut Context<'_>,
num_permits: u32,
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/batch_semaphore.rs | MIT | ce0e9c67cfe61c7a91a284331ecc53fa01c32879 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ce0e9c67cfe61c7a91a284331ecc53fa01c32879/tokio/src/sync/batch_semaphore.rs | 281 | 340 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.