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

ztimer: warn users when calling ztimer_now() on inactive clocks

This commit is contained in:
Jue 2022-11-03 14:25:04 +01:00
parent 96b7988511
commit 2b53f35a28
2 changed files with 29 additions and 2 deletions

View File

@ -554,6 +554,17 @@ int ztimer_msg_receive_timeout(ztimer_clock_t *clock, msg_t *msg,
*/
ztimer_now_t _ztimer_now_extend(ztimer_clock_t *clock);
/**
* @brief asserts the given clock to be active
*
* @internal
*
* @note This function is internal
*
* @param[in] clock ztimer clock to operate on
*/
void _ztimer_assert_clock_active(ztimer_clock_t *clock);
/**
* @brief Get the current time from a clock
*
@ -668,9 +679,10 @@ ztimer_now_t _ztimer_now_extend(ztimer_clock_t *clock);
*/
static inline ztimer_now_t ztimer_now(ztimer_clock_t *clock)
{
#if MODULE_ZTIMER_ONDEMAND_STRICT
assert(clock->users > 0);
#if MODULE_ZTIMER_ONDEMAND && DEVELHELP
_ztimer_assert_clock_active(clock);
#endif
#if MODULE_ZTIMER_NOW64
if (1) {
#elif MODULE_ZTIMER_EXTEND

View File

@ -32,6 +32,7 @@
#include "pm_layered.h"
#endif
#include "ztimer.h"
#include "log.h"
#define ENABLE_DEBUG 0
#include "debug.h"
@ -529,3 +530,17 @@ static void _ztimer_print(const ztimer_clock_t *clock)
} while ((entry = entry->next));
puts("");
}
#if MODULE_ZTIMER_ONDEMAND && DEVELHELP
void _ztimer_assert_clock_active(ztimer_clock_t *clock)
{
if (clock->users == 0) {
LOG_WARNING("WARNING! You are accessing ztimer_now() on a non-active clock!\n"
" Make sure to call ztimer_acquire() before accessing ztimer_now().\n"
" Once you've finished don't forget to call ztimer_release().\n");
}
#if MODULE_ZTIMER_ONDEMAND_STRICT
assert(clock->users > 0);
#endif
}
#endif