lkml.org 
[lkml]   [2009]   [May]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [RFC] mod_timer() helper functions?
From
How about something like these helper functions?

The function names "timer_settime_msecs()" and "timer_settime_secs()"
are not fantastic, but they are inspired by the precedent set by the
POSIX Realtime function timer_settime().


/**
* timer_settime_msecs - modify a timer's timeout
* @timer: the timer to be modified
* @msecs: minimum time in milliseconds to sleep for
*/
int timer_settime_msecs(struct timer_list *timer, int msecs)
{
unsigned long expires = jiffies + msecs_to_jiffies(msecs);

/* TODO? round_jiffies() if msecs parameter is large, say >= ~5000? */
/* If people don't mind if timer_settime_msecs() rounds to
whole seconds, then timer_settime_secs() might be unnecessary. */

return mod_timer(timer, expires);
}


/**
* timer_settime_secs - modify a timer's timeout
* @timer: the timer to be modified
* @secs: approximate time in seconds to sleep for
*/
int timer_settime_secs(struct timer_list *timer, time_t secs)
{
unsigned long expires = jiffies + (secs * HZ);

/* If the caller doesn't mind waiting multiple seconds, then
* feel free to round up to whole seconds (to reduce wakeups).
*/
if (secs >= 2)
expires = round_jiffies_up(expires);

return mod_timer(timer, expires);
}


\
 
 \ /
  Last update: 2009-05-20 09:15    [W:1.415 / U:0.036 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site