-
-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(maitake): add wait::Semaphore
#301
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This is a draft primarily because I'd like to add docs. |
hawkw
changed the title
[WIP] feat(maitake): add
feat(maitake): add Aug 29, 2022
wait::Semaphore
wait::Semaphore
@jamesmunns any opinions as to whether this belongs in |
This was referenced Aug 30, 2022
hawkw
added a commit
that referenced
this pull request
Aug 30, 2022
currently, `maitake` has a `wait` module, which contains `WaitCell`, `WaitQueue`, `WaitMap`, and (as of #301) `Semaphore`. in addition, it has a separate `sync` module, which currently contains `Mutex` and nothing else (and may grow a `RwLock` eventually/soon). this feels a bit unfortunate --- the `wait` types are also synchronization primitives. this branch moves all of `maitake::wait` into `maitake::sync`. in addition,i fixed up the docs a little bit. closes #302
hawkw
added a commit
that referenced
this pull request
Sep 1, 2022
This branch adds an async read-write lock implementation in `maitake::sync`. This lock is implemented using the `Semaphore` type added in #301. The rwlock is modeled using a `Semaphore` with `Semaphore::MAX_PERMITS` permits in it; a reader must acquire a single permit to gain read access, while a writer must acquire all the permits.
hawkw
added a commit
that referenced
this pull request
Sep 1, 2022
This branch adds an async read-write lock implementation in `maitake::sync`. This lock is implemented using the `Semaphore` type added in #301. The rwlock is modeled using a `Semaphore` with `Semaphore::MAX_PERMITS` permits in it; a reader must acquire a single permit to gain read access, while a writer must acquire all the permits.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
A semaphore is a useful synchronization type for things like
rate-limiting async tasks. It could also be used as a lower-level
primitive to implement things like read-write locks1 and
channels2.
This branch adds an asynchronous semaphore implementation in
maitake::wait
. The implementation is based on the implementation Iwrote for Tokio in tokio-rs/tokio#2325, with some code simplified a bit
as it was not necessary to maintain Tokio's required API surface.
Closes #299
Footnotes
a rwlock can be modeled by a semaphore with n permits (where n
is the maximum number of concurrent readers); each reader must
acquire a single permit, while a writer must acquire n permits). ↩
a bounded MPSC channel of capacity n can be implemented using a
semaphore with n permits, where each producer must acquire a
single permit to write, and every time a message is consumed, the
reader releases a permit to the writers. ↩