You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@asyncband.apache.org by ti...@apache.org on 2026/09/04 06:58:30 UTC
(asyncband) branch main updated: fix: preserve third-party source licensing (#279)
This is an automated email from the ASF dual-hosted git repository.
tisonkun pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/asyncband.git
The following commit(s) were added to refs/heads/main by this push:
new 5c34751 fix: preserve third-party source licensing (#279)
5c34751 is described below
commit 5c347517b391d9614e473dfe265129e66f330434
Author: tison <wa...@gmail.com>
AuthorDate: Fri Sep 4 14:58:26 2026 +0800
fix: preserve third-party source licensing (#279)
---
CHANGELOG.md | 4 +
HISTORY.md | 17 --
LICENSE | 254 ++++++++++++++---
README.md | 6 +-
asyncband/HISTORY.md | 1 -
asyncband/src/barrier/mod.rs | 15 +-
asyncband/src/blocking/executor.rs | 89 ++++++
asyncband/src/blocking/mod.rs | 80 +-----
asyncband/src/blocking/parker.rs | 6 +-
asyncband/src/broadcast/mpmc/unbounded/mod.rs | 304 ++++++++++-----------
asyncband/src/internal/atomic_waker.rs | 6 +-
asyncband/src/internal/semaphore.rs | 9 +
asyncband/src/internal/value_cell.rs | 8 +
asyncband/src/mpsc/bounded.rs | 129 +++------
asyncband/src/mpsc/error.rs | 10 +-
asyncband/src/mpsc/unbounded.rs | 105 +++----
asyncband/src/mutex/mod.rs | 23 +-
asyncband/src/once/once_cell/mod.rs | 9 +
asyncband/src/once/once_map/mod.rs | 4 +-
asyncband/src/oneshot/mod.rs | 8 +-
asyncband/src/oneshot/receiver.rs | 9 +-
asyncband/src/oneshot/sender.rs | 9 +-
asyncband/src/oneshot/tests.rs | 9 +-
asyncband/src/pool/bounded.rs | 34 ++-
asyncband/src/pool/common.rs | 34 ++-
asyncband/src/pool/mod.rs | 34 ++-
asyncband/src/pool/state.rs | 35 ++-
asyncband/src/pool/unbounded.rs | 38 ++-
asyncband/src/rwlock/mapped_read_guard.rs | 26 +-
asyncband/src/rwlock/mapped_write_guard.rs | 25 +-
asyncband/src/rwlock/mod.rs | 23 +-
asyncband/src/rwlock/owned_mapped_read_guard.rs | 26 +-
asyncband/src/rwlock/owned_mapped_write_guard.rs | 25 +-
asyncband/src/rwlock/owned_read_guard.rs | 25 +-
asyncband/src/rwlock/owned_write_guard.rs | 25 +-
asyncband/src/rwlock/read_guard.rs | 25 +-
asyncband/src/rwlock/write_guard.rs | 25 +-
asyncband/src/semaphore/mod.rs | 9 +
licenserc.toml | 25 +-
tests-integration/tests/oneshot_test/main.rs | 13 +-
tests-integration/tests/oneshot_test/support.rs | 9 +-
.../tests/pool_recycle_cancelled_test.rs | 34 ++-
tests-integration/tests/pool_replenish_test.rs | 34 ++-
43 files changed, 814 insertions(+), 824 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 141417e..a2955d9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
## Unreleased
+### Improvements
+
+* Preserve applicable third-party licensing and copyright notices on derived source files, and record exact provenance mappings and design acknowledgements in `LICENSE` and source comments.
+
## v0.7.1
This is an interim non-ASF release. It has not been approved by the Apache Incubator PMC and is not an act of the Apache Software Foundation.
diff --git a/HISTORY.md b/HISTORY.md
deleted file mode 100644
index 51da90a..0000000
--- a/HISTORY.md
+++ /dev/null
@@ -1,17 +0,0 @@
-# History
-
-Asyncband collects composable, runtime-agnostic concurrency building blocks informed by several existing implementations. Only components that draw on external designs or code are listed here. The terms `derived`, `adapted`, and `ported` identify incorporated source code; `inspired`, `informed`, and `reimplementation` identify independent implementations drawing on designs or APIs. See [LICENSE](LICENSE) for the governing terms and exact file scope of incorporated third-party code.
-
-- `barrier::Barrier` is inspired by [`std::sync::Barrier`](https://doc.rust-lang.org/std/sync/struct.Barrier.html) and [`tokio::sync::Barrier`](https://docs.rs/tokio/latest/tokio/sync/struct.Barrier.html), with a different implementation based on the internal `WaitSet` primitive.
-- The single-future polling loop in `blocking` is adapted from [`pollster` 1.0.1](https://github.com/zesterer/pollster/blob/6a1a148208326e9c5b231b16f199f5227c550774/src/lib.rs), its reuse of a thread-local `Parker`/`Waker` pair with a fresh pair for recursive calls is adapted from [`futures-lite` 2.6.1](https://github.com/smol-rs/futures-lite/blob/226ce18976d8714d6bd9700b61dcc81d7200bc9a/src/future.rs#L62-L91), and its private parker state machine is adapted from [`parking` 2.2.1](https: [...]
-- `condvar::Condvar` is inspired by [`std::sync::Condvar`](https://doc.rust-lang.org/std/sync/struct.Condvar.html) and [`async_std::sync::Condvar`](https://docs.rs/async-std/latest/async_std/sync/struct.Condvar.html), with a fair FIFO waiter queue and standard non-buffered notification semantics.
-- `latch::Latch` is inspired by [`latches`](https://github.com/mirromutth/latches), with a different implementation based on the internal `CountdownState` primitive.
-- `mutex::Mutex` is derived from [`tokio::sync::Mutex` in Tokio 1.41.0](https://github.com/tokio-rs/tokio/blob/01e04daaa162ce6122bb894fdda0b6803dd32093/tokio/src/sync/mutex.rs).
-- The internal `AtomicWaker` state machine is derived from [`futures-rs` 0.3.34](https://github.com/rust-lang/futures-rs/blob/705e6b5c0f06535b1aac1cb1989a172b3d45be8c/futures-core/src/task/__internal/atomic_waker.rs), with panic recovery informed by [`tokio::sync::task::AtomicWaker`](https://github.com/tokio-rs/tokio/blob/75fef53d0a8590c2d1dbb63672aa7b7d1ef51155/tokio/src/sync/task/atomic_waker.rs) in Tokio 1.53.1.
-- `once::OnceCell` has an API informed by [`tokio::sync::OnceCell`](https://docs.rs/tokio/latest/tokio/sync/struct.OnceCell.html), with an independent implementation based on Asyncband's semaphore and value storage.
-- `once::OnceMap` is inspired by [`uv-once-map`](https://github.com/astral-sh/uv/tree/936e6cdc42f44365e087a4ba7148238afc090b0b/crates/uv-once-map), with a redesigned interface and implementation.
-- `oneshot::channel` is derived from the [`oneshot`](https://github.com/faern/oneshot) crate, with significant simplifications because Asyncband does not provide synchronized receive operations.
-- `pool` is ported from [`fastpool` 1.1.1](https://github.com/fast/fastpool/tree/e4c65f1ed38395abc58d68eda8bd09925c13028e), which is a reimplementation of [`deadpool`](https://github.com/deadpool-rs/deadpool), while retaining Fastpool's runtime-agnostic design and caller-side timeout composition.
-- `rwlock::RwLock` is derived from [`tokio::sync::RwLock` in Tokio 1.42.0](https://github.com/tokio-rs/tokio/blob/bb9d57017e100985f86d8ca41ac105ee9140423e/tokio/src/sync/rwlock.rs), but accepts any `NonZeroUsize` as `max_readers` instead of Tokio's restricted range.
-- `semaphore::Semaphore` has an API informed by [`tokio::sync::Semaphore`](https://docs.rs/tokio/latest/tokio/sync/struct.Semaphore.html), with an independent implementation using Asyncband's waiter queue and permit accounting; it omits `close`, avoids Tokio's fixed maximum-permit constant, and adds operations such as `reduce_permits` for Asyncband's use cases.
-- `waitgroup::WaitGroup` is inspired by [`waitgroup-rs`](https://github.com/laizy/waitgroup-rs), but treats every cloned handle as an RAII participant and supports cancellable multi-observer waits.
diff --git a/LICENSE b/LICENSE
index 735d3c3..2229678 100644
--- a/LICENSE
+++ b/LICENSE
@@ -203,31 +203,102 @@
THIRD-PARTY WORKS
This product contains portions of third-party works. The paths below identify
-the files containing those portions. Modifications made for Apache Asyncband
-are licensed under the Apache License, Version 2.0, unless otherwise noted.
+each local file containing those portions and the corresponding upstream
+source paths. Modifications made for Apache Asyncband are licensed under the
+Apache License, Version 2.0, unless otherwise noted.
+
+In this section, "derived", "adapted", and "ported" identify incorporated
+source code. "Inspired" and "informed" identify independent implementations
+that draw on external designs or APIs.
Tokio
-Portions of the following files are derived from Tokio:
+Portions of asyncband/src/mutex/mod.rs are derived from Tokio 1.41.0:
+
+ https://github.com/tokio-rs/tokio/blob/01e04daaa162ce6122bb894fdda0b6803dd32093/tokio/src/sync/mutex.rs
+
+Portions of the following files are derived from Tokio 1.42.0. Each local path
+is followed by its upstream source path or paths:
- asyncband/src/mutex/mod.rs
- asyncband/src/rwlock/mapped_read_guard.rs
- asyncband/src/rwlock/mapped_write_guard.rs
asyncband/src/rwlock/mod.rs
- asyncband/src/rwlock/owned_mapped_read_guard.rs
- asyncband/src/rwlock/owned_mapped_write_guard.rs
- asyncband/src/rwlock/owned_read_guard.rs
- asyncband/src/rwlock/owned_write_guard.rs
+ tokio/src/sync/rwlock.rs
asyncband/src/rwlock/read_guard.rs
+ tokio/src/sync/rwlock/read_guard.rs
asyncband/src/rwlock/write_guard.rs
+ tokio/src/sync/rwlock/write_guard.rs
+ asyncband/src/rwlock/owned_read_guard.rs
+ tokio/src/sync/rwlock/owned_read_guard.rs
+ asyncband/src/rwlock/owned_write_guard.rs
+ tokio/src/sync/rwlock/owned_write_guard.rs
+ asyncband/src/rwlock/mapped_write_guard.rs
+ tokio/src/sync/rwlock/write_guard_mapped.rs
+ asyncband/src/rwlock/owned_mapped_write_guard.rs
+ tokio/src/sync/rwlock/owned_write_guard_mapped.rs
+ asyncband/src/rwlock/mapped_read_guard.rs
+ tokio/src/sync/rwlock/read_guard.rs
+ tokio/src/sync/rwlock/write_guard_mapped.rs
+ asyncband/src/rwlock/owned_mapped_read_guard.rs
+ tokio/src/sync/rwlock/owned_read_guard.rs
+ tokio/src/sync/rwlock/owned_write_guard_mapped.rs
-Portions of asyncband/src/internal/atomic_waker.rs are informed by Tokio's
-AtomicWaker implementation.
+The exact Tokio 1.42.0 revision is:
-The original Mutex and RwLock sources are available at:
+ https://github.com/tokio-rs/tokio/tree/bb9d57017e100985f86d8ca41ac105ee9140423e/tokio/src/sync
- https://github.com/tokio-rs/tokio/blob/01e04daaa162ce6122bb894fdda0b6803dd32093/tokio/src/sync/mutex.rs
- https://github.com/tokio-rs/tokio/blob/bb9d57017e100985f86d8ca41ac105ee9140423e/tokio/src/sync/rwlock.rs
+Asyncband's RwLock accepts any NonZeroUsize as max_readers instead of Tokio's
+restricted range.
+
+Portions of the following files originated from Tokio 1.47.0's OnceCell. Each
+local path is followed by its upstream source path:
+
+ asyncband/src/once/once_cell/mod.rs
+ tokio/src/sync/once_cell.rs
+ asyncband/src/internal/value_cell.rs
+ tokio/src/sync/once_cell.rs
+
+The exact Tokio 1.47.0 source is:
+
+ https://github.com/tokio-rs/tokio/blob/3911cb8523f190142f61c64b66881c07c0d3e7be/tokio/src/sync/once_cell.rs
+
+Asyncband substantially changed this implementation. OnceCell uses a permit
+only to serialize initialization and does not close its semaphore when a value
+is published. It can remove a value and later initialize the cell again, and
+its set operation waits for an in-progress initializer instead of reporting a
+closed or initializing state. ValueCell factors storage out of OnceCell,
+contains no semaphore or closed-state invariant, supports mutation, removal,
+and reinitialization, and is shared by OnceCell and LazyCell.
+
+Portions of the following files originated from Tokio 1.42.0's public and
+internal semaphore implementations:
+
+ asyncband/src/semaphore/mod.rs
+ tokio/src/sync/semaphore.rs
+ asyncband/src/internal/semaphore.rs
+ tokio/src/sync/batch_semaphore.rs
+
+The exact Tokio 1.42.0 sources are:
+
+ https://github.com/tokio-rs/tokio/blob/bb9d57017e100985f86d8ca41ac105ee9140423e/tokio/src/sync/semaphore.rs
+ https://github.com/tokio-rs/tokio/blob/bb9d57017e100985f86d8ca41ac105ee9140423e/tokio/src/sync/batch_semaphore.rs
+
+Asyncband substantially changed this implementation. It has no closed state,
+close operation, close errors, reserved status bits, or fixed maximum-permit
+constant. It uses usize permit counts and adds direct draining and exact
+reduction. Its internal implementation replaces Tokio's intrusive waiter node,
+which is pinned inside each acquire future, with queue-owned WaitList nodes
+addressed by stable IDs. Exact reduction inserts permit debt at the queue head.
+Cancellation detaches the queue-owned node and returns permits already assigned
+to it, while Asyncband's own batching machinery moves waker drops and wakeups
+outside the waiter lock.
+
+The standard ASF source headers on these four files apply to the substantial
+modifications contributed to Apache Asyncband. They do not replace the Tokio
+copyright notice or MIT License applicable to the incorporated portions.
+
+The panic-recovery behavior in asyncband/src/internal/atomic_waker.rs was
+informed by Tokio's AtomicWaker implementation at:
+
+ https://github.com/tokio-rs/tokio/blob/75fef53d0a8590c2d1dbb63672aa7b7d1ef51155/tokio/src/sync/task/atomic_waker.rs
Tokio is licensed under the MIT License:
@@ -259,66 +330,159 @@ The Apache License, Version 2.0, reproduced above, applies to the upstream
portions identified below. Where an upstream project offers a choice of
Apache-2.0 or MIT, Apache Asyncband uses the Apache-2.0 option.
-Portions of the following implementation files are derived from the oneshot
-crate at commit 83fd0864be7289067ce96cc79cd96c0928742979:
+Portions of the following files are derived or adapted from oneshot v0.1.11.
+This is the version that Asyncband originally incorporated, before oneshot split
+its channel implementation across sender, receiver, channel, and state modules.
+Each local path is followed by its upstream source path or paths:
asyncband/src/oneshot/mod.rs
+ src/lib.rs
asyncband/src/oneshot/receiver.rs
+ src/lib.rs
+ src/errors.rs
asyncband/src/oneshot/sender.rs
-
-Portions of the following test files and support are adapted from the same
-upstream test suite:
-
+ src/lib.rs
+ src/errors.rs
asyncband/src/oneshot/tests.rs
+ tests/helpers/mod.rs
+ tests/helpers/waker.rs
tests-integration/tests/oneshot_test/main.rs
+ tests/async.rs
+ tests/future.rs
+ tests/sync.rs
tests-integration/tests/oneshot_test/support.rs
+ tests/helpers/mod.rs
+ tests/helpers/waker.rs
+
+The exact upstream revision is:
-The oneshot crate is available from https://github.com/faern/oneshot and is
-licensed under Apache-2.0 or MIT. The corresponding upstream tests are:
+ https://github.com/faern/oneshot/tree/25274e995ee0a702b3e9e1ac81e577f8c3ce0892
- https://github.com/faern/oneshot/blob/83fd0864be7289067ce96cc79cd96c0928742979/tests/async.rs
- https://github.com/faern/oneshot/blob/83fd0864be7289067ce96cc79cd96c0928742979/tests/future.rs
- https://github.com/faern/oneshot/blob/83fd0864be7289067ce96cc79cd96c0928742979/tests/miri.rs
- https://github.com/faern/oneshot/blob/83fd0864be7289067ce96cc79cd96c0928742979/tests/sync.rs
- https://github.com/faern/oneshot/tree/83fd0864be7289067ce96cc79cd96c0928742979/tests/helpers
+The oneshot crate is licensed under Apache-2.0 or MIT. Apache Asyncband uses
+the Apache-2.0 option for the incorporated portions.
+
+Asyncband does not provide the upstream crate's synchronized receive
+operations and simplifies the incorporated implementation accordingly.
Portions of asyncband/src/internal/atomic_waker.rs are derived from futures-rs
-0.3.34 at commit 705e6b5c0f06535b1aac1cb1989a172b3d45be8c, available from
-https://github.com/rust-lang/futures-rs and licensed under Apache-2.0 or MIT:
+0.3.34 at the following exact revision and source path:
+
+ https://github.com/rust-lang/futures-rs/blob/705e6b5c0f06535b1aac1cb1989a172b3d45be8c/futures-core/src/task/__internal/atomic_waker.rs
+
+futures-rs is licensed under Apache-2.0 or MIT. Apache Asyncband uses the
+Apache-2.0 option for the incorporated portions. The upstream source carries
+the following copyright notices:
Copyright (c) 2016 Alex Crichton
Copyright (c) 2017 The Tokio Authors
-The polling loop in asyncband/src/blocking/mod.rs is adapted from Pollster 1.0.1
-at commit 6a1a148208326e9c5b231b16f199f5227c550774. Its reuse of a thread-local
-Parker/Waker pair, with a fresh pair for recursive calls, is adapted from
-futures-lite 2.6.1 at commit 226ce18976d8714d6bd9700b61dcc81d7200bc9a.
-Pollster is available from https://github.com/zesterer/pollster and is
-licensed under Apache-2.0 or MIT:
+The polling loop in asyncband/src/blocking/executor.rs is adapted from Pollster
+1.0.1 at the following exact revision and source path:
+
+ https://github.com/zesterer/pollster/blob/6a1a148208326e9c5b231b16f199f5227c550774/src/lib.rs
+
+The same file's reuse of a thread-local Parker/Waker pair, with a fresh pair
+for recursive calls, is adapted from futures-lite 2.6.1 at the following exact
+revision and source path:
+
+ https://github.com/smol-rs/futures-lite/blob/226ce18976d8714d6bd9700b61dcc81d7200bc9a/src/future.rs#L62-L91
+
+Pollster is licensed under Apache-2.0 or MIT. Apache Asyncband uses the
+Apache-2.0 option for the incorporated portions. The upstream source carries
+the following copyright notice:
Copyright (c) 2020-2021 Joshua Barretto
-futures-lite is available from https://github.com/smol-rs/futures-lite and is
-licensed under Apache-2.0 or MIT.
+futures-lite is licensed under Apache-2.0 or MIT. Apache Asyncband uses the
+Apache-2.0 option for the incorporated portions.
Portions of asyncband/src/blocking/parker.rs are adapted from parking 2.2.1 at
-commit 0ece32dbfd6cd1bc1510ede6ed56acb772edf83f, available from
-https://github.com/smol-rs/parking and licensed under Apache-2.0 or MIT:
+the following exact revision and source path:
+
+ https://github.com/smol-rs/parking/blob/0ece32dbfd6cd1bc1510ede6ed56acb772edf83f/src/lib.rs#L327-L429
+
+parking is licensed under Apache-2.0 or MIT. Apache Asyncband uses the
+Apache-2.0 option for the incorporated portions. The upstream source carries
+the following copyright notice:
Copyright 2014-2020 The Rust Project Developers
-Portions of the following files are ported from Fastpool 1.1.1 at commit
-e4c65f1ed38395abc58d68eda8bd09925c13028e:
+Portions of the following files are ported from Fastpool 1.1.1. Each local path
+is followed by its upstream source path or paths:
+ asyncband/src/pool/mod.rs
+ fastpool/src/lib.rs
asyncband/src/pool/bounded.rs
+ fastpool/src/bounded.rs
asyncband/src/pool/common.rs
- asyncband/src/pool/mod.rs
+ fastpool/src/common.rs
asyncband/src/pool/state.rs
+ fastpool/src/bounded.rs
+ fastpool/src/unbounded.rs
asyncband/src/pool/unbounded.rs
+ fastpool/src/unbounded.rs
tests-integration/tests/pool_recycle_cancelled_test.rs
+ fastpool/tests/recycle_cancelled_tests.rs
tests-integration/tests/pool_replenish_test.rs
+ fastpool/tests/replenish_tests.rs
+
+The exact upstream revision is:
+
+ https://github.com/fast/fastpool/tree/e4c65f1ed38395abc58d68eda8bd09925c13028e/fastpool
-Fastpool is available from https://github.com/fast/fastpool and is licensed
-under Apache-2.0:
+Asyncband retains Fastpool's runtime-agnostic design and caller-side timeout
+composition. Fastpool is licensed under Apache-2.0, and its source carries the
+following copyright notice:
Copyright 2025 FastLabs Developers
+
+DESIGN PROVENANCE WITHOUT INCORPORATED THIRD-PARTY SOURCE
+
+The following implementations were informed by external designs or APIs but
+do not incorporate source from those projects. They remain licensed under
+Apache-2.0.
+
+barrier::Barrier is inspired by std::sync::Barrier and tokio::sync::Barrier:
+
+ https://doc.rust-lang.org/std/sync/struct.Barrier.html
+ https://docs.rs/tokio/latest/tokio/sync/struct.Barrier.html
+
+Asyncband uses a separate implementation based on its internal WaitSet
+primitive.
+
+condvar::Condvar is inspired by std::sync::Condvar and
+async_std::sync::Condvar:
+
+ https://doc.rust-lang.org/std/sync/struct.Condvar.html
+ https://docs.rs/async-std/latest/async_std/sync/struct.Condvar.html
+
+Asyncband uses a fair FIFO waiter queue and standard non-buffered notification
+semantics.
+
+latch::Latch is inspired by latches:
+
+ https://github.com/mirromutth/latches
+
+Asyncband uses a separate implementation based on its internal CountdownState
+primitive.
+
+mpsc channels are inspired by std::sync::mpsc and tokio::sync::mpsc:
+
+ https://doc.rust-lang.org/std/sync/mpsc/index.html
+ https://docs.rs/tokio/latest/tokio/sync/mpsc/index.html
+
+Asyncband uses the standard library channels for storage and supplies its own
+asynchronous wakeup and bounded-backpressure coordination.
+
+once::OnceMap is inspired by uv-once-map:
+
+ https://github.com/astral-sh/uv/tree/936e6cdc42f44365e087a4ba7148238afc090b0b/crates/uv-once-map
+
+Asyncband redesigns both the interface and implementation.
+
+waitgroup::WaitGroup is inspired by waitgroup-rs:
+
+ https://github.com/laizy/waitgroup-rs
+
+Asyncband treats every cloned handle as an RAII participant and supports
+cancellable multi-observer waits.
diff --git a/README.md b/README.md
index ba97830..24597f3 100644
--- a/README.md
+++ b/README.md
@@ -133,10 +133,6 @@ The policy is that the minimum Rust version required to use this crate can be in
## License and Trademarks
-This project is licensed under [Apache License, Version 2.0](LICENSE); the license file also identifies incorporated third-party works and their terms.
+This project is licensed under [Apache License, Version 2.0](LICENSE); the license file also records incorporated third-party works, their terms, and external designs that informed independent Asyncband implementations.
Apache Asyncband, Asyncband, and Apache are either registered trademarks or trademarks of The Apache Software Foundation in the United States and/or other countries.
-
-## History
-
-See [HISTORY.md](HISTORY.md) for the external implementations that informed Asyncband's APIs.
diff --git a/asyncband/HISTORY.md b/asyncband/HISTORY.md
deleted file mode 120000
index a5333ae..0000000
--- a/asyncband/HISTORY.md
+++ /dev/null
@@ -1 +0,0 @@
-../HISTORY.md
\ No newline at end of file
diff --git a/asyncband/src/barrier/mod.rs b/asyncband/src/barrier/mod.rs
index 87830c6..acf4d4d 100644
--- a/asyncband/src/barrier/mod.rs
+++ b/asyncband/src/barrier/mod.rs
@@ -118,25 +118,20 @@ impl BarrierWaitResult {
}
impl Barrier {
- /// Creates a new barrier that can block the specified number of tasks.
+ /// Creates a barrier for `n` participants.
///
- /// A barrier will block `n-1` tasks and release them all at once when the `n`th task arrives.
- ///
- /// # Arguments
- ///
- /// * `n`: The number of tasks to wait for. If `n` is 0, it will be treated as 1.
+ /// Each generation completes when `n` calls to [`wait`](Self::wait) have arrived. Passing zero
+ /// selects the same immediately completing behavior as passing one.
///
/// # Examples
///
/// ```
/// use asyncband::barrier::Barrier;
///
- /// let barrier = Barrier::new(3); // Creates a barrier for 3 tasks
+ /// let barrier = Barrier::new(3);
/// ```
pub fn new(n: u32) -> Self {
- // If n is 0, it's not clear what behavior the user wants.
- // std::sync::Barrier works with n = 0 the same as n = 1,
- // where every .wait() immediately unblocks, so we adopt that here as well.
+ // Normalize an empty group to one participant so every wait completes its own generation.
let n = if n > 0 { n } else { 1 };
Self {
diff --git a/asyncband/src/blocking/executor.rs b/asyncband/src/blocking/executor.rs
new file mode 100644
index 0000000..0a9c1e2
--- /dev/null
+++ b/asyncband/src/blocking/executor.rs
@@ -0,0 +1,89 @@
+// This file contains a polling loop adapted from Pollster 1.0.1 and a thread-local Parker/Waker
+// reuse strategy adapted from futures-lite 2.6.1.
+// Copyright (c) 2020-2021 Joshua Barretto
+// Asyncband uses the Apache-2.0 license option for code incorporated from both projects.
+// The incorporated code has been modified for use in Apache Asyncband.
+// Upstream sources:
+// https://github.com/zesterer/pollster/blob/6a1a148208326e9c5b231b16f199f5227c550774/src/lib.rs
+// https://github.com/smol-rs/futures-lite/blob/226ce18976d8714d6bd9700b61dcc81d7200bc9a/src/future.rs#L62-L91
+
+use std::cell::RefCell;
+use std::future::IntoFuture;
+use std::pin::pin;
+use std::task::Context;
+use std::task::Poll;
+use std::task::Waker;
+use std::time::Duration;
+use std::time::Instant;
+
+use super::parker::Parker;
+
+pub(super) fn block_on<F: IntoFuture>(future: F) -> F::Output {
+ let mut future = pin!(future.into_future());
+
+ with_parker(|parker, waker| {
+ let mut context = Context::from_waker(waker);
+
+ loop {
+ match future.as_mut().poll(&mut context) {
+ Poll::Pending => parker.park(),
+ Poll::Ready(output) => return output,
+ }
+ }
+ })
+}
+
+pub(super) fn wait_timeout<F: IntoFuture>(future: F, timeout: Duration) -> Option<F::Output> {
+ let Some(deadline) = Instant::now().checked_add(timeout) else {
+ // A duration beyond Instant's range cannot expire during the process lifetime.
+ return Some(block_on(future));
+ };
+ let mut future = pin!(future.into_future());
+
+ with_parker(|parker, waker| {
+ let mut context = Context::from_waker(waker);
+
+ loop {
+ if let Poll::Ready(output) = future.as_mut().poll(&mut context) {
+ return Some(output);
+ }
+
+ let now = Instant::now();
+ if now >= deadline {
+ return None;
+ }
+ parker.park_timeout(deadline.saturating_duration_since(now));
+ }
+ })
+}
+
+fn parker_and_waker() -> (Parker, Waker) {
+ let parker = Parker::new();
+ let waker = parker.waker();
+ (parker, waker)
+}
+
+thread_local! {
+ // Holding the mutable borrow while polling makes a recursive call take the fresh-parker path
+ // instead of sharing a notification token.
+ static CACHE: RefCell<(Parker, Waker)> = RefCell::new(parker_and_waker());
+}
+
+fn with_parker<T>(wait: impl FnOnce(&Parker, &Waker) -> T) -> T {
+ CACHE.with(|cache| {
+ let cached;
+ let fresh;
+ let (parker, waker) = match cache.try_borrow_mut() {
+ Ok(pair) => {
+ cached = pair;
+ &*cached
+ }
+ Err(_) => {
+ fresh = parker_and_waker();
+ &fresh
+ }
+ };
+
+ wait(parker, waker)
+ })
+}
diff --git a/asyncband/src/blocking/mod.rs b/asyncband/src/blocking/mod.rs
index eb04301..979714c 100644
--- a/asyncband/src/blocking/mod.rs
+++ b/asyncband/src/blocking/mod.rs
@@ -15,11 +15,6 @@
// specific language governing permissions and limitations
// under the License.
-// The polling loop is adapted from Pollster 1.0.1. Reusing a thread-local Parker/Waker pair and
-// creating a fresh pair for recursive calls is adapted from futures-lite 2.6.1:
-// https://github.com/zesterer/pollster/blob/6a1a148208326e9c5b231b16f199f5227c550774/src/lib.rs
-// https://github.com/smol-rs/futures-lite/blob/226ce18976d8714d6bd9700b61dcc81d7200bc9a/src/future.rs#L62-L91
-
//! Synchronous interoperability for runtime-agnostic futures.
//!
//! This module bridges synchronous Rust code to a single future. Enable it with the opt-in
@@ -59,18 +54,11 @@
//! work assigned to that executor. Call these methods only from synchronous code, such as `main`,
//! a dedicated thread, or a sync-to-async boundary.
+mod executor;
mod parker;
-use std::cell::RefCell;
use std::future::IntoFuture;
-use std::pin::pin;
-use std::task::Context;
-use std::task::Poll;
-use std::task::Waker;
use std::time::Duration;
-use std::time::Instant;
-
-use self::parker::Parker;
/// Extension methods for waiting on a future from synchronous code.
///
@@ -93,18 +81,7 @@ pub trait FutureExt: IntoFuture {
where
Self: Sized,
{
- let mut future = pin!(self.into_future());
-
- with_parker(|parker, waker| {
- let mut context = Context::from_waker(waker);
-
- loop {
- match future.as_mut().poll(&mut context) {
- Poll::Pending => parker.park(),
- Poll::Ready(output) => return output,
- }
- }
- })
+ executor::block_on(self)
}
/// Blocks the current thread until this future is ready or `timeout` elapses.
@@ -120,59 +97,8 @@ pub trait FutureExt: IntoFuture {
where
Self: Sized,
{
- let Some(deadline) = Instant::now().checked_add(timeout) else {
- // A duration beyond Instant's range cannot expire during the process lifetime.
- return Some(FutureExt::block_on(self));
- };
- let mut future = pin!(self.into_future());
-
- with_parker(|parker, waker| {
- let mut context = Context::from_waker(waker);
-
- loop {
- if let Poll::Ready(output) = future.as_mut().poll(&mut context) {
- return Some(output);
- }
-
- let now = Instant::now();
- if now >= deadline {
- return None;
- }
- parker.park_timeout(deadline.saturating_duration_since(now));
- }
- })
+ executor::wait_timeout(self, timeout)
}
}
impl<F: IntoFuture> FutureExt for F {}
-
-fn parker_and_waker() -> (Parker, Waker) {
- let parker = Parker::new();
- let waker = parker.waker();
- (parker, waker)
-}
-
-thread_local! {
- // Holding the mutable borrow while polling makes a recursive call take the fresh-parker path
- // instead of sharing a notification token.
- static CACHE: RefCell<(Parker, Waker)> = RefCell::new(parker_and_waker());
-}
-
-fn with_parker<T>(wait: impl FnOnce(&Parker, &Waker) -> T) -> T {
- CACHE.with(|cache| {
- let cached;
- let fresh;
- let (parker, waker) = match cache.try_borrow_mut() {
- Ok(pair) => {
- cached = pair;
- &*cached
- }
- Err(_) => {
- fresh = parker_and_waker();
- &fresh
- }
- };
-
- wait(parker, waker)
- })
-}
diff --git a/asyncband/src/blocking/parker.rs b/asyncband/src/blocking/parker.rs
index 57d4a0a..bd07509 100644
--- a/asyncband/src/blocking/parker.rs
+++ b/asyncband/src/blocking/parker.rs
@@ -1,4 +1,8 @@
-// Adapted from parking 2.2.1 at commit 0ece32dbfd6cd1bc1510ede6ed56acb772edf83f:
+// This file contains code adapted from parking 2.2.1.
+// Copyright 2014-2020 The Rust Project Developers
+// Asyncband uses the upstream project's Apache-2.0 license option for the incorporated code.
+// The incorporated code has been modified for use in Apache Asyncband.
+// Upstream source:
// https://github.com/smol-rs/parking/blob/0ece32dbfd6cd1bc1510ede6ed56acb772edf83f/src/lib.rs#L327-L429
use std::cell::Cell;
diff --git a/asyncband/src/broadcast/mpmc/unbounded/mod.rs b/asyncband/src/broadcast/mpmc/unbounded/mod.rs
index 59b6615..85712a5 100644
--- a/asyncband/src/broadcast/mpmc/unbounded/mod.rs
+++ b/asyncband/src/broadcast/mpmc/unbounded/mod.rs
@@ -15,78 +15,47 @@
// specific language governing permissions and limitations
// under the License.
-//! A multi-producer multi-consumer broadcast channel with an unbounded buffer.
+//! An unbounded fan-out channel with multiple senders and receivers.
//!
-//! This channel supports multiple senders and multiple receivers. Each message sent by any
-//! sender is received by all active receivers. If a receiver falls behind, messages are buffered
-//! until the receiver consumes them or is dropped.
+//! A send publishes one value to every receiver that exists at that moment. Receivers advance
+//! independently, and a receiver created later starts with the next value rather than replaying
+//! earlier values.
//!
-//! # Memory usage
+//! # Backlog and memory
//!
-//! This channel does not impose a capacity limit. A slow or stalled receiver can cause the
-//! buffer to grow without bound, because messages are retained until every active receiver has
-//! consumed them or the receiver is dropped. Use
-//! [`UnboundedSender::retained_message_count`] to monitor the number of messages currently retained
-//! by the channel.
+//! Published values remain in the shared backlog until every receiver that was eligible for them
+//! has advanced past them or been dropped. Because sending has no capacity limit, one stalled
+//! receiver can make that backlog exhaust available memory.
+//! [`UnboundedSender::retained_message_count`] reports its current length.
//!
-//! The buffer keeps the capacity a steady workload needs, so a channel that repeatedly fills and
-//! drains does not reallocate. Capacity grown for a one-off burst is released once a later cycle
-//! drains completely without needing it.
+//! Buffer capacity is reused across steady bursts. Allocation retained for an unusually large burst
+//! is released after a later, substantially smaller cycle drains completely.
//!
//! # Receivers
//!
-//! Each receiver has an independent cursor. Use [`UnboundedSender::subscribe`] or
-//! [`UnboundedReceiver::resubscribe`] to create a receiver that starts at the current tail.
+//! [`UnboundedSender::subscribe`] and [`UnboundedReceiver::resubscribe`] add a receiver at the
+//! current publication boundary. They do not copy another receiver's unread backlog.
//!
-//! Messages are reclaimed once the slowest receiver moves past them, which scans one slot per
-//! receiver. Only the receiver that advances the slowest cursor pays for that scan. The channel
-//! keeps a slot for every receiver it hands out, so the cost follows the largest number of
-//! receivers that were ever active at once rather than the number active now.
+//! Reclaiming the oldest value requires finding the earliest remaining receiver cursor. That work
+//! scales with the receiver slots allocated by the channel, including slots retained for reuse
+//! after receivers are dropped.
//!
-//! # Examples
-//!
-//! Basic usage:
-//!
-//! ```
-//! use asyncband::broadcast::mpmc;
-//!
-//! # #[tokio::main]
-//! # async fn main() {
-//! let (tx, mut rx1) = mpmc::unbounded();
-//! let mut rx2 = tx.subscribe();
-//!
-//! tx.send(10);
-//! tx.send(20);
-//!
-//! assert_eq!(rx1.recv().await, Ok(10));
-//! assert_eq!(rx1.recv().await, Ok(20));
-//! assert_eq!(rx2.recv().await, Ok(10));
-//! assert_eq!(rx2.recv().await, Ok(20));
-//! # }
-//! ```
-//!
-//! Slow receivers do not miss messages:
+//! # Example
//!
//! ```
-//! use asyncband::broadcast::mpmc;
-//!
-//! # #[tokio::main]
-//! # async fn main() {
-//! let (tx, mut rx1) = mpmc::unbounded();
-//! let mut rx2 = tx.subscribe();
+//! use asyncband::broadcast::mpmc::TryRecvError;
+//! use asyncband::broadcast::mpmc::unbounded;
//!
-//! tx.send(1);
-//! tx.send(2);
+//! let (publisher, mut early) = unbounded();
+//! publisher.send("before subscription");
//!
-//! // One receiver draining the channel does not discard what the other has not read yet.
-//! assert_eq!(rx1.recv().await, Ok(1));
-//! assert_eq!(rx1.recv().await, Ok(2));
-//! assert_eq!(tx.retained_message_count(), 2);
+//! let mut late = publisher.subscribe();
+//! publisher.send("after subscription");
//!
-//! assert_eq!(rx2.recv().await, Ok(1));
-//! assert_eq!(rx2.recv().await, Ok(2));
-//! assert_eq!(tx.retained_message_count(), 0);
-//! # }
+//! assert_eq!(early.try_recv(), Ok("before subscription"));
+//! assert_eq!(early.try_recv(), Ok("after subscription"));
+//! assert_eq!(late.try_recv(), Ok("after subscription"));
+//! assert_eq!(late.try_recv(), Err(TryRecvError::Empty));
//! ```
use std::collections::VecDeque;
@@ -110,18 +79,19 @@ use crate::internal::wakerset::WakerToken;
#[cfg(test)]
mod tests;
-/// Creates a new broadcast channel with an unbounded buffer.
+/// Creates an unbounded broadcast channel and its first receiver.
///
-/// Every accepted value is retained until all active receivers consume it or are dropped.
+/// The returned receiver is subscribed before any value can be published. Additional receivers can
+/// be added with [`UnboundedSender::subscribe`].
///
/// # Examples
///
/// ```
-/// use asyncband::broadcast::mpmc;
+/// use asyncband::broadcast::mpmc::unbounded;
///
-/// let (tx, mut rx) = mpmc::unbounded();
-/// tx.send(10);
-/// assert_eq!(rx.try_recv(), Ok(10));
+/// let (publisher, mut receiver) = unbounded();
+/// publisher.send("ready");
+/// assert_eq!(receiver.try_recv(), Ok("ready"));
/// ```
pub fn unbounded<T: Clone>() -> (UnboundedSender<T>, UnboundedReceiver<T>) {
let mut receivers = Arena::new();
@@ -145,38 +115,36 @@ pub fn unbounded<T: Clone>() -> (UnboundedSender<T>, UnboundedReceiver<T>) {
(sender, receiver)
}
-/// Error returned by [`UnboundedReceiver::recv`].
+/// A receive operation reached the end of its subscription.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum RecvError {
- /// All senders have been dropped, and this receiver has no remaining messages.
+ /// No sender remains and this receiver has consumed its entire backlog.
Disconnected,
}
impl fmt::Display for RecvError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- match self {
- RecvError::Disconnected => write!(f, "receiving on a disconnected channel"),
- }
+ f.write_str("receiving on a disconnected channel")
}
}
impl std::error::Error for RecvError {}
-/// Error returned by [`UnboundedReceiver::try_recv`].
+/// A non-blocking receive did not yield a value.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum TryRecvError {
- /// No message is currently available, but at least one sender remains.
+ /// This receiver is caught up, but a sender can still publish more values.
Empty,
- /// All senders have been dropped, and this receiver has no remaining messages.
+ /// No sender remains and this receiver has consumed its entire backlog.
Disconnected,
}
impl fmt::Display for TryRecvError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- match self {
- TryRecvError::Empty => write!(f, "receiving on an empty channel"),
- TryRecvError::Disconnected => write!(f, "receiving on a disconnected channel"),
- }
+ f.write_str(match self {
+ TryRecvError::Empty => "receiving on an empty channel",
+ TryRecvError::Disconnected => "receiving on a disconnected channel",
+ })
}
}
@@ -365,10 +333,10 @@ struct Shared<T> {
senders: AtomicUsize,
}
-/// The sending side of an unbounded broadcast channel.
+/// A publishing handle for an unbounded broadcast channel.
///
-/// The sender can be cloned to create multiple producers. Dropping the final sender disconnects
-/// the channel. Each receiver may drain its own buffered messages before observing disconnection.
+/// Cloning this handle adds another publisher. Once the final sender is dropped, each receiver can
+/// drain the values already published for it and then observes disconnection.
pub struct UnboundedSender<T> {
shared: Arc<Shared<T>>,
}
@@ -410,27 +378,28 @@ impl<T> Drop for UnboundedSender<T> {
}
impl<T> UnboundedSender<T> {
- /// Broadcasts a value to all active receivers.
+ /// Publishes `msg` to every receiver currently subscribed.
///
- /// This operation does not wait for receiver capacity. If receivers fall behind, messages
- /// remain buffered until all active receivers have consumed them or the lagging receivers
- /// are dropped.
+ /// Sending has no backpressure. The channel retains the value until every eligible receiver
+ /// consumes it or is dropped.
///
- /// If no receivers are active, the message is dropped immediately.
+ /// When no receivers exist, `msg` is discarded without entering the backlog.
///
/// # Panics
///
- /// Panics if the internal message version counter overflows. After `u64::MAX` successful sends
- /// on one channel instance, the next send panics.
+ /// Panics when publishing would overflow the channel's internal version counter.
///
/// # Examples
///
/// ```
- /// use asyncband::broadcast::mpmc;
+ /// use asyncband::broadcast::mpmc::unbounded;
+ ///
+ /// let (publisher, mut first) = unbounded();
+ /// let mut second = publisher.subscribe();
+ /// publisher.send("update");
///
- /// let (tx, mut rx) = mpmc::unbounded();
- /// tx.send(10);
- /// assert_eq!(rx.try_recv(), Ok(10));
+ /// assert_eq!(first.try_recv(), Ok("update"));
+ /// assert_eq!(second.try_recv(), Ok("update"));
/// ```
pub fn send(&self, msg: T) {
let msg = Arc::new(msg);
@@ -465,48 +434,50 @@ impl<T> UnboundedSender<T> {
wake_all(wakers);
}
- /// Returns the number of messages currently retained by the channel.
+ /// Returns the number of values in the shared backlog.
///
- /// This is not the number of messages any single receiver can still read. It is the shared
- /// backlog kept alive by the slowest active receiver.
+ /// This is not an unread count for any particular receiver. A value remains included until the
+ /// last receiver eligible for it advances or is dropped.
///
- /// The returned value is an instantaneous snapshot. It is suitable for diagnostics and soft
- /// flow-control decisions, but concurrent sends and receives may change it immediately.
+ /// The result is an instantaneous observation and may become stale as other tasks send or
+ /// receive.
///
/// # Examples
///
/// ```
- /// use asyncband::broadcast::mpmc;
+ /// use asyncband::broadcast::mpmc::unbounded;
///
- /// let (tx, mut rx) = mpmc::unbounded();
- /// tx.send(10);
- /// assert_eq!(tx.retained_message_count(), 1);
+ /// let (publisher, mut fast) = unbounded();
+ /// let mut slow = publisher.subscribe();
+ /// publisher.send("update");
+ /// assert_eq!(publisher.retained_message_count(), 1);
///
- /// assert_eq!(rx.try_recv(), Ok(10));
- /// assert_eq!(tx.retained_message_count(), 0);
+ /// assert_eq!(fast.try_recv(), Ok("update"));
+ /// assert_eq!(publisher.retained_message_count(), 1);
+ /// assert_eq!(slow.try_recv(), Ok("update"));
+ /// assert_eq!(publisher.retained_message_count(), 0);
/// ```
pub fn retained_message_count(&self) -> usize {
self.shared.inner.lock().buffer.len()
}
- /// Creates a new receiver that starts receiving messages from the current tail of the channel.
+ /// Subscribes a new receiver for values published from this point forward.
+ ///
+ /// Values already in the backlog are not visible to the new receiver.
///
/// # Examples
///
/// ```
- /// use asyncband::broadcast::mpmc;
/// use asyncband::broadcast::mpmc::TryRecvError;
+ /// use asyncband::broadcast::mpmc::unbounded;
///
- /// # #[tokio::main]
- /// # async fn main() {
- /// let (tx, _) = mpmc::unbounded();
- /// tx.send(10);
+ /// let (publisher, _) = unbounded();
+ /// publisher.send("earlier");
///
- /// let mut rx = tx.subscribe();
- /// assert_eq!(rx.try_recv(), Err(TryRecvError::Empty));
- /// tx.send(20);
- /// assert_eq!(rx.recv().await, Ok(20));
- /// # }
+ /// let mut receiver = publisher.subscribe();
+ /// assert_eq!(receiver.try_recv(), Err(TryRecvError::Empty));
+ /// publisher.send("later");
+ /// assert_eq!(receiver.try_recv(), Ok("later"));
/// ```
#[must_use = "the receiver is dropped immediately if it is not retained"]
pub fn subscribe(&self) -> UnboundedReceiver<T> {
@@ -518,9 +489,10 @@ impl<T> UnboundedSender<T> {
}
}
-/// A receiver for an unbounded broadcast channel.
+/// An independent subscription to an unbounded broadcast channel.
///
-/// Each receiver sees every message sent to the channel while the receiver is active.
+/// This receiver observes every value published after its subscription point and retains its own
+/// position in the shared backlog.
pub struct UnboundedReceiver<T> {
shared: Arc<Shared<T>>,
key: SlotId,
@@ -543,30 +515,32 @@ impl<T> Drop for UnboundedReceiver<T> {
}
impl<T: Clone> UnboundedReceiver<T> {
- /// Receives the next value for this receiver.
- ///
- /// # Returns
+ /// Waits for this receiver's next value.
///
- /// * `Ok(T)`: The next message.
- /// * `Err(RecvError::Disconnected)`: All senders have been dropped and this receiver has no
- /// remaining messages.
+ /// Values already published for this receiver are returned before disconnection.
+ /// [`RecvError::Disconnected`] is returned only when no sender remains and this receiver's
+ /// backlog is empty.
///
/// # Cancel safety
///
- /// This method is cancel safe. If `recv` is used as the event in a `select` statement and some
- /// other branch completes first, it is guaranteed that no messages were received on this
- /// channel.
+ /// Dropping a pending `recv` leaves this receiver's cursor unchanged. Its next call can still
+ /// return the same next value, so `recv` can be raced with other futures in a selection
+ /// construct.
///
/// # Examples
///
/// ```
- /// use asyncband::broadcast::mpmc;
+ /// use asyncband::broadcast::mpmc::RecvError;
+ /// use asyncband::broadcast::mpmc::unbounded;
///
/// # #[tokio::main]
/// # async fn main() {
- /// let (tx, mut rx) = mpmc::unbounded();
- /// tx.send(10);
- /// assert_eq!(rx.recv().await, Ok(10));
+ /// let (publisher, mut receiver) = unbounded();
+ /// publisher.send("final update");
+ /// drop(publisher);
+ ///
+ /// assert_eq!(receiver.recv().await, Ok("final update"));
+ /// assert_eq!(receiver.recv().await, Err(RecvError::Disconnected));
/// # }
/// ```
pub async fn recv(&mut self) -> Result<T, RecvError> {
@@ -577,23 +551,25 @@ impl<T: Clone> UnboundedReceiver<T> {
.await
}
- /// Attempts to receive the next value for this receiver without blocking.
+ /// Attempts to take this receiver's next value without waiting.
///
- /// # Returns
- ///
- /// * `Ok(T)`: The next message.
- /// * `Err(TryRecvError::Empty)`: No message is currently available.
- /// * `Err(TryRecvError::Disconnected)`: All senders have been dropped and this receiver has no
- /// remaining messages.
+ /// [`TryRecvError::Empty`] means this receiver is currently caught up while a sender remains.
+ /// [`TryRecvError::Disconnected`] means no sender remains and this receiver has drained its
+ /// backlog.
///
/// # Examples
///
/// ```
- /// use asyncband::broadcast::mpmc;
+ /// use asyncband::broadcast::mpmc::TryRecvError;
+ /// use asyncband::broadcast::mpmc::unbounded;
+ ///
+ /// let (publisher, mut receiver) = unbounded();
+ /// assert_eq!(receiver.try_recv(), Err(TryRecvError::Empty));
///
- /// let (tx, mut rx) = mpmc::unbounded();
- /// tx.send(10);
- /// assert_eq!(rx.try_recv(), Ok(10));
+ /// publisher.send("update");
+ /// assert_eq!(receiver.try_recv(), Ok("update"));
+ /// drop(publisher);
+ /// assert_eq!(receiver.try_recv(), Err(TryRecvError::Disconnected));
/// ```
pub fn try_recv(&mut self) -> Result<T, TryRecvError> {
let (msg, reclaimed) = self.try_recv_shared()?;
@@ -640,26 +616,27 @@ impl<T> UnboundedReceiver<T> {
}
}
- /// Re-subscribes to the channel, returning a new receiver that starts receiving messages from
- /// the *current* tail of the channel.
+ /// Creates another receiver at the current publication boundary.
///
- /// This is useful if the receiver wants to jump to the latest message, skipping everything in
- /// between. The original receiver is unchanged and continues to retain its own backlog until
- /// it consumes those messages or is dropped.
+ /// The new receiver skips this receiver's unread backlog. The original receiver remains at its
+ /// current position and continues retaining those values until it consumes them or is dropped.
///
/// # Examples
///
/// ```
- /// use asyncband::broadcast::mpmc;
+ /// use asyncband::broadcast::mpmc::TryRecvError;
+ /// use asyncband::broadcast::mpmc::unbounded;
///
- /// let (tx, mut rx) = mpmc::unbounded();
- /// tx.send(1);
- /// tx.send(2);
+ /// let (publisher, mut original) = unbounded();
+ /// publisher.send("pending for original");
///
- /// let mut rx2 = rx.resubscribe();
- /// tx.send(3);
+ /// let mut fresh = original.resubscribe();
+ /// assert_eq!(fresh.try_recv(), Err(TryRecvError::Empty));
+ /// publisher.send("visible to both");
///
- /// assert_eq!(rx2.try_recv(), Ok(3));
+ /// assert_eq!(original.try_recv(), Ok("pending for original"));
+ /// assert_eq!(original.try_recv(), Ok("visible to both"));
+ /// assert_eq!(fresh.try_recv(), Ok("visible to both"));
/// ```
#[must_use = "the receiver is dropped immediately if it is not retained"]
pub fn resubscribe(&self) -> Self {
@@ -670,29 +647,26 @@ impl<T> UnboundedReceiver<T> {
Self { shared, key }
}
- /// Returns the number of messages this receiver can still read.
+ /// Returns this receiver's unread value count.
///
- /// This count is specific to this receiver, unlike
- /// [`UnboundedSender::retained_message_count`], which reports the shared backlog retained by
- /// the slowest active receiver.
+ /// Unlike [`UnboundedSender::retained_message_count`], this excludes values retained only for
+ /// other receivers.
///
- /// The returned value is an instantaneous snapshot. It is suitable for detecting that this
- /// receiver is falling behind, but concurrent sends may change it immediately.
+ /// The result is an instantaneous observation and may become stale as other tasks publish
+ /// values.
///
/// # Examples
///
/// ```
- /// use asyncband::broadcast::mpmc;
- ///
- /// let (tx, mut rx) = mpmc::unbounded();
- /// assert_eq!(rx.unread_message_count(), 0);
+ /// use asyncband::broadcast::mpmc::unbounded;
///
- /// tx.send(10);
- /// tx.send(20);
- /// assert_eq!(rx.unread_message_count(), 2);
+ /// let (publisher, mut receiver) = unbounded();
+ /// publisher.send("first");
+ /// publisher.send("second");
+ /// assert_eq!(receiver.unread_message_count(), 2);
///
- /// assert_eq!(rx.try_recv(), Ok(10));
- /// assert_eq!(rx.unread_message_count(), 1);
+ /// assert_eq!(receiver.try_recv(), Ok("first"));
+ /// assert_eq!(receiver.unread_message_count(), 1);
/// ```
pub fn unread_message_count(&self) -> usize {
let inner = self.shared.inner.lock();
diff --git a/asyncband/src/internal/atomic_waker.rs b/asyncband/src/internal/atomic_waker.rs
index b2adce6..3616691 100644
--- a/asyncband/src/internal/atomic_waker.rs
+++ b/asyncband/src/internal/atomic_waker.rs
@@ -15,7 +15,11 @@
// specific language governing permissions and limitations
// under the License.
-// Portions derived from futures-rs 0.3.34, with panic recovery informed by Tokio 1.53.1:
+// This file contains a state machine derived from futures-rs 0.3.34 and panic-recovery behavior
+// informed by Tokio 1.53.1.
+// Asyncband uses the Apache-2.0 license option for code incorporated from futures-rs.
+// The incorporated code has been modified for use in Apache Asyncband.
+// Upstream sources:
// https://github.com/rust-lang/futures-rs/blob/705e6b5c0f06535b1aac1cb1989a172b3d45be8c/futures-core/src/task/__internal/atomic_waker.rs
// https://github.com/tokio-rs/tokio/blob/75fef53d0a8590c2d1dbb63672aa7b7d1ef51155/tokio/src/sync/task/atomic_waker.rs
diff --git a/asyncband/src/internal/semaphore.rs b/asyncband/src/internal/semaphore.rs
index 70c3337..f537d23 100644
--- a/asyncband/src/internal/semaphore.rs
+++ b/asyncband/src/internal/semaphore.rs
@@ -15,6 +15,15 @@
// specific language governing permissions and limitations
// under the License.
+// Portions of the permit-accounting algorithm originated from Tokio 1.42.0's batch semaphore.
+// Copyright (c) Tokio Contributors
+// The Tokio-derived portions remain licensed under the MIT License.
+// Asyncband substantially replaced the waiter lifecycle with queue-owned WaitList nodes, supports
+// queue-head permit debt for exact reductions, has no closed state or reserved flag bits, and uses
+// its own cancellation, detachment, and batched-waking machinery.
+// Upstream source:
+// https://github.com/tokio-rs/tokio/blob/bb9d57017e100985f86d8ca41ac105ee9140423e/tokio/src/sync/batch_semaphore.rs
+
use std::future::Future;
use std::mem::MaybeUninit;
use std::pin::Pin;
diff --git a/asyncband/src/internal/value_cell.rs b/asyncband/src/internal/value_cell.rs
index 928b1b8..85f046a 100644
--- a/asyncband/src/internal/value_cell.rs
+++ b/asyncband/src/internal/value_cell.rs
@@ -15,6 +15,14 @@
// specific language governing permissions and limitations
// under the License.
+// This file was factored out of Asyncband's Tokio-derived OnceCell implementation.
+// Copyright (c) Tokio Contributors
+// The Tokio-derived portions remain licensed under the MIT License.
+// Unlike Tokio's storage, ValueCell has no semaphore or closed-state invariant. It provides
+// reusable value publication, mutation, removal, and reinitialization for OnceCell and LazyCell.
+// Upstream source:
+// https://github.com/tokio-rs/tokio/blob/3911cb8523f190142f61c64b66881c07c0d3e7be/tokio/src/sync/once_cell.rs
+
use std::cell::UnsafeCell;
use std::mem::MaybeUninit;
use std::sync::atomic::AtomicBool;
diff --git a/asyncband/src/mpsc/bounded.rs b/asyncband/src/mpsc/bounded.rs
index 0f398a8..3ca6098 100644
--- a/asyncband/src/mpsc/bounded.rs
+++ b/asyncband/src/mpsc/bounded.rs
@@ -36,12 +36,10 @@ use crate::internal::atomic_waker::AtomicWaker;
use crate::internal::semaphore::Acquire;
use crate::internal::semaphore::Semaphore;
-/// Creates a bounded mpsc channel for communicating between asynchronous
-/// tasks with backpressure.
+/// Creates a bounded mpsc channel with room for `buffer` queued messages.
///
-/// A `send` on this channel will wait if the buffer of the channel is full until a
-/// `recv` is called on the receiver, which will consume the message and
-/// free up space in the buffer.
+/// [`BoundedSender::send`] waits for capacity when the buffer is full. Receiving a message releases
+/// one slot for a waiting sender.
///
/// # Panics
///
@@ -72,7 +70,7 @@ struct BoundedState {
rx_waker: AtomicWaker,
}
-/// Send values to the associated [`BoundedReceiver`].
+/// The sending endpoint of a bounded mpsc channel.
///
/// Instances are created by the [`bounded`] function.
pub struct BoundedSender<T> {
@@ -114,19 +112,15 @@ impl<T> Drop for BoundedSender<T> {
}
impl<T> BoundedSender<T> {
- /// Sends a message to the associated receiver.
+ /// Sends a message, waiting until the channel has capacity when necessary.
///
- /// This method will wait if the buffer of the channel is full until a `recv` is called on the
- /// receiver, which will consume the message and free up space in the buffer.
- ///
- /// If the receiver has been dropped, this function returns an error. The error includes
- /// the value passed to `send`.
+ /// If the receiver has been dropped, the returned error contains `value`.
///
/// # Cancel safety
///
- /// Cancelling a call that is waiting for capacity removes it from the send queue and drops
- /// `value`. A poll that returns `Pending` has not enqueued the value. Use [`Self::try_send`] if
- /// the caller must recover an unsent value.
+ /// Dropping a pending `send` removes that operation from the capacity wait queue and drops
+ /// `value`; a call that has returned `Pending` has not sent the message. Use [`Self::try_send`]
+ /// when the caller must retain ownership if capacity is unavailable.
pub async fn send(&self, value: T) -> Result<(), SendError<T>> {
let value = match self.try_send(value) {
Ok(()) => return Ok(()),
@@ -177,30 +171,25 @@ impl<T> BoundedSender<T> {
poll_fn(|cx| send.poll_send(cx)).await
}
- /// Attempts to send a message to the associated receiver without waiting.
- ///
- /// This method returns the [`Full`] error if the buffer of the channel is full.
+ /// Attempts to send a message without waiting for capacity.
///
- /// This method returns the [`Disconnected`] error if the receiver has been dropped.
- ///
- /// [`Full`]: TrySendError::Full
- /// [`Disconnected`]: TrySendError::Disconnected
+ /// A full buffer returns [`TrySendError::Full`], while a dropped receiver returns
+ /// [`TrySendError::Disconnected`]. Both errors return ownership of the unsent value.
///
/// # Examples
///
/// ```
- /// # #[tokio::main]
- /// # async fn main() {
/// use asyncband::mpsc::TrySendError;
/// use asyncband::mpsc::bounded;
- /// let (tx, mut rx) = bounded::<i32>(1);
///
- /// tx.try_send(1).unwrap();
- /// assert_eq!(tx.try_send(2), Err(TrySendError::Full(2)));
+ /// let (tx, mut rx) = bounded(1);
+ /// tx.try_send(10).unwrap();
+ /// assert_eq!(tx.try_send(20), Err(TrySendError::Full(20)));
///
+ /// assert_eq!(rx.try_recv(), Ok(10));
+ /// tx.try_send(20).unwrap();
/// drop(rx);
- /// assert_eq!(tx.try_send(3), Err(TrySendError::Disconnected(3)));
- /// # }
+ /// assert_eq!(tx.try_send(30), Err(TrySendError::Disconnected(30)));
/// ```
pub fn try_send(&self, value: T) -> Result<(), TrySendError<T>> {
// INVARIANT: A shared borrow of the endpoint cannot overlap its destructor.
@@ -219,7 +208,7 @@ impl<T> BoundedSender<T> {
}
}
-/// Receives values from the associated [`BoundedSender`].
+/// The receiving endpoint of a bounded mpsc channel.
///
/// Instances are created by the [`bounded`] function.
pub struct BoundedReceiver<T> {
@@ -245,39 +234,27 @@ impl<T> Drop for BoundedReceiver<T> {
}
impl<T> BoundedReceiver<T> {
- /// Tries to receive the next value for this receiver and frees up a space in the buffer if
- /// successful.
- ///
- /// This method returns the [`Empty`] error if the channel is currently
- /// empty, but there are still outstanding [senders].
+ /// Attempts to receive the next queued value without waiting.
///
- /// This method returns the [`Disconnected`] error if the channel is
- /// currently empty, and there are no outstanding [senders].
- ///
- /// [`Empty`]: TryRecvError::Empty
- /// [`Disconnected`]: TryRecvError::Disconnected
- /// [senders]: BoundedSender
+ /// Receiving a value frees one buffer slot. An empty channel returns [`TryRecvError::Empty`]
+ /// while at least one sender remains, or [`TryRecvError::Disconnected`] after every sender has
+ /// been dropped and all queued values have been consumed.
///
/// # Examples
///
/// ```
- /// # #[tokio::main]
- /// # async fn main() {
- /// use asyncband::mpsc;
/// use asyncband::mpsc::TryRecvError;
- /// let (tx, mut rx) = mpsc::bounded(2);
- ///
- /// tx.send("hello").await.unwrap();
+ /// use asyncband::mpsc::bounded;
///
- /// assert_eq!(Ok("hello"), rx.try_recv());
- /// assert_eq!(Err(TryRecvError::Empty), rx.try_recv());
+ /// let (tx, mut rx) = bounded(2);
+ /// tx.try_send("first").unwrap();
+ /// tx.try_send("second").unwrap();
///
- /// tx.send("hello").await.unwrap();
+ /// assert_eq!(rx.try_recv(), Ok("first"));
+ /// assert_eq!(rx.try_recv(), Ok("second"));
+ /// assert_eq!(rx.try_recv(), Err(TryRecvError::Empty));
/// drop(tx);
- ///
- /// assert_eq!(Ok("hello"), rx.try_recv());
- /// assert_eq!(Err(TryRecvError::Disconnected), rx.try_recv());
- /// # }
+ /// assert_eq!(rx.try_recv(), Err(TryRecvError::Disconnected));
/// ```
pub fn try_recv(&mut self) -> Result<T, TryRecvError> {
// INVARIANT: A mutable borrow of the endpoint cannot overlap its destructor.
@@ -292,20 +269,17 @@ impl<T> BoundedReceiver<T> {
}
}
- /// Receives the next value for this receiver and frees up a space in the buffer if successful.
+ /// Waits for and receives the next value, freeing one buffer slot.
///
- /// This method returns `Err(RecvError::Disconnected)` after all senders have been dropped and
- /// no buffered messages remain. At that point, this `Receiver` can never receive another
- /// value.
- ///
- /// If the buffer is empty while a sender remains, this method waits until a message is sent or
- /// the final sender is dropped.
+ /// If no value is queued, this method waits until a sender adds one or the last sender is
+ /// dropped. It returns [`RecvError::Disconnected`] only after all senders are gone and the
+ /// buffer has been drained.
///
/// # Cancel safety
///
- /// This method is cancel safe. If `recv` is used as the event in a `select` statement
- /// and some other branch completes first, it is guaranteed that no messages were received
- /// on this channel.
+ /// Dropping a pending `recv` does not remove a message from the channel. A later receive
+ /// operation can still observe the next queued value, so `recv` may safely be raced with other
+ /// futures in a selection construct.
///
/// # Examples
///
@@ -313,30 +287,15 @@ impl<T> BoundedReceiver<T> {
/// # #[tokio::main]
/// # async fn main() {
/// use asyncband::mpsc;
- /// let (tx, mut rx) = mpsc::bounded(1);
- ///
- /// tokio::spawn(async move {
- /// tx.send("hello").await.unwrap();
- /// });
- ///
- /// assert_eq!(Ok("hello"), rx.recv().await);
- /// assert_eq!(Err(mpsc::RecvError::Disconnected), rx.recv().await);
- /// # }
- /// ```
- ///
- /// Values are buffered if the channel has enough capacity:
- ///
- /// ```
- /// # #[tokio::main]
- /// # async fn main() {
- /// use asyncband::mpsc;
/// let (tx, mut rx) = mpsc::bounded(2);
///
- /// tx.send("hello").await.unwrap();
- /// tx.send("world").await.unwrap();
+ /// tx.send("first").await.unwrap();
+ /// tx.send("second").await.unwrap();
+ /// drop(tx);
///
- /// assert_eq!(Ok("hello"), rx.recv().await);
- /// assert_eq!(Ok("world"), rx.recv().await);
+ /// assert_eq!(rx.recv().await, Ok("first"));
+ /// assert_eq!(rx.recv().await, Ok("second"));
+ /// assert_eq!(rx.recv().await, Err(mpsc::RecvError::Disconnected));
/// # }
/// ```
pub async fn recv(&mut self) -> Result<T, RecvError> {
diff --git a/asyncband/src/mpsc/error.rs b/asyncband/src/mpsc/error.rs
index 3c10549..586e4e9 100644
--- a/asyncband/src/mpsc/error.rs
+++ b/asyncband/src/mpsc/error.rs
@@ -18,13 +18,13 @@
use std::any::type_name;
use std::fmt;
-/// An error returned when trying to send on a disconnected channel.
+/// A send failed because the receiving endpoint has been dropped.
///
/// Returned from [`UnboundedSender::send`] or [`BoundedSender::send`] if the
/// corresponding [`UnboundedReceiver`] or [`BoundedReceiver`] has already been
/// dropped.
///
-/// The message that could not be sent can be retrieved again with
+/// The rejected message remains available through [`SendError::as_inner`] or
/// [`SendError::into_inner`].
///
/// [`UnboundedSender::send`]: crate::mpsc::UnboundedSender::send
@@ -65,7 +65,7 @@ impl<T> fmt::Debug for SendError<T> {
impl<T> std::error::Error for SendError<T> {}
-/// Error returned by `try_send`.
+/// A non-blocking send could not accept its message.
#[derive(Clone, PartialEq, Eq)]
pub enum TrySendError<T> {
/// The channel is full, so the message cannot be sent without waiting for capacity.
@@ -111,7 +111,7 @@ impl<T> fmt::Debug for TrySendError<T> {
impl<T> std::error::Error for TrySendError<T> {}
-/// Error returned by `recv`.
+/// A receive operation cannot produce another value.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum RecvError {
/// All senders have been dropped, and no buffered messages remain.
@@ -126,7 +126,7 @@ impl fmt::Display for RecvError {
impl std::error::Error for RecvError {}
-/// Error returned by `try_recv`.
+/// A non-blocking receive did not produce a value.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum TryRecvError {
/// No message is currently available, but at least one sender remains.
diff --git a/asyncband/src/mpsc/unbounded.rs b/asyncband/src/mpsc/unbounded.rs
index ed6eb56..cb5ca5e 100644
--- a/asyncband/src/mpsc/unbounded.rs
+++ b/asyncband/src/mpsc/unbounded.rs
@@ -31,15 +31,11 @@ use super::SendError;
use super::TryRecvError;
use crate::internal::atomic_waker::AtomicWaker;
-/// Creates an unbounded mpsc channel for communicating between asynchronous
-/// tasks without backpressure.
+/// Creates an unbounded mpsc channel whose send operation never waits for capacity.
///
-/// A `send` on this channel will always succeed as long as the receiver is alive.
-/// If the receiver falls behind, messages will be arbitrarily buffered.
-///
-/// Note that the amount of available system memory is an implicit bound to
-/// the channel. Using an `unbounded` channel has the ability of causing the
-/// process to run out of memory. In this case, the process will be aborted.
+/// While the receiver is alive, each send appends its value immediately. Pending messages can
+/// therefore grow with producer demand and are limited only by successful memory allocation. Use a
+/// bounded channel or external admission control when producers may outpace the receiver.
pub fn unbounded<T>() -> (UnboundedSender<T>, UnboundedReceiver<T>) {
let state = Arc::new(UnboundedState {
senders: AtomicUsize::new(1),
@@ -62,7 +58,7 @@ struct UnboundedState {
rx_waker: AtomicWaker,
}
-/// Send values to the associated [`UnboundedReceiver`].
+/// The sending endpoint of an unbounded mpsc channel.
///
/// Instances are created by the [`unbounded`] function.
pub struct UnboundedSender<T> {
@@ -104,14 +100,10 @@ impl<T> Drop for UnboundedSender<T> {
}
impl<T> UnboundedSender<T> {
- /// Sends a message without blocking.
- ///
- /// This method is not marked async because sending a message to an unbounded channel
- /// never requires any form of waiting. Because of this, the `send` method can be
- /// used in both synchronous and asynchronous code without problems.
+ /// Enqueues a message without waiting for capacity.
///
- /// If the receiver has been dropped, this function returns an error. The error includes
- /// the value passed to `send`.
+ /// This operation is synchronous because the channel has no capacity limit. If the receiver has
+ /// been dropped, the returned error contains `value`.
pub fn send(&self, value: T) -> Result<(), SendError<T>> {
// INVARIANT: A shared borrow of the endpoint cannot overlap its destructor.
let sender = self.sender.as_ref().unwrap();
@@ -123,7 +115,7 @@ impl<T> UnboundedSender<T> {
}
}
-/// Receive values from the associated [`UnboundedSender`].
+/// The receiving endpoint of an unbounded mpsc channel.
///
/// Instances are created by the [`unbounded`] function.
pub struct UnboundedReceiver<T> {
@@ -142,38 +134,27 @@ impl<T> fmt::Debug for UnboundedReceiver<T> {
}
impl<T> UnboundedReceiver<T> {
- /// Tries to receive the next value for this receiver.
- ///
- /// This method returns the [`Empty`] error if the channel is currently
- /// empty, but there are still outstanding [senders].
+ /// Attempts to receive the next queued value without waiting.
///
- /// This method returns the [`Disconnected`] error if the channel is
- /// currently empty, and there are no outstanding [senders].
- ///
- /// [`Empty`]: TryRecvError::Empty
- /// [`Disconnected`]: TryRecvError::Disconnected
- /// [senders]: UnboundedSender
+ /// An empty channel returns [`TryRecvError::Empty`] while at least one sender remains, or
+ /// [`TryRecvError::Disconnected`] after every sender has been dropped and all queued values
+ /// have been consumed.
///
/// # Examples
///
/// ```
- /// # #[tokio::main]
- /// # async fn main() {
- /// use asyncband::mpsc;
/// use asyncband::mpsc::TryRecvError;
- /// let (tx, mut rx) = mpsc::unbounded();
- ///
- /// tx.send("hello").unwrap();
+ /// use asyncband::mpsc::unbounded;
///
- /// assert_eq!(Ok("hello"), rx.try_recv());
- /// assert_eq!(Err(TryRecvError::Empty), rx.try_recv());
+ /// let (tx, mut rx) = unbounded();
+ /// tx.send("first").unwrap();
+ /// tx.send("second").unwrap();
///
- /// tx.send("hello").unwrap();
+ /// assert_eq!(rx.try_recv(), Ok("first"));
+ /// assert_eq!(rx.try_recv(), Ok("second"));
+ /// assert_eq!(rx.try_recv(), Err(TryRecvError::Empty));
/// drop(tx);
- ///
- /// assert_eq!(Ok("hello"), rx.try_recv());
- /// assert_eq!(Err(TryRecvError::Disconnected), rx.try_recv());
- /// # }
+ /// assert_eq!(rx.try_recv(), Err(TryRecvError::Disconnected));
/// ```
pub fn try_recv(&mut self) -> Result<T, TryRecvError> {
match self.receiver.try_recv() {
@@ -183,20 +164,17 @@ impl<T> UnboundedReceiver<T> {
}
}
- /// Receives the next value for this receiver.
- ///
- /// This method returns `Err(RecvError::Disconnected)` after all senders have been dropped and
- /// no buffered messages remain. At that point, this `Receiver` can never receive another
- /// value.
+ /// Waits for and receives the next value.
///
- /// If the buffer is empty while a sender remains, this method waits until a message is sent or
- /// the final sender is dropped.
+ /// If no value is queued, this method waits until a sender adds one or the last sender is
+ /// dropped. It returns [`RecvError::Disconnected`] only after all senders are gone and the
+ /// queue has been drained.
///
/// # Cancel safety
///
- /// This method is cancel safe. If `recv` is used as the event in a `select` statement
- /// and some other branch completes first, it is guaranteed that no messages were received
- /// on this channel.
+ /// Dropping a pending `recv` does not remove a message from the channel. A later receive
+ /// operation can still observe the next queued value, so `recv` may safely be raced with other
+ /// futures in a selection construct.
///
/// # Examples
///
@@ -206,28 +184,13 @@ impl<T> UnboundedReceiver<T> {
/// use asyncband::mpsc;
/// let (tx, mut rx) = mpsc::unbounded();
///
- /// tokio::spawn(async move {
- /// tx.send("hello").unwrap();
- /// });
- ///
- /// assert_eq!(Ok("hello"), rx.recv().await);
- /// assert_eq!(Err(mpsc::RecvError::Disconnected), rx.recv().await);
- /// # }
- /// ```
- ///
- /// Values are buffered:
- ///
- /// ```
- /// # #[tokio::main]
- /// # async fn main() {
- /// use asyncband::mpsc;
- /// let (tx, mut rx) = mpsc::unbounded();
- ///
- /// tx.send("hello").unwrap();
- /// tx.send("world").unwrap();
+ /// tx.send("first").unwrap();
+ /// tx.send("second").unwrap();
+ /// drop(tx);
///
- /// assert_eq!(Ok("hello"), rx.recv().await);
- /// assert_eq!(Ok("world"), rx.recv().await);
+ /// assert_eq!(rx.recv().await, Ok("first"));
+ /// assert_eq!(rx.recv().await, Ok("second"));
+ /// assert_eq!(rx.recv().await, Err(mpsc::RecvError::Disconnected));
/// # }
/// ```
pub async fn recv(&mut self) -> Result<T, RecvError> {
diff --git a/asyncband/src/mutex/mod.rs b/asyncband/src/mutex/mod.rs
index 1a1ac35..b0986ad 100644
--- a/asyncband/src/mutex/mod.rs
+++ b/asyncband/src/mutex/mod.rs
@@ -1,21 +1,8 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-// Portions derived from Tokio 1.41.0:
+// This file contains code derived from Tokio 1.41.0.
+// Copyright (c) Tokio Contributors
+// The derived code remains licensed under the MIT License.
+// The incorporated code has been modified for use in Apache Asyncband.
+// Upstream source:
// https://github.com/tokio-rs/tokio/blob/01e04daaa162ce6122bb894fdda0b6803dd32093/tokio/src/sync/mutex.rs
//! An async mutex for protecting shared data.
diff --git a/asyncband/src/once/once_cell/mod.rs b/asyncband/src/once/once_cell/mod.rs
index 7c4e47f..d05775b 100644
--- a/asyncband/src/once/once_cell/mod.rs
+++ b/asyncband/src/once/once_cell/mod.rs
@@ -15,6 +15,15 @@
// specific language governing permissions and limitations
// under the License.
+// Portions of this file originated from Tokio 1.47.0's OnceCell implementation.
+// Copyright (c) Tokio Contributors
+// The Tokio-derived portions remain licensed under the MIT License.
+// Asyncband substantially changed the synchronization model: initialization does not close the
+// semaphore, the cell can be emptied and initialized again, and value storage is delegated to a
+// reusable ValueCell shared with LazyCell.
+// Upstream source:
+// https://github.com/tokio-rs/tokio/blob/3911cb8523f190142f61c64b66881c07c0d3e7be/tokio/src/sync/once_cell.rs
+
use std::convert::Infallible;
use std::fmt;
diff --git a/asyncband/src/once/once_map/mod.rs b/asyncband/src/once/once_map/mod.rs
index 3923218..b3cc4f4 100644
--- a/asyncband/src/once/once_map/mod.rs
+++ b/asyncband/src/once/once_map/mod.rs
@@ -45,8 +45,8 @@ enum Lookup<K, V> {
/// A hash map that runs computation only once for each key and stores the result.
///
-/// Note that this always clones the value out of the underlying map. Because of this, it's common
-/// to wrap the `V` in an `Arc<V>` to make cloning cheap.
+/// Every successful lookup returns an owned clone of `V`. Choose a cheaply cloned value type, such
+/// as `Arc<T>`, when entries are large or frequently shared.
pub struct OnceMap<K, V, S = RandomState> {
// Hashbrown allocates the table lazily, and computation always runs after releasing this lock.
entries: Mutex<Entries<K, V>>,
diff --git a/asyncband/src/oneshot/mod.rs b/asyncband/src/oneshot/mod.rs
index 71bdd32..e591394 100644
--- a/asyncband/src/oneshot/mod.rs
+++ b/asyncband/src/oneshot/mod.rs
@@ -15,9 +15,11 @@
// specific language governing permissions and limitations
// under the License.
-// Portions derived from the oneshot crate at commit
-// 83fd0864be7289067ce96cc79cd96c0928742979:
-// https://github.com/faern/oneshot/blob/83fd0864be7289067ce96cc79cd96c0928742979/src/lib.rs
+// This file contains code derived from the oneshot crate.
+// Asyncband uses the upstream crate's Apache-2.0 license option for that code.
+// The incorporated code has been modified for use in Apache Asyncband.
+// Upstream source (oneshot v0.1.11, before its channel code was split into modules):
+// https://github.com/faern/oneshot/blob/25274e995ee0a702b3e9e1ac81e577f8c3ce0892/src/lib.rs
//! A one-shot channel is used for sending a single message between asynchronous tasks. The
//! [`channel`] function is used to create a [`Sender`] and [`Receiver`] pair that form the channel.
diff --git a/asyncband/src/oneshot/receiver.rs b/asyncband/src/oneshot/receiver.rs
index ca82f2e..fdd4ba5 100644
--- a/asyncband/src/oneshot/receiver.rs
+++ b/asyncband/src/oneshot/receiver.rs
@@ -15,9 +15,12 @@
// specific language governing permissions and limitations
// under the License.
-// Portions derived from the oneshot crate at commit
-// 83fd0864be7289067ce96cc79cd96c0928742979:
-// https://github.com/faern/oneshot/blob/83fd0864be7289067ce96cc79cd96c0928742979/src/lib.rs
+// This file contains code derived from the oneshot crate.
+// Asyncband uses the upstream crate's Apache-2.0 license option for that code.
+// The incorporated code has been modified for use in Apache Asyncband.
+// Upstream sources (oneshot v0.1.11, before its channel code was split into modules):
+// https://github.com/faern/oneshot/blob/25274e995ee0a702b3e9e1ac81e577f8c3ce0892/src/lib.rs
+// https://github.com/faern/oneshot/blob/25274e995ee0a702b3e9e1ac81e577f8c3ce0892/src/errors.rs
use std::fmt;
use std::mem::ManuallyDrop;
diff --git a/asyncband/src/oneshot/sender.rs b/asyncband/src/oneshot/sender.rs
index 99f11ea..ad4287b 100644
--- a/asyncband/src/oneshot/sender.rs
+++ b/asyncband/src/oneshot/sender.rs
@@ -15,9 +15,12 @@
// specific language governing permissions and limitations
// under the License.
-// Portions derived from the oneshot crate at commit
-// 83fd0864be7289067ce96cc79cd96c0928742979:
-// https://github.com/faern/oneshot/blob/83fd0864be7289067ce96cc79cd96c0928742979/src/lib.rs
+// This file contains code derived from the oneshot crate.
+// Asyncband uses the upstream crate's Apache-2.0 license option for that code.
+// The incorporated code has been modified for use in Apache Asyncband.
+// Upstream sources (oneshot v0.1.11, before its channel code was split into modules):
+// https://github.com/faern/oneshot/blob/25274e995ee0a702b3e9e1ac81e577f8c3ce0892/src/lib.rs
+// https://github.com/faern/oneshot/blob/25274e995ee0a702b3e9e1ac81e577f8c3ce0892/src/errors.rs
use std::any::type_name;
use std::fmt;
diff --git a/asyncband/src/oneshot/tests.rs b/asyncband/src/oneshot/tests.rs
index 4703432..a3011ab 100644
--- a/asyncband/src/oneshot/tests.rs
+++ b/asyncband/src/oneshot/tests.rs
@@ -15,9 +15,12 @@
// specific language governing permissions and limitations
// under the License.
-// Portions of the test support are adapted from the oneshot crate at commit
-// 83fd0864be7289067ce96cc79cd96c0928742979:
-// https://github.com/faern/oneshot/tree/83fd0864be7289067ce96cc79cd96c0928742979/tests/helpers
+// This file contains test support adapted from the oneshot crate.
+// Asyncband uses the upstream crate's Apache-2.0 license option for that code.
+// The incorporated code has been modified for use in Apache Asyncband.
+// Upstream test support (oneshot v0.1.11):
+// https://github.com/faern/oneshot/blob/25274e995ee0a702b3e9e1ac81e577f8c3ce0892/tests/helpers/mod.rs
+// https://github.com/faern/oneshot/blob/25274e995ee0a702b3e9e1ac81e577f8c3ce0892/tests/helpers/waker.rs
use std::future::Future;
use std::future::IntoFuture;
diff --git a/asyncband/src/pool/bounded.rs b/asyncband/src/pool/bounded.rs
index dc0ff79..6c3009a 100644
--- a/asyncband/src/pool/bounded.rs
+++ b/asyncband/src/pool/bounded.rs
@@ -1,23 +1,21 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
+// Copyright 2025 FastLabs Developers
//
-// http://www.apache.org/licenses/LICENSE-2.0
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-// Portions ported from Fastpool 1.1.1 at commit e4c65f1ed38395abc58d68eda8bd09925c13028e:
-// Copyright 2025 FastLabs Developers
-// https://github.com/fast/fastpool/tree/e4c65f1ed38395abc58d68eda8bd09925c13028e
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// This file contains code ported from Fastpool 1.1.1.
+// The incorporated code has been modified for use in Apache Asyncband.
+// Upstream source:
+// https://github.com/fast/fastpool/blob/e4c65f1ed38395abc58d68eda8bd09925c13028e/fastpool/src/bounded.rs
//! Bounded object pools.
//!
diff --git a/asyncband/src/pool/common.rs b/asyncband/src/pool/common.rs
index e59af4b..3101961 100644
--- a/asyncband/src/pool/common.rs
+++ b/asyncband/src/pool/common.rs
@@ -1,23 +1,21 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
+// Copyright 2025 FastLabs Developers
//
-// http://www.apache.org/licenses/LICENSE-2.0
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-// Portions ported from Fastpool 1.1.1 at commit e4c65f1ed38395abc58d68eda8bd09925c13028e:
-// Copyright 2025 FastLabs Developers
-// https://github.com/fast/fastpool/tree/e4c65f1ed38395abc58d68eda8bd09925c13028e
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// This file contains code ported from Fastpool 1.1.1.
+// The incorporated code has been modified for use in Apache Asyncband.
+// Upstream source:
+// https://github.com/fast/fastpool/blob/e4c65f1ed38395abc58d68eda8bd09925c13028e/fastpool/src/common.rs
use std::future::Future;
use std::time::Instant;
diff --git a/asyncband/src/pool/mod.rs b/asyncband/src/pool/mod.rs
index a306627..8895e94 100644
--- a/asyncband/src/pool/mod.rs
+++ b/asyncband/src/pool/mod.rs
@@ -1,23 +1,21 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
+// Copyright 2025 FastLabs Developers
//
-// http://www.apache.org/licenses/LICENSE-2.0
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-// Portions ported from Fastpool 1.1.1 at commit e4c65f1ed38395abc58d68eda8bd09925c13028e:
-// Copyright 2025 FastLabs Developers
-// https://github.com/fast/fastpool/tree/e4c65f1ed38395abc58d68eda8bd09925c13028e
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// This file contains code ported from Fastpool 1.1.1.
+// The incorporated code has been modified for use in Apache Asyncband.
+// Upstream source:
+// https://github.com/fast/fastpool/blob/e4c65f1ed38395abc58d68eda8bd09925c13028e/fastpool/src/lib.rs
//! Runtime-agnostic object pools for async Rust.
//!
diff --git a/asyncband/src/pool/state.rs b/asyncband/src/pool/state.rs
index abf70ed..42c80d5 100644
--- a/asyncband/src/pool/state.rs
+++ b/asyncband/src/pool/state.rs
@@ -1,23 +1,22 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
+// Copyright 2025 FastLabs Developers
//
-// http://www.apache.org/licenses/LICENSE-2.0
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-// Portions ported from Fastpool 1.1.1 at commit e4c65f1ed38395abc58d68eda8bd09925c13028e:
-// Copyright 2025 FastLabs Developers
-// https://github.com/fast/fastpool/tree/e4c65f1ed38395abc58d68eda8bd09925c13028e
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// This file contains code ported from Fastpool 1.1.1.
+// The incorporated code has been modified for use in Apache Asyncband.
+// Upstream sources:
+// https://github.com/fast/fastpool/blob/e4c65f1ed38395abc58d68eda8bd09925c13028e/fastpool/src/bounded.rs
+// https://github.com/fast/fastpool/blob/e4c65f1ed38395abc58d68eda8bd09925c13028e/fastpool/src/unbounded.rs
use std::collections::VecDeque;
diff --git a/asyncband/src/pool/unbounded.rs b/asyncband/src/pool/unbounded.rs
index 0e557b1..688533c 100644
--- a/asyncband/src/pool/unbounded.rs
+++ b/asyncband/src/pool/unbounded.rs
@@ -1,23 +1,21 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
+// Copyright 2025 FastLabs Developers
//
-// http://www.apache.org/licenses/LICENSE-2.0
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-// Portions ported from Fastpool 1.1.1 at commit e4c65f1ed38395abc58d68eda8bd09925c13028e:
-// Copyright 2025 FastLabs Developers
-// https://github.com/fast/fastpool/tree/e4c65f1ed38395abc58d68eda8bd09925c13028e
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// This file contains code ported from Fastpool 1.1.1.
+// The incorporated code has been modified for use in Apache Asyncband.
+// Upstream source:
+// https://github.com/fast/fastpool/blob/e4c65f1ed38395abc58d68eda8bd09925c13028e/fastpool/src/unbounded.rs
//! Unbounded object pools.
//!
@@ -201,13 +199,13 @@ pub struct PoolIsEmpty(());
impl std::fmt::Debug for PoolIsEmpty {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
- write!(f, "unbounded pool is empty")
+ f.write_str("unbounded pool is empty")
}
}
impl std::fmt::Display for PoolIsEmpty {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
- std::fmt::Debug::fmt(self, f)
+ f.write_str("unbounded pool is empty")
}
}
diff --git a/asyncband/src/rwlock/mapped_read_guard.rs b/asyncband/src/rwlock/mapped_read_guard.rs
index fea757e..741e286 100644
--- a/asyncband/src/rwlock/mapped_read_guard.rs
+++ b/asyncband/src/rwlock/mapped_read_guard.rs
@@ -1,22 +1,10 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-// Portions derived from Tokio 1.42.0's RwLock implementation:
-// https://github.com/tokio-rs/tokio/tree/bb9d57017e100985f86d8ca41ac105ee9140423e/tokio/src/sync/rwlock
+// This file contains code derived from Tokio 1.42.0's RwLock implementation.
+// Copyright (c) Tokio Contributors
+// The derived code remains licensed under the MIT License.
+// The incorporated code has been modified for use in Apache Asyncband.
+// Upstream sources:
+// https://github.com/tokio-rs/tokio/blob/bb9d57017e100985f86d8ca41ac105ee9140423e/tokio/src/sync/rwlock/read_guard.rs
+// https://github.com/tokio-rs/tokio/blob/bb9d57017e100985f86d8ca41ac105ee9140423e/tokio/src/sync/rwlock/write_guard_mapped.rs
use std::fmt;
use std::marker::PhantomData;
diff --git a/asyncband/src/rwlock/mapped_write_guard.rs b/asyncband/src/rwlock/mapped_write_guard.rs
index c28e0ac..04e4862 100644
--- a/asyncband/src/rwlock/mapped_write_guard.rs
+++ b/asyncband/src/rwlock/mapped_write_guard.rs
@@ -1,22 +1,9 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-// Portions derived from Tokio 1.42.0's RwLock implementation:
-// https://github.com/tokio-rs/tokio/tree/bb9d57017e100985f86d8ca41ac105ee9140423e/tokio/src/sync/rwlock
+// This file contains code derived from Tokio 1.42.0's RwLock implementation.
+// Copyright (c) Tokio Contributors
+// The derived code remains licensed under the MIT License.
+// The incorporated code has been modified for use in Apache Asyncband.
+// Upstream source:
+// https://github.com/tokio-rs/tokio/blob/bb9d57017e100985f86d8ca41ac105ee9140423e/tokio/src/sync/rwlock/write_guard_mapped.rs
use std::fmt;
use std::marker::PhantomData;
diff --git a/asyncband/src/rwlock/mod.rs b/asyncband/src/rwlock/mod.rs
index 23615aa..80d8b40 100644
--- a/asyncband/src/rwlock/mod.rs
+++ b/asyncband/src/rwlock/mod.rs
@@ -1,21 +1,8 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-// Portions derived from Tokio 1.42.0:
+// This file contains code derived from Tokio 1.42.0.
+// Copyright (c) Tokio Contributors
+// The derived code remains licensed under the MIT License.
+// The incorporated code has been modified for use in Apache Asyncband.
+// Upstream source:
// https://github.com/tokio-rs/tokio/blob/bb9d57017e100985f86d8ca41ac105ee9140423e/tokio/src/sync/rwlock.rs
//! A reader-writer lock that allows multiple readers or a single writer at a time.
diff --git a/asyncband/src/rwlock/owned_mapped_read_guard.rs b/asyncband/src/rwlock/owned_mapped_read_guard.rs
index d9d8c17..c0d6dfc 100644
--- a/asyncband/src/rwlock/owned_mapped_read_guard.rs
+++ b/asyncband/src/rwlock/owned_mapped_read_guard.rs
@@ -1,22 +1,10 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-// Portions derived from Tokio 1.42.0's RwLock implementation:
-// https://github.com/tokio-rs/tokio/tree/bb9d57017e100985f86d8ca41ac105ee9140423e/tokio/src/sync/rwlock
+// This file contains code derived from Tokio 1.42.0's RwLock implementation.
+// Copyright (c) Tokio Contributors
+// The derived code remains licensed under the MIT License.
+// The incorporated code has been modified for use in Apache Asyncband.
+// Upstream sources:
+// https://github.com/tokio-rs/tokio/blob/bb9d57017e100985f86d8ca41ac105ee9140423e/tokio/src/sync/rwlock/owned_read_guard.rs
+// https://github.com/tokio-rs/tokio/blob/bb9d57017e100985f86d8ca41ac105ee9140423e/tokio/src/sync/rwlock/owned_write_guard_mapped.rs
use std::fmt;
use std::marker::PhantomData;
diff --git a/asyncband/src/rwlock/owned_mapped_write_guard.rs b/asyncband/src/rwlock/owned_mapped_write_guard.rs
index 8093d4c..585b80a 100644
--- a/asyncband/src/rwlock/owned_mapped_write_guard.rs
+++ b/asyncband/src/rwlock/owned_mapped_write_guard.rs
@@ -1,22 +1,9 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-// Portions derived from Tokio 1.42.0's RwLock implementation:
-// https://github.com/tokio-rs/tokio/tree/bb9d57017e100985f86d8ca41ac105ee9140423e/tokio/src/sync/rwlock
+// This file contains code derived from Tokio 1.42.0's RwLock implementation.
+// Copyright (c) Tokio Contributors
+// The derived code remains licensed under the MIT License.
+// The incorporated code has been modified for use in Apache Asyncband.
+// Upstream source:
+// https://github.com/tokio-rs/tokio/blob/bb9d57017e100985f86d8ca41ac105ee9140423e/tokio/src/sync/rwlock/owned_write_guard_mapped.rs
use std::fmt;
use std::marker::PhantomData;
diff --git a/asyncband/src/rwlock/owned_read_guard.rs b/asyncband/src/rwlock/owned_read_guard.rs
index a823629..00b8d89 100644
--- a/asyncband/src/rwlock/owned_read_guard.rs
+++ b/asyncband/src/rwlock/owned_read_guard.rs
@@ -1,22 +1,9 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-// Portions derived from Tokio 1.42.0's RwLock implementation:
-// https://github.com/tokio-rs/tokio/tree/bb9d57017e100985f86d8ca41ac105ee9140423e/tokio/src/sync/rwlock
+// This file contains code derived from Tokio 1.42.0's RwLock implementation.
+// Copyright (c) Tokio Contributors
+// The derived code remains licensed under the MIT License.
+// The incorporated code has been modified for use in Apache Asyncband.
+// Upstream source:
+// https://github.com/tokio-rs/tokio/blob/bb9d57017e100985f86d8ca41ac105ee9140423e/tokio/src/sync/rwlock/owned_read_guard.rs
use std::fmt;
use std::ops::Deref;
diff --git a/asyncband/src/rwlock/owned_write_guard.rs b/asyncband/src/rwlock/owned_write_guard.rs
index e547b1a..fd183da 100644
--- a/asyncband/src/rwlock/owned_write_guard.rs
+++ b/asyncband/src/rwlock/owned_write_guard.rs
@@ -1,22 +1,9 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-// Portions derived from Tokio 1.42.0's RwLock implementation:
-// https://github.com/tokio-rs/tokio/tree/bb9d57017e100985f86d8ca41ac105ee9140423e/tokio/src/sync/rwlock
+// This file contains code derived from Tokio 1.42.0's RwLock implementation.
+// Copyright (c) Tokio Contributors
+// The derived code remains licensed under the MIT License.
+// The incorporated code has been modified for use in Apache Asyncband.
+// Upstream source:
+// https://github.com/tokio-rs/tokio/blob/bb9d57017e100985f86d8ca41ac105ee9140423e/tokio/src/sync/rwlock/owned_write_guard.rs
use std::fmt;
use std::mem::ManuallyDrop;
diff --git a/asyncband/src/rwlock/read_guard.rs b/asyncband/src/rwlock/read_guard.rs
index 68b2579..7400685 100644
--- a/asyncband/src/rwlock/read_guard.rs
+++ b/asyncband/src/rwlock/read_guard.rs
@@ -1,22 +1,9 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-// Portions derived from Tokio 1.42.0's RwLock implementation:
-// https://github.com/tokio-rs/tokio/tree/bb9d57017e100985f86d8ca41ac105ee9140423e/tokio/src/sync/rwlock
+// This file contains code derived from Tokio 1.42.0's RwLock implementation.
+// Copyright (c) Tokio Contributors
+// The derived code remains licensed under the MIT License.
+// The incorporated code has been modified for use in Apache Asyncband.
+// Upstream source:
+// https://github.com/tokio-rs/tokio/blob/bb9d57017e100985f86d8ca41ac105ee9140423e/tokio/src/sync/rwlock/read_guard.rs
use std::fmt;
use std::mem::ManuallyDrop;
diff --git a/asyncband/src/rwlock/write_guard.rs b/asyncband/src/rwlock/write_guard.rs
index 7da936b..de29337 100644
--- a/asyncband/src/rwlock/write_guard.rs
+++ b/asyncband/src/rwlock/write_guard.rs
@@ -1,22 +1,9 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-// Portions derived from Tokio 1.42.0's RwLock implementation:
-// https://github.com/tokio-rs/tokio/tree/bb9d57017e100985f86d8ca41ac105ee9140423e/tokio/src/sync/rwlock
+// This file contains code derived from Tokio 1.42.0's RwLock implementation.
+// Copyright (c) Tokio Contributors
+// The derived code remains licensed under the MIT License.
+// The incorporated code has been modified for use in Apache Asyncband.
+// Upstream source:
+// https://github.com/tokio-rs/tokio/blob/bb9d57017e100985f86d8ca41ac105ee9140423e/tokio/src/sync/rwlock/write_guard.rs
use std::fmt;
use std::mem::ManuallyDrop;
diff --git a/asyncband/src/semaphore/mod.rs b/asyncband/src/semaphore/mod.rs
index 3278458..8ce06e5 100644
--- a/asyncband/src/semaphore/mod.rs
+++ b/asyncband/src/semaphore/mod.rs
@@ -15,6 +15,15 @@
// specific language governing permissions and limitations
// under the License.
+// Portions of this file originated from Tokio 1.42.0's Semaphore and permit APIs.
+// Copyright (c) Tokio Contributors
+// The Tokio-derived portions remain licensed under the MIT License.
+// Asyncband substantially changed the contract: it has no closed state or close errors, accepts
+// usize permit counts without reserved flag bits, and adds direct drain and exact-reduction
+// operations backed by Asyncband's own waiter queue.
+// Upstream source:
+// https://github.com/tokio-rs/tokio/blob/bb9d57017e100985f86d8ca41ac105ee9140423e/tokio/src/sync/semaphore.rs
+
//! Limit concurrent access with a set of permits.
//!
//! [`Semaphore::acquire`] waits for the requested number of permits and returns a guard that puts
diff --git a/licenserc.toml b/licenserc.toml
index ec2bfc7..f004664 100644
--- a/licenserc.toml
+++ b/licenserc.toml
@@ -19,6 +19,27 @@
builtin = "Apache-2.0-ASF"
[files]
-# This adapted third-party source intentionally does not carry the ASF source header.
-excludes = ["asyncband/src/blocking/parker.rs"]
+# These third-party-derived files use the applicable upstream license and copyright notices instead
+# of the standard ASF source header.
+excludes = [
+ "asyncband/src/blocking/executor.rs",
+ "asyncband/src/blocking/parker.rs",
+ "asyncband/src/mutex/mod.rs",
+ "asyncband/src/pool/bounded.rs",
+ "asyncband/src/pool/common.rs",
+ "asyncband/src/pool/mod.rs",
+ "asyncband/src/pool/state.rs",
+ "asyncband/src/pool/unbounded.rs",
+ "asyncband/src/rwlock/mapped_read_guard.rs",
+ "asyncband/src/rwlock/mapped_write_guard.rs",
+ "asyncband/src/rwlock/mod.rs",
+ "asyncband/src/rwlock/owned_mapped_read_guard.rs",
+ "asyncband/src/rwlock/owned_mapped_write_guard.rs",
+ "asyncband/src/rwlock/owned_read_guard.rs",
+ "asyncband/src/rwlock/owned_write_guard.rs",
+ "asyncband/src/rwlock/read_guard.rs",
+ "asyncband/src/rwlock/write_guard.rs",
+ "tests-integration/tests/pool_recycle_cancelled_test.rs",
+ "tests-integration/tests/pool_replenish_test.rs",
+]
includes = ["**/*.proto", "**/*.rs", "**/*.yml", "**/*.yaml", "**/*.toml"]
diff --git a/tests-integration/tests/oneshot_test/main.rs b/tests-integration/tests/oneshot_test/main.rs
index 11f0154..98e60bb 100644
--- a/tests-integration/tests/oneshot_test/main.rs
+++ b/tests-integration/tests/oneshot_test/main.rs
@@ -15,12 +15,13 @@
// specific language governing permissions and limitations
// under the License.
-// Portions of these tests are adapted from the oneshot crate at commit
-// 83fd0864be7289067ce96cc79cd96c0928742979:
-// https://github.com/faern/oneshot/blob/83fd0864be7289067ce96cc79cd96c0928742979/tests/async.rs
-// https://github.com/faern/oneshot/blob/83fd0864be7289067ce96cc79cd96c0928742979/tests/future.rs
-// https://github.com/faern/oneshot/blob/83fd0864be7289067ce96cc79cd96c0928742979/tests/miri.rs
-// https://github.com/faern/oneshot/blob/83fd0864be7289067ce96cc79cd96c0928742979/tests/sync.rs
+// This file contains tests adapted from the oneshot crate.
+// Asyncband uses the upstream crate's Apache-2.0 license option for that code.
+// The incorporated code has been modified for use in Apache Asyncband.
+// Upstream tests (oneshot v0.1.11):
+// https://github.com/faern/oneshot/blob/25274e995ee0a702b3e9e1ac81e577f8c3ce0892/tests/async.rs
+// https://github.com/faern/oneshot/blob/25274e995ee0a702b3e9e1ac81e577f8c3ce0892/tests/future.rs
+// https://github.com/faern/oneshot/blob/25274e995ee0a702b3e9e1ac81e577f8c3ce0892/tests/sync.rs
use std::future::Future;
use std::future::IntoFuture;
diff --git a/tests-integration/tests/oneshot_test/support.rs b/tests-integration/tests/oneshot_test/support.rs
index ce3531e..0b67c36 100644
--- a/tests-integration/tests/oneshot_test/support.rs
+++ b/tests-integration/tests/oneshot_test/support.rs
@@ -15,9 +15,12 @@
// specific language governing permissions and limitations
// under the License.
-// Portions of this test support are adapted from the oneshot crate at commit
-// 83fd0864be7289067ce96cc79cd96c0928742979:
-// https://github.com/faern/oneshot/tree/83fd0864be7289067ce96cc79cd96c0928742979/tests/helpers
+// This file contains test support adapted from the oneshot crate.
+// Asyncband uses the upstream crate's Apache-2.0 license option for that code.
+// The incorporated code has been modified for use in Apache Asyncband.
+// Upstream test support (oneshot v0.1.11):
+// https://github.com/faern/oneshot/blob/25274e995ee0a702b3e9e1ac81e577f8c3ce0892/tests/helpers/mod.rs
+// https://github.com/faern/oneshot/blob/25274e995ee0a702b3e9e1ac81e577f8c3ce0892/tests/helpers/waker.rs
use std::hint::spin_loop;
use std::sync::Arc;
diff --git a/tests-integration/tests/pool_recycle_cancelled_test.rs b/tests-integration/tests/pool_recycle_cancelled_test.rs
index 88f3b55..144beaa 100644
--- a/tests-integration/tests/pool_recycle_cancelled_test.rs
+++ b/tests-integration/tests/pool_recycle_cancelled_test.rs
@@ -1,23 +1,21 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
+// Copyright 2025 FastLabs Developers
//
-// http://www.apache.org/licenses/LICENSE-2.0
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-// Portions ported from Fastpool 1.1.1 at commit e4c65f1ed38395abc58d68eda8bd09925c13028e:
-// Copyright 2025 FastLabs Developers
-// https://github.com/fast/fastpool/tree/e4c65f1ed38395abc58d68eda8bd09925c13028e
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// This file contains code ported from Fastpool 1.1.1.
+// The incorporated code has been modified for use in Apache Asyncband.
+// Upstream source:
+// https://github.com/fast/fastpool/blob/e4c65f1ed38395abc58d68eda8bd09925c13028e/fastpool/tests/recycle_cancelled_tests.rs
use std::future::Future;
use std::future::poll_fn;
diff --git a/tests-integration/tests/pool_replenish_test.rs b/tests-integration/tests/pool_replenish_test.rs
index 8e44c40..5dbca19 100644
--- a/tests-integration/tests/pool_replenish_test.rs
+++ b/tests-integration/tests/pool_replenish_test.rs
@@ -1,23 +1,21 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
+// Copyright 2025 FastLabs Developers
//
-// http://www.apache.org/licenses/LICENSE-2.0
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-// Portions ported from Fastpool 1.1.1 at commit e4c65f1ed38395abc58d68eda8bd09925c13028e:
-// Copyright 2025 FastLabs Developers
-// https://github.com/fast/fastpool/tree/e4c65f1ed38395abc58d68eda8bd09925c13028e
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// This file contains code ported from Fastpool 1.1.1.
+// The incorporated code has been modified for use in Apache Asyncband.
+// Upstream source:
+// https://github.com/fast/fastpool/blob/e4c65f1ed38395abc58d68eda8bd09925c13028e/fastpool/tests/replenish_tests.rs
use std::convert::Infallible;
use std::future::poll_fn;
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@asyncband.apache.org
For additional commands, e-mail: commits-help@asyncband.apache.org