Commit Graph

101 Commits

Author SHA1 Message Date
Jacob Rothstein f402b7e24c feat: Add a loom implementation for event-listener 2024-03-30 12:00:55 -07:00
John Nunley 58dbfc8bc5 docs: Make empty listener panic clearer
This commit makes the panic message for a listener that's not inserted
into the linked list much clearer. The goal is to convey to the user
that they may be `poll`ing the listener after it has completed.

This commit also fixes some new Clippy lints.

cc #124

Signed-off-by: John Nunley <dev@notgull.net>
2024-03-28 08:37:08 -07:00
John Nunley c9d736a29b
feat: Mark StackSlot as Sync
Since it has no interior mutability it should be safe to share between
threads.

Signed-off-by: John Nunley <dev@notgull.net>
2024-02-25 18:02:44 -08:00
Matt Klein e5464b4fdc StackSlot should be send
Signed-off-by: Matt Klein <mklein@bitdrift.io>
2024-02-10 09:53:46 -08:00
John Nunley 6e6202b3f1 chore: Polish the implementation of the new API
* Make sure Unpin is implemented for StackListener
* Purge the prelude
* Remove unused imports from doctests

Signed-off-by: John Nunley <dev@notgull.net>
2024-02-03 09:49:22 -08:00
John Nunley 6fc00c0f3f feat: Move Future impl to forwarding macro
Signed-off-by: John Nunley <dev@notgull.net>
2024-02-03 09:49:22 -08:00
John Nunley 68be5281d7 feat: Add stack-based listener
It is instantiated with the listener!() macro.

Signed-off-by: John Nunley <dev@notgull.net>
2024-02-03 09:49:22 -08:00
John Nunley d9144a8a41 feat: Create Listener trait
This commit creates the Listener trait and moves most of EventListener's
functionality to that trait.

Signed-off-by: John Nunley <dev@notgull.net>
2024-02-03 09:49:22 -08:00
John Nunley 86b778074c feat: Move EventListener back onto the heap
Minimal amount of changes to make EventListener a heap-allocated type
again. The existence of the EventListener implies that it is already
listening; accordingly the new() and listen() methods on EventListener
have been removed.

cc #104

Signed-off-by: John Nunley <dev@notgull.net>
2024-02-03 09:49:22 -08:00
John Nunley ac18bdf617
chore: Fix up some minor bits before release
Signed-off-by: John Nunley <dev@notgull.net>
2024-01-27 12:21:00 -08:00
Linken Quy Dinh a68f5ee1b0
feat: Add a way to get the current number of listeners 2024-01-24 20:59:40 -08:00
Taiki Endo 5f5135ed81 Remove RefCell<Option> from PARKER 2024-01-07 22:28:46 +09:00
Anton e0c8290f0d
bugfix: Avoid spinning when waiting for deadline 2023-12-25 07:30:31 -08:00
John Nunley c2d1ccb7ae
bugfix: Remove listener if one already exists
This commit makes it so EventListener::listen() does not overwrite
existing listeners if they already exist. If the listener is already
registered in an event listener list, it removes the listener from that
list before registering the new listener. This soundness bug was missed
during #94.

This is a patch-compatible fix for #100. We may also want an API-level
fix for #100 as well. This is up for further discussion.

Signed-off-by: John Nunley <dev@notgull.net>
2023-12-18 07:28:51 -08:00
John Nunley 21b34bf6dd
breaking: Fix the EventListener::new() footgun
This is a breaking change. It makes `new()` take no parameters in its
signature and `listen()` take a reference to an event in its signature.
This should avoid a footgun where a listener can be waited on without
listening on it.

Closes #91

Signed-off-by: John Nunley <dev@notgull.net>
2023-11-15 06:01:17 -08:00
Pierre Krieger 3f0d516c80
feat: Implement `UnwindSafe` for `EventListener` 2023-11-12 12:49:31 -08:00
Irine 74e82311c9
m: Update fmt::Debug to produce new info
Co-authored-by: John Nunley <dev@notgull.net>
2023-10-22 07:56:56 -07:00
John Nunley 5c1124135b
Fix doctest and nitpick
Signed-off-by: John Nunley <dev@notgull.net>
2023-10-18 08:35:13 -07:00
John Nunley ac3978ebb4
docs: Document that EventListeners must be listen'd on
In retrospect it is sometimes unclear in the documentation that the new event
listener needs to be pinned and inserted into the list before it can receive
events. This PR adds documentation that should clarify this issue.

Closes #89

