#ifndef INCLUDED_OS_TIMEWHEEL_H #define INCLUDED_OS_TIMEWHEEL_H #ifndef INCLUDED_OS_TYPES_H #include #endif /*INCLUDED_OS_TYPES_H*/ #ifndef INCLUDED_OS_TIMER_H #include #endif /*INCLUDED_OS_TIMER_H*/ #ifndef INCLUDED_OS_MACROS_H #include #endif /*INCLUDED_OS_MACROS_H*/ /* -------------------------------------------------------------------------------------------------------------- */ /* */ #define OS_TIMEWHEEL_TICK_OK 0 #define OS_TIMEWHEEL_TICK_NEED_SCHEDULE 201 /* -------------------------------------------------------------------------------------------------------------- */ /* |------|------|------|------|--------| * 6 6 6 6 8(R) * N3 N2 N1 N0 */ #define TWR_BITS 8 #define TWN_BITS 6 #define TWN_MASK 0x3F #define TWR_SIZE (1<>(TWR_BITS + (N)*TWN_BITS)) & TWN_MASK) /* -------------------------------------------------------------------------------------------------------------- */ /* */ extern volatile os_tick_t os_timewheel__tick; extern os_list_t os_timewheel__R[TWR_SIZE]; extern os_list_t os_timewheel__N0[TWN_SIZE]; extern os_list_t os_timewheel__N1[TWN_SIZE]; extern os_list_t os_timewheel__N2[TWN_SIZE]; extern os_list_t os_timewheel__N3[TWN_SIZE]; OS_STATIC_FORCE_INLINE void os_timewheel_init(void) { os_timewheel__tick = 0; for (os_size_t i=0; inode); os_timer_init(timer, function, userdata, ticks, flags); timer->expire_tick = os_timewheel__tick + ticks; os_list_t* wheel = os_timewheel_find(timer->expire_tick); os_list_insert_before(wheel, &timer->node); } OS_STATIC_FORCE_INLINE void os_timewheel_add_until_timer(os_timer_t* timer, os_timer_function_t function, void* userdata, os_tick_t ticks, int flags) { os_timer_init(timer, function, userdata, ticks, flags); timer->expire_tick = ticks; os_list_t* wheel = os_timewheel_find(timer->expire_tick); os_list_insert_before(wheel, &timer->node); } os_err_t os_timewheel_tick(void); /* ------------------------------------------------------------------------------------------------------------------ */ /* */ #define OS_AddTimer os_timewheel_add_timer #define OS_AddUntilTimer os_timewheel_add_until_timer #define OS_TimerTick os_timewheel_tick #endif /*INCLUDED_OS_TIMEWHEEL_H*/