c - hrtimer_init() 中的 hrtimer 定时器模式与 hrtimer_start() 中的到期模式
问题描述
我很难理解为什么我们有两种 hrtimer 模式。hrtimer_start()(和相关函数)中的到期模式与 hrtimer_init() 中的定时器模式相比有什么影响?
解决方案
在中,和hrtimer_init(timer, clock_id, mode)
之间的唯一区别是函数可以用if替换值:HRTIMER_MODE_ABS
HRTIMER_MODE_REL
clock_id
CLOCK_REALTIME
CLOCK_MONOTONIC
HRTIMER_MODE_REL
/*
* POSIX magic: Relative CLOCK_REALTIME timers are not affected by
* clock modifications, so they needs to become CLOCK_MONOTONIC to
* ensure POSIX compliance.
*/
if (clock_id == CLOCK_REALTIME && mode & HRTIMER_MODE_REL)
clock_id = CLOCK_MONOTONIC;
在hrtimer_start(timer, tim, mode)
中,mode & HRTIMER_MODE_REL
表示tim
相对于当前时间。