Skip to content
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

sys/event/timeout: add event_timeout_is_pending() #19963

Merged
merged 2 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions sys/include/event/timeout.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,18 @@ void event_timeout_set(event_timeout_t *event_timeout, uint32_t timeout);
*/
void event_timeout_clear(event_timeout_t *event_timeout);

/**
* @brief Check if a timeout event is scheduled to be executed in the future
*
* @param[in] event_timeout event_timout context object to use
* @return true if the event is scheduled, false otherwise
*/
static inline bool event_timeout_is_pending(const event_timeout_t *event_timeout)
{
return ztimer_is_set(event_timeout->clock, &event_timeout->timer)
|| event_is_queued(event_timeout->queue, event_timeout->event);
}

#ifdef __cplusplus
}
#endif
Expand Down
2 changes: 2 additions & 0 deletions tests/sys/events/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
const char *text;
} custom_event_t;

static custom_event_t custom_event = { .super.handler = custom_callback, .text = "CUSTOM CALLBACK" };

Check warning on line 73 in tests/sys/events/main.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
static event_callback_t* event_callback_ptr;
static event_callback_t noevent_callback = EVENT_CALLBACK_INIT(forbidden_callback, 0);

Expand All @@ -94,7 +94,7 @@
uint32_t now = xtimer_now_usec();
#endif
expect((now - before >= 100000LU));
printf("triggered timed callback with arg 0x%08x after %" PRIu32 "us\n", (unsigned)arg, now - before);

Check warning on line 97 in tests/sys/events/main.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
puts("[SUCCESS]");
}

Expand Down Expand Up @@ -197,6 +197,7 @@
before = xtimer_now_usec();
#endif
event_timeout_set(&event_timeout, (1 * US_PER_SEC));
expect(event_timeout_is_pending(&event_timeout));

event_timeout_t event_timeout_canceled;

Expand All @@ -205,6 +206,7 @@
(event_t *)&noevent_callback);
event_timeout_set(&event_timeout_canceled, 500 * US_PER_MS);
event_timeout_clear(&event_timeout_canceled);
expect(!event_timeout_is_pending(&event_timeout_canceled));

puts("launching event queue");
event_loop(&queue);
Expand Down
Loading