]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MINOR] task: new function task_schedule() to schedule a wake up
authorWilly Tarreau <w@1wt.eu>
Mon, 25 Jul 2011 12:30:42 +0000 (14:30 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 25 Jul 2011 13:30:39 +0000 (15:30 +0200)
This function is used when a task should be woken up at most at a given
date. This will be used with rate shapers.

include/proto/task.h

index 2c02ca6ef5bef4e633993e4523f1af99fd8afbd5..adcae4cf0002765b9ba8b9052c4b9fef48cc7fca 100644 (file)
@@ -224,6 +224,23 @@ static inline void task_queue(struct task *task)
                __task_queue(task);
 }
 
+/* Ensure <task> will be woken up at most at <when>. If the task is already in
+ * the run queue (but not running), nothing is done. It may be used that way
+ * with a delay :  task_schedule(task, tick_add(now_ms, delay));
+ */
+static inline void task_schedule(struct task *task, int when)
+{
+       if (task_in_rq(task))
+               return;
+
+       if (task_in_wq(task))
+               when = tick_first(when, task->expire);
+
+       task->expire = when;
+       if (!task_in_wq(task) || tick_is_lt(task->expire, task->wq.key))
+               __task_queue(task);
+}
+
 /*
  * This does 4 things :
  *   - wake up all expired tasks