-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit adds an implementation of the event-listener algorithm built without locks. This is a replacement of the old no_std backend. It is written without concurrent-queue and therefore closes #109. The idea behind this implementation is to store the listeners in "slots" in an infinitely large list. Then, assign each listener a number and then use that to wait on each listener. The list used is similar to the one used by the thread-local crate. It consists of a list of "buckets" that hold slots. The number of slots increases in an amortized way. The first slot holds 1, the second slot holds 2, the third slot holds 4... all the way up to usize::MAX slots. Indexes are done by having a list of reusable indexes and using those when possible, only increasing the max index when necessary. This part of the code could use some work; under contention it's possible to make some slots unusuable. This can happen under two cases: - If there is contention on the indexes list when the listener is being freed. - If the slot is still being notified when it is attempted to be reused. Both of these cases are probably fixable, and should be fixed before release. Otherwise long running server processes using this code will run out of memory under heavy loads. From here the rest of the implementation is an atomic linked list based on the above primitives. It functions very similarly to the std variant. The main difference is that the Link structure's waker functions very similarly to AtomicWaker from the atomic-waker crate. Aside from that the code isn't very interesting on its own. Signed-off-by: John Nunley <[email protected]>
- Loading branch information
Showing
9 changed files
with
1,061 additions
and
203 deletions.
There are no files selected for viewing
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ name = "event-listener" | |
version = "2.5.3" | ||
authors = ["Stjepan Glavina <[email protected]>"] | ||
edition = "2021" | ||
rust-version = "1.56" | ||
rust-version = "1.59" | ||
description = "Notify async tasks or threads" | ||
license = "Apache-2.0 OR MIT" | ||
repository = "https://github.com/smol-rs/event-listener" | ||
|
@@ -21,9 +21,8 @@ portable-atomic = ["portable-atomic-crate", "portable-atomic-util"] | |
|
||
[dependencies] | ||
portable-atomic-crate = { version = "1.6.0", package = "portable-atomic", optional = true } | ||
portable-atomic-util = { version = "0.1.5", optional = true } | ||
portable-atomic-util = { version = "0.1.5", features = ["alloc"], optional = true } | ||
|
||
[dev-dependencies] | ||
futures = { version = "0.3", default-features = false, features = ["std"] } | ||
futures-lite = "2.3.0" | ||
waker-fn = "1" |
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
Oops, something went wrong.