1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

sys/ztimer: ztimer_remove return its success

Co-authored-by: Marian Buschsieweke <maribu@users.noreply.github.com>
This commit is contained in:
chrysn 2021-12-15 14:34:26 +01:00
parent 0afed1de20
commit 991f74a62a
2 changed files with 18 additions and 5 deletions

View File

@ -408,8 +408,14 @@ unsigned ztimer_is_set(const ztimer_clock_t *clock, const ztimer_t *timer);
*
* @param[in] clock ztimer clock to operate on
* @param[in] timer timer entry to remove
*
* @retval true The timer was removed (and thus its callback neither was nor
* will be called by ztimer).
* @retval false The timer fired previously or is not set on the @p clock
* at all.
*
*/
void ztimer_remove(ztimer_clock_t *clock, ztimer_t *timer);
bool ztimer_remove(ztimer_clock_t *clock, ztimer_t *timer);
/**
* @brief Post a message after a delay

View File

@ -37,7 +37,7 @@
#include "debug.h"
static void _add_entry_to_list(ztimer_clock_t *clock, ztimer_base_t *entry);
static void _del_entry_from_list(ztimer_clock_t *clock, ztimer_base_t *entry);
static bool _del_entry_from_list(ztimer_clock_t *clock, ztimer_base_t *entry);
static void _ztimer_update(ztimer_clock_t *clock);
static void _ztimer_print(const ztimer_clock_t *clock);
static uint32_t _ztimer_update_head_offset(ztimer_clock_t *clock);
@ -68,18 +68,20 @@ unsigned ztimer_is_set(const ztimer_clock_t *clock, const ztimer_t *timer)
return res;
}
void ztimer_remove(ztimer_clock_t *clock, ztimer_t *timer)
bool ztimer_remove(ztimer_clock_t *clock, ztimer_t *timer)
{
bool was_removed = false;
unsigned state = irq_disable();
if (_is_set(clock, timer)) {
_ztimer_update_head_offset(clock);
_del_entry_from_list(clock, &timer->base);
was_removed = _del_entry_from_list(clock, &timer->base);
_ztimer_update(clock);
}
irq_restore(state);
return was_removed;
}
uint32_t ztimer_set(ztimer_clock_t *clock, ztimer_t *timer, uint32_t val)
@ -232,8 +234,10 @@ static uint32_t _ztimer_update_head_offset(ztimer_clock_t *clock)
return now;
}
static void _del_entry_from_list(ztimer_clock_t *clock, ztimer_base_t *entry)
static bool _del_entry_from_list(ztimer_clock_t *clock, ztimer_base_t *entry)
{
bool was_removed = false;
DEBUG("_del_entry_from_list()\n");
ztimer_base_t *list = &clock->list;
@ -254,6 +258,7 @@ static void _del_entry_from_list(ztimer_clock_t *clock, ztimer_base_t *entry)
list_entry->offset += entry->offset;
}
was_removed = true;
/* reset the entry's next pointer so _is_set() considers it unset */
entry->next = NULL;
break;
@ -268,6 +273,8 @@ static void _del_entry_from_list(ztimer_clock_t *clock, ztimer_base_t *entry)
pm_unblock(clock->block_pm_mode);
}
#endif
return was_removed;
}
static ztimer_t *_now_next(ztimer_clock_t *clock)