Skip to content

Commit 04607ed

Browse files
committed
ztimer: add on_demand_strict
Enforce ztimer_clock_t to be active (i.e. clock->users > 0) before ztimer_now() can be called.
1 parent f9b5837 commit 04607ed

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

sys/include/ztimer.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,12 +576,18 @@ ztimer_now_t _ztimer_now_extend(ztimer_clock_t *clock);
576576
* @warning don't compare ztimer_now() values from different clocks. The
577577
* clocks are almost certainly not synchronized.
578578
*
579+
* @warning Make sure to call @ref ztimer_acquire(@p clock) before fetching
580+
* the clock's current time.
581+
*
579582
* @param[in] clock ztimer clock to operate on
580583
*
581584
* @return Current count on @p clock
582585
*/
583586
static inline ztimer_now_t ztimer_now(ztimer_clock_t *clock)
584587
{
588+
#if MODULE_ZTIMER_ONDEMAND_STRICT
589+
assert(clock->users > 0);
590+
#endif
585591
#if MODULE_ZTIMER_NOW64
586592
if (1) {
587593
#elif MODULE_ZTIMER_EXTEND
@@ -610,6 +616,10 @@ static inline ztimer_now_t ztimer_now(ztimer_clock_t *clock)
610616
* If the time (@p last_wakeup + @p period) has already passed, the function
611617
* sets @p last_wakeup to @p last_wakeup + @p period and returns immediately.
612618
*
619+
* @warning Make sure to call @ref ztimer_acquire(@p clock) before making use
620+
* of @ref ztimer_periodic_wakeup. After usage
621+
* @ref ztimer_release(@p clock) should be called.
622+
*
613623
* @param[in] clock ztimer clock to operate on
614624
* @param[in] last_wakeup base time stamp for the wakeup
615625
* @param[in] period time in ticks that will be added to @p last_wakeup

sys/ztimer/Makefile.dep

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ ifneq (,$(filter ztimer_%,$(USEMODULE)))
4848
USEMODULE += ztimer_extend
4949
endif
5050

51+
ifneq (,$(filter ztimer_ondemand_strict,$(USEMODULE)))
52+
USEMODULE += ztimer_ondemand
53+
endif
54+
5155
ifneq (,$(filter ztimer_convert_%,$(USEMODULE)))
5256
USEMODULE += ztimer_convert
5357
endif

0 commit comments

Comments
 (0)