* - return the date of next event in <next> or eternity.
*/
-void process_runnable_tasks(int *next);
+void process_runnable_tasks();
/*
* Extract all expired timers from the timer queue, and wakes up all
* associated tasks. Returns the date of next event (or eternity).
*/
-void wake_expired_tasks(int *next);
+int wake_expired_tasks();
/* Perform minimal initializations, report 0 in case of error, 1 if OK. */
int init_task();
tv_update_date(0,1);
while (1) {
+ /* Process a few tasks */
+ process_runnable_tasks();
+
/* check if we caught some signals and process them */
signal_process_queue();
/* Check if we can expire some tasks */
- wake_expired_tasks(&next);
-
- /* Process a few tasks */
- process_runnable_tasks(&next);
+ next = wake_expired_tasks();
/* stop when there's nothing left to do */
if (jobs == 0)
/*
* Extract all expired timers from the timer queue, and wakes up all
- * associated tasks. Returns the date of next event (or eternity) in <next>.
+ * associated tasks. Returns the date of next event (or eternity).
*/
-void wake_expired_tasks(int *next)
+int wake_expired_tasks()
{
struct task *task;
struct eb32_node *eb;
if (likely(tick_is_lt(now_ms, eb->key))) {
/* timer not expired yet, revisit it later */
- *next = eb->key;
- return;
+ return eb->key;
}
/* timer looks expired, detach it from the queue */
task_wakeup(task, TASK_WOKEN_TIMER);
}
- /* We have found no task to expire in any tree */
- *next = TICK_ETERNITY;
- return;
+ /* No task is expired */
+ return TICK_ETERNITY;
}
/* The run queue is chronologically sorted in a tree. An insertion counter is
*
* The function adjusts <next> if a new event is closer.
*/
-void process_runnable_tasks(int *next)
+void process_runnable_tasks()
{
struct task *t;
unsigned int max_processed;
- int expire;
run_queue_cur = run_queue; /* keep a copy for reporting */
nb_tasks_cur = nb_tasks;
if (likely(niced_tasks))
max_processed = (max_processed + 3) / 4;
- expire = *next;
-
while (max_processed--) {
/* Note: this loop is one of the fastest code path in
* the whole program. It should not be re-arranged
if (likely(t != NULL)) {
t->state &= ~TASK_RUNNING;
- if (t->expire) {
+ if (t->expire)
task_queue(t);
- expire = tick_first_2nz(expire, t->expire);
- }
}
}
- *next = expire;
}
/* perform minimal intializations, report 0 in case of error, 1 if OK. */