blob: 8bd973a513fbcce64c1b58f1eb6e9050d7f8bc94 [file] [log] [blame]
Willy Tarreaubaaee002006-06-26 02:48:02 +02001/*
2 include/proto/task.h
3 Functions for task management.
4
5 Copyright (C) 2000-2006 Willy Tarreau - w@1wt.eu
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation, version 2.1
10 exclusively.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20*/
21
22#ifndef _PROTO_TASK_H
23#define _PROTO_TASK_H
24
25
26#include <sys/time.h>
Willy Tarreaue3ba5f02006-06-29 18:54:54 +020027
28#include <common/config.h>
Willy Tarreau2dd0d472006-06-29 17:53:05 +020029#include <common/memory.h>
Willy Tarreaue3ba5f02006-06-29 18:54:54 +020030#include <types/task.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020031
32
33/* puts the task <t> in run queue <q>, and returns <t> */
34static inline struct task *task_wakeup(struct task **q, struct task *t)
35{
36 if (t->state == TASK_RUNNING)
37 return t;
38 else {
39 t->rqnext = *q;
40 t->state = TASK_RUNNING;
41 return *q = t;
42 }
43}
44
45/* removes the task <t> from the queue <q>
46 * <s> MUST be <q>'s first task.
47 * set the run queue to point to the next one, and return it
48 */
49static inline struct task *task_sleep(struct task **q, struct task *t)
50{
51 if (t->state == TASK_RUNNING) {
52 *q = t->rqnext;
53 t->state = TASK_IDLE; /* tell that s has left the run queue */
54 }
55 return *q; /* return next running task */
56}
57
58/*
59 * removes the task <t> from its wait queue. It must have already been removed
60 * from the run queue. A pointer to the task itself is returned.
61 */
62static inline struct task *task_delete(struct task *t)
63{
Willy Tarreau964c9362007-01-07 00:38:00 +010064 rb_erase(&t->rb_node, t->wq);
65 t->wq = NULL;
Willy Tarreaubaaee002006-06-26 02:48:02 +020066 return t;
67}
68
69/*
70 * frees a task. Its context must have been freed since it will be lost.
71 */
72static inline void task_free(struct task *t)
73{
74 pool_free(task, t);
75}
76
77/* inserts <task> into its assigned wait queue, where it may already be. In this case, it
78 * may be only moved or left where it was, depending on its timing requirements.
79 * <task> is returned.
80 */
81struct task *task_queue(struct task *task);
82
83/*
84 * This does 4 things :
85 * - wake up all expired tasks
86 * - call all runnable tasks
87 * - call maintain_proxies() to enable/disable the listeners
88 * - return the delay till next event in ms, -1 = wait indefinitely
89 * Note: this part should be rewritten with the O(ln(n)) scheduler.
90 *
91 */
92
93int process_runnable_tasks();
94
95
96#endif /* _PROTO_TASK_H */
97
98/*
99 * Local variables:
100 * c-indent-level: 8
101 * c-basic-offset: 8
102 * End:
103 */