Signed-off-by: John Nunley <dev@notgull.net>
2023-10-17 21:39:08 -07:00
Taiki Endo ccd2dfe873
Migrate to Rust 2021 (#85) 2023-10-13 10:36:17 +09:00
John Nunley 10bae60266
tests: Fix MIRI test errors
Signed-off-by: John Nunley <dev@notgull.net>
2023-10-12 16:41:11 -07:00
Taiki Endo 7bbabd02f5
Relax memory ordering in AtomicCell::replace (#83) 2023-09-10 23:49:32 +09:00
Taiki Endo 450942e773
Disable IntoNotification::tag with no_std (#81) 2023-09-10 23:49:15 +09:00
Taiki Endo 4965dddf8f
Remove extra comma from cfg (#82) 2023-09-10 22:56:05 +09:00
John Nunley c278371cfb
feat: Add explicit web support
This commit adds WASM compilation support to this crate. The main thing
is that the wait() family of APIs are removed in WASM mode, as blocking
is not allowed in WASM.

In addition, tests are added to CI to support WASM.

Signed-off-by: John Nunley <dev@notgull.net>
2023-08-26 12:53:39 -07:00
John Nunley 85ca6d3feb
feat: Implement UnwindSafe on core
With the new MSRV, UnwindSafe is now in libcore.

Signed-off-by: John Nunley <dev@notgull.net>
2023-08-24 08:07:32 -07:00
John Nunley e408ccda10
bugfix: Tracking down a deadlock in async-channel
There was a deadlock where notifications would not get delivered for
listeners that were stuck in the fallback queue. There is an
optimization where the notification count is checked to see if the
notifications delivered by the user would make any impact on the
listener chain; if it wouldn't, then it isn't done at all. For no_std,
I've removed this optimization, as I doubt that it can be done
consistently due to the nature of the fallback queue.

During testing I also uncovered problems with the current implementation
of the fallback queue itself. I've replaced it with concurrent-queue for
now, as I doubt that a fully functioning queue wouldn't be trivial
enough to justify inlining it into event-listener itself. Unfortunately
it adds three additional dependencies to the tree of event-listener.

With this change, the async-channel tests pass consistently.

Signed-off-by: John Nunley <dev@notgull.net>
2023-08-19 08:36:34 -07:00
John Nunley 564b84b416
m: Remove tag support from no_std
For tagging to work under no-std mode, the tags would need to be stored
in the backup queue. For notifications for std::usize::MAX listeners,
this is not possible. Therefore the only strategy left to use that doesn't
massively constrain the use of tagging is to remove tags from no_std
mode.

Closes #73

Signed-off-by: John Nunley <dev@notgull.net>
2023-08-17 14:13:51 -07:00
John Nunley 1c95cd2eec
bugfix: Fix a couple of bugs in the no_std implementation
- Prevent a panic for when the task has already been taken in the node
- Fix a null pointer dereference in the backup queue

Signed-off-by: John Nunley <dev@notgull.net>
2023-08-17 08:36:29 -07:00
Taiki Endo 7ce2634cb5
bugfix: Use inline assembly in full_fence
Bumps the MSRV to 1.59
2023-08-13 14:31:59 -07:00
Taiki Endo 0ea464102e
m: Remove most of Pin API related unsafe code
- Use Option::as_pin_mut/Pin::set
- Use pin-project-lite
2023-08-09 12:27:09 -07:00
Taiki Endo a1c3570ede
docs: Fix typos 2023-08-09 12:22:36 -07:00
John Nunley 6b6644a557
feat: Add an is_listening() method to the event listener
This allows users to determine if the listener is registered without needing to keep track of external state.

Signed-off-by: John Nunley <dev@notgull.net>
2023-08-06 14:41:28 -07:00
John Nunley 7c42a41290
Add smol-rs logo (#63) 2023-07-17 14:41:30 +09:00
John Nunley d6065ed8cb
Make sure Event/EventListener are Send/Sync (#59)
Necessary to resolve failing tests in smol-rs/async-channel#59
2023-05-22 18:28:02 -07:00
jtnunley e2e89d2d55
Add documentation of new functionality 2023-05-20 11:33:19 -07:00
jtnunley 6345794547 Make the notify() function return notified count
Fix off-by-one error in implementation
2023-05-17 15:12:13 -07:00
John Nunley 6d2a09741c
feat: Add an "is_notified" function (#48) 2023-05-14 10:28:18 -07:00
jtnunley 92750544c4
Replace boxed closure with a vec of tags
This should hopefully reduce the amount of allocation on the cold no_std
path
2023-05-10 10:06:41 -07:00
John Nunley a7e74b256d Fix doctests 2023-04-04 16:05:49 -07:00
John Nunley 15b4ea27ff Seal the Notification and IntoNotification traits
This PR seals these two traits to prevent breaking changes from causing
semver breaks. It also adds documentation to both traits.
2023-04-04 15:49:43 -07:00
jtnunley 723c3282bb Fix various CI errors
Fixes the following issues:

- Failed to build on MSRV due to Unpin bound
- Failed to build on no_std, as I didn't import Box
- Failed to build on portable-atomic, as Arc didn't implement Unpin
2023-04-04 09:44:23 -07:00
jtnunley e001c7a0c8 Add a type parameter T to Event
Sets up tagged events to use the Notification trait.
2023-04-03 07:37:26 -07:00
jtnunley 266b60d2b1 Change out SingleNotify for GenericNotify 2023-04-03 07:35:52 -07:00
jtnunley 5f67dd0cff Adjust the Notification logic slightly
I missed that this is needed for notification propogation.
2023-04-03 07:35:52 -07:00
jtnunley d986a5c9c3 Add the Notification trait
This will be used to replace the notify_* family of functions.
2023-04-03 07:35:52 -07:00
John Nunley e909945dcb
Add a portable-atomic feature (#53) 2023-04-02 21:36:44 -07:00
notgull 72bfe0733b Review comments 2023-04-02 11:24:24 -07:00
jtnunley 8208309a6d Forgot to adjust length in remove() 2023-03-31 14:04:55 -07:00
jtnunley 17952d648e Fix code review/CI issues 2023-03-31 13:58:16 -07:00