Skip to content

Commit

Permalink
Fix multiwaiter public header. (#419)
Browse files Browse the repository at this point in the history
It had a load of left-over things in it from when the scheduler knew
about event groups.

---------

Co-authored-by: Nathaniel Wesley Filardo <[email protected]>
  • Loading branch information
davidchisnall and nwf authored Jan 17, 2025
1 parent 7c12bd5 commit 95ba13d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 43 deletions.
44 changes: 7 additions & 37 deletions sdk/include/multiwaiter.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,55 +33,25 @@
#include <stdlib.h>
#include <timeout.h>

/**
* The kind of event source to wait for in a multiwaiter.
*/
enum EventWaiterKind
{
/// Event source is an event channel.
EventWaiterEventChannel,
/// Event source is a futex.
EventWaiterFutex
};

enum [[clang::flag_enum]] EventWaiterEventChannelFlags
{
/// Automatically clear the bits we waited on.
EventWaiterEventChannelClearOnExit = (1 << 24),
/// Notify when all bits were set.
EventWaiterEventChannelWaitAll = (1 << 26)
};

/**
* Structure describing a change to the set of managed event sources for an
* event waiter.
*/
struct EventWaiterSource
{
/**
* A pointer to the event source. For a futex, this should be the memory
* address. For other sources, it should be a pointer to an object of the
* corresponding type.
* A pointer to the event source. This is the futex that is monitored for
* the multiwaiter.
*/
void *eventSource;
/**
* The kind of the event source. This must match the pointer type.
*/
enum EventWaiterKind kind;
/**
* Event-specific configuration. This field is modified during the wait
* call. The interpretation of this depends on `kind`:
* Event value. This field is modified during the wait
* call.
*
* - `EventWaiterEventChannel`: The low 24 bits contain the bits to
* monitor, the top bit indicates whether this event is triggered if all
* of the bits are set (true) or some of them (false). On return, this
* contains the bits that have been set during the call.
* - `EventWaiterFutex`: This indicates the value to compare the futex word
* against. If they mismatch, the event fires immediately.
* This indicates the value to compare the futex word against. If they
* mismatch, the event fires immediately.
*
* If waiting for a futex, signal the event immediately if the value
* does not match. On return, this is set to 1 if the futex is
* signaled, 0 otherwise.
* On return, this is set to 1 if the futex is signaled, 0 otherwise.
*/
uint32_t value;
};
Expand Down
12 changes: 6 additions & 6 deletions tests/multiwaiter-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ int test_multiwaiter()
EventWaiterSource events[4];

debug_log("Testing error case: Invalid values");
events[0] = {nullptr, static_cast<EventWaiterKind>(5), 0};
events[0] = {nullptr, 0};
ret = multiwaiter_wait(&t, mw, events, 1);
TEST(ret == -EINVAL, "multiwaiter returned {}, expected {}", ret, -EINVAL);

debug_log("Testing one futex, already ready");
events[0] = {&futex, EventWaiterFutex, 1};
events[0] = {&futex, 1};
t.remaining = 5;
ret = multiwaiter_wait(&t, mw, events, 1);
TEST(ret == 0, "multiwaiter returned {}, expected 0", ret);
Expand All @@ -53,7 +53,7 @@ int test_multiwaiter()

debug_log("Testing one futex, not yet ready");
setFutex(&futex, 1);
events[0] = {&futex, EventWaiterFutex, 0};
events[0] = {&futex, 0};
t.remaining = 6;
ret = multiwaiter_wait(&t, mw, events, 1);
TEST(ret == 0, "multiwaiter returned {}, expected 0", ret);
Expand All @@ -62,8 +62,8 @@ int test_multiwaiter()
futex = 0;
futex2 = 2;
setFutex(&futex2, 3);
events[0] = {&futex, EventWaiterFutex, 0};
events[1] = {&futex2, EventWaiterFutex, 2};
events[0] = {&futex, 0};
events[1] = {&futex2, 2};
t.remaining = 6;
ret = multiwaiter_wait(&t, mw, events, 2);
TEST(ret == 0, "multiwaiter returned {}, expected 0", ret);
Expand Down Expand Up @@ -118,7 +118,7 @@ int test_multiwaiter()
futex = 0;
setFutex(&futex, 1);
multiwaiter_queue_receive_init(&events[0], queue);
events[1] = {&futex, EventWaiterFutex, 0};
events[1] = {&futex, 0};
t.remaining = 6;
ret = multiwaiter_wait(&t, mw, events, 2);
TEST(ret == 0, "multiwait on futex and queue returned {}", ret);
Expand Down

0 comments on commit 95ba13d

Please sign in to comment.