Commit d529ae44 authored by Alessandro Rubini's avatar Alessandro Rubini

include/wrc-task: add an helper for periodic tasks

Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent ed59a870
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
/* /*
* A task is a data structure, but currently suboptimal. * A task is a data structure, but currently suboptimal.
* FIXME: init must return int, and both should get a pointer to data * FIXME: init must return int, and both should get a pointer to data
* FIXME: provide a jiffy-based period. * (but doing this is heavy, and forces to change the submodule too).
*/ */
struct wrc_task { struct wrc_task {
...@@ -23,6 +23,27 @@ struct wrc_task { ...@@ -23,6 +23,27 @@ struct wrc_task {
unsigned long nanos; unsigned long nanos;
}; };
/* An helper for periodic tasks, relying on a static varible */
static inline int __task_not_yet(uint32_t *lastt, unsigned period,
uint32_t now)
{
if (!*lastt) {
*lastt = now;
return 0;
}
if (time_before(now, *lastt + period))
return 1; /* not yet */
*lastt += period;
return 0;
}
static inline int task_not_yet(uint32_t *lastt, unsigned period)
{
return __task_not_yet(lastt, period, timer_get_tics());
}
/* Put the tasks in their own section */ /* Put the tasks in their own section */
#define DEFINE_WRC_TASK(_name) \ #define DEFINE_WRC_TASK(_name) \
static struct wrc_task __task_ ## _name \ static struct wrc_task __task_ ## _name \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment