Skip to content

Commit

Permalink
libtock-sync: alarm: Support empty delays
Browse files Browse the repository at this point in the history
If libtocksync_alarm_delay_ms() is provided a delay of 0ms we currenty
schedule an alarm which is a high overhead for a empty delay.

Instead let's just call a yield_no_wait() and return success if we don't
actually need to delay.

Signed-off-by: Alistair Francis <[email protected]>
  • Loading branch information
alistair23 committed Jul 7, 2024
1 parent 30f4ee9 commit c2379b0
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions libtock-sync/services/alarm.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ int libtocksync_alarm_delay_ms(uint32_t ms) {
libtock_alarm_t alarm;
int rc;

if (ms == 0) {
yield_no_wait();
return RETURNCODE_SUCCESS;
}

if ((rc = libtock_alarm_in_ms(ms, delay_cb, NULL, &alarm)) != RETURNCODE_SUCCESS) {
return rc;
}
Expand Down

0 comments on commit c2379b0

Please sign in to comment.