+static unsigned int task_helper(struct timespec *last, struct timespec *now, unsigned int period, void do_task())
+{
+ unsigned int next, since;
+
+ since = mtime_since(last, now);
+ if (since >= period || period - since < 10) {
+ do_task();
+ timespec_add_msec(last, since);
+ if (since > period)
+ next = period - (since - period);
+ else
+ next = period;
+ } else
+ next = period - since;
+
+ return next;
+}
+