Author: bonefish Date: 2011-05-28 01:34:37 +0200 (Sat, 28 May 2011) New Revision: 41785 Changeset: https://dev.haiku-os.org/changeset/41785 Modified: haiku/branches/developer/bonefish/signals/headers/private/kernel/timer.h haiku/branches/developer/bonefish/signals/src/system/kernel/timer.cpp Log: Introduced flag B_TIMER_USE_TIMER_STRUCT_TIMES for add_timer(). When specified the function ignores the period parameter and instead uses the timer::period and timer::schedule_time fields. This allows to add a periodic timer with a start time independent from the interval. Modified: haiku/branches/developer/bonefish/signals/headers/private/kernel/timer.h =================================================================== --- haiku/branches/developer/bonefish/signals/headers/private/kernel/timer.h 2011-05-27 22:45:43 UTC (rev 41784) +++ haiku/branches/developer/bonefish/signals/headers/private/kernel/timer.h 2011-05-27 23:34:37 UTC (rev 41785) @@ -15,8 +15,15 @@ struct kernel_args; +#define B_TIMER_USE_TIMER_STRUCT_TIMES 0x4000 + // For add_timer(): Use the timer::schedule_time (absolute time) and + // timer::period values instead of the period parameter. #define B_TIMER_ACQUIRE_SCHEDULER_LOCK 0x8000 -#define B_TIMER_FLAGS B_TIMER_ACQUIRE_SCHEDULER_LOCK + // The timer hook is invoked with the scheduler lock held. When invoking + // cancel_timer() with the scheduler lock held, too, this helps to avoid + // race conditions. +#define B_TIMER_FLAGS \ + (B_TIMER_USE_TIMER_STRUCT_TIMES | B_TIMER_ACQUIRE_SCHEDULER_LOCK) /* Timer info structure */ struct timer_info { Modified: haiku/branches/developer/bonefish/signals/src/system/kernel/timer.cpp =================================================================== --- haiku/branches/developer/bonefish/signals/src/system/kernel/timer.cpp 2011-05-27 22:45:43 UTC (rev 41784) +++ haiku/branches/developer/bonefish/signals/src/system/kernel/timer.cpp 2011-05-27 23:34:37 UTC (rev 41785) @@ -168,7 +168,6 @@ status_t add_timer(timer* event, timer_hook hook, bigtime_t period, int32 flags) { - bigtime_t scheduleTime; bigtime_t currentTime = system_time(); cpu_status state; @@ -177,12 +176,19 @@ TRACE(("add_timer: event %p\n", event)); - scheduleTime = period; - if ((flags & ~B_TIMER_FLAGS) != B_ONE_SHOT_ABSOLUTE_TIMER) - scheduleTime += currentTime; + // compute the schedule time + bigtime_t scheduleTime; + if ((flags & B_TIMER_USE_TIMER_STRUCT_TIMES) != 0) { + scheduleTime = event->schedule_time; + period = event->period; + } else { + scheduleTime = period; + if ((flags & ~B_TIMER_FLAGS) != B_ONE_SHOT_ABSOLUTE_TIMER) + scheduleTime += currentTime; + event->schedule_time = (int64)scheduleTime; + event->period = period; + } - event->schedule_time = (int64)scheduleTime; - event->period = period; event->hook = hook; event->flags = flags;