History log of /haiku/src/system/kernel/events/wait_for_objects.cpp
Revision Date Author Comments
# 2d43eebc 04-Aug-2023 Augustin Cavalier <waddlesplash@gmail.com>

kernel: Store "next" pointer before notifying B_EVENT_INVALID.

Once B_EVENT_INVALID has been set, the select routine is free to
delete the select_info at any time. We therefore cannot access
the "next" pointer after notify_select_events returns.

May fix a KDL seen by trungnt2910.


# f66d2b46 26-Jul-2023 Augustin Cavalier <waddlesplash@gmail.com>

kernel: Add event queue implementation to wait for objects efficiently.

Based on hamishm's original patch from 2015, but heavily modified,
refactored, and reworked.

From the original commit message:

> When an object is deleted, a B_EVENT_INVALID event is delivered,
> and the object is unregistered from the queue.
>
> The special event flag B_EVENT_ONE_SHOT can be passed in when adding
> an object so that the object is automatically unregistered when an
> event is delivered.

Modifications to the original change include:

* Removed the public interface (syscalls remain private for the moment)

* Event list queueing/dequeueing almost entirely rewritten, including:
- Clear events field when dequeueing.

- Have B_EVENT_QUEUED actually indicate whether the event has been
appended to the linked list (or not), based around lock state.
The previous logic was prone to races and double-insertions.

- "Modify" is now just "Deselect + Select" performed at once;
previously it could cause use-after-frees.

- Unlock for deselect only once at the end of dequeue.

- Handle INVALID events still in the queue upon destruction,
fixing memory leaks.

* Deduplified code with wait_for_objects.

* Use of C++ virtual dispatch instead of C-style enum + function calls,
and BReferenceable plus destructors for teardown.

* Removed select/modify/delete flags. Select/Modify are now the same
operation on the syscall interface, and "Delete" is done when 0
is passed for "events". Additionally, the events selected can be fetched
by passing -1 for "events".

* Implemented level-triggered mode.

* Use of BStackOrHeapArray and other convenience routines in syscalls.

Change-Id: I1d2f094fd981c95215a59adbc087523c7bbbe40b
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6745
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: Jérôme Duval <jerome.duval@gmail.com>


# ddde98b0 24-Jul-2023 Augustin Cavalier <waddlesplash@gmail.com>

kernel: Move some source files around.

* stack_protector.cpp now lives with other files in "lib".

* Notifications.cpp, wait_for_objects.cpp go to a new "events" directory,
which will soon contain more files related to the event_queue.

No functional change.