2006-06-26 00:48:02 +00:00
|
|
|
/*
|
|
|
|
include/proto/task.h
|
|
|
|
Functions for task management.
|
|
|
|
|
2008-06-24 06:17:16 +00:00
|
|
|
Copyright (C) 2000-2008 Willy Tarreau - w@1wt.eu
|
2006-06-26 00:48:02 +00:00
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation, version 2.1
|
|
|
|
exclusively.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _PROTO_TASK_H
|
|
|
|
#define _PROTO_TASK_H
|
|
|
|
|
|
|
|
|
|
|
|
#include <sys/time.h>
|
2006-06-29 16:54:54 +00:00
|
|
|
|
|
|
|
#include <common/config.h>
|
2006-06-29 15:53:05 +00:00
|
|
|
#include <common/memory.h>
|
2007-04-29 08:41:56 +00:00
|
|
|
#include <common/mini-clist.h>
|
|
|
|
#include <common/standard.h>
|
|
|
|
|
2006-06-29 16:54:54 +00:00
|
|
|
#include <types/task.h>
|
2006-06-26 00:48:02 +00:00
|
|
|
|
2008-06-30 05:51:00 +00:00
|
|
|
extern unsigned int run_queue; /* run queue size */
|
|
|
|
extern unsigned int niced_tasks; /* number of niced tasks in the run queue */
|
2007-05-13 17:43:47 +00:00
|
|
|
extern struct pool_head *pool2_task;
|
2008-07-05 16:16:19 +00:00
|
|
|
extern struct task *last_timer; /* optimization: last queued timer */
|
2007-05-13 17:43:47 +00:00
|
|
|
|
2008-06-24 06:17:16 +00:00
|
|
|
/* perform minimal initializations, report 0 in case of error, 1 if OK. */
|
2007-05-13 17:43:47 +00:00
|
|
|
int init_task();
|
2007-04-29 08:41:56 +00:00
|
|
|
|
2008-08-29 16:19:04 +00:00
|
|
|
/* puts the task <t> in run queue with reason flags <f>, and returns <t> */
|
2008-08-29 13:26:14 +00:00
|
|
|
struct task *__task_wakeup(struct task *t);
|
2008-08-29 16:19:04 +00:00
|
|
|
static inline struct task *task_wakeup(struct task *t, unsigned int f)
|
2008-08-29 13:26:14 +00:00
|
|
|
{
|
2008-08-29 16:19:04 +00:00
|
|
|
if (likely(!(t->state & TASK_IN_RUNQUEUE)))
|
|
|
|
__task_wakeup(t);
|
|
|
|
t->state |= f;
|
|
|
|
return t;
|
2008-08-29 13:26:14 +00:00
|
|
|
}
|
2006-06-26 00:48:02 +00:00
|
|
|
|
2007-04-29 08:41:56 +00:00
|
|
|
/* removes the task <t> from the run queue if it was in it.
|
|
|
|
* returns <t>.
|
2006-06-26 00:48:02 +00:00
|
|
|
*/
|
2007-04-29 08:41:56 +00:00
|
|
|
static inline struct task *task_sleep(struct task *t)
|
2006-06-26 00:48:02 +00:00
|
|
|
{
|
2008-08-29 16:19:04 +00:00
|
|
|
if (t->state & TASK_IN_RUNQUEUE) {
|
|
|
|
t->state = TASK_SLEEPING;
|
2008-06-29 20:40:23 +00:00
|
|
|
eb32_delete(&t->eb);
|
|
|
|
run_queue--;
|
2008-06-30 05:51:00 +00:00
|
|
|
if (likely(t->nice))
|
|
|
|
niced_tasks--;
|
2006-06-26 00:48:02 +00:00
|
|
|
}
|
2007-04-29 08:41:56 +00:00
|
|
|
return t;
|
2006-06-26 00:48:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-04-29 08:41:56 +00:00
|
|
|
* unlinks the task from wherever it is queued :
|
2008-06-29 20:40:23 +00:00
|
|
|
* - run_queue
|
2008-06-24 06:17:16 +00:00
|
|
|
* - wait queue
|
2007-04-29 08:41:56 +00:00
|
|
|
* A pointer to the task itself is returned.
|
2006-06-26 00:48:02 +00:00
|
|
|
*/
|
2008-07-05 16:16:19 +00:00
|
|
|
static inline struct task *task_dequeue(struct task *t)
|
2006-06-26 00:48:02 +00:00
|
|
|
{
|
2008-07-05 16:16:19 +00:00
|
|
|
if (likely(t->eb.node.leaf_p)) {
|
|
|
|
if (last_timer == t)
|
|
|
|
last_timer = NULL;
|
2008-06-24 06:17:16 +00:00
|
|
|
eb32_delete(&t->eb);
|
2008-07-05 16:16:19 +00:00
|
|
|
}
|
|
|
|
return t;
|
|
|
|
}
|
2008-06-24 06:17:16 +00:00
|
|
|
|
2008-07-05 16:16:19 +00:00
|
|
|
/*
|
|
|
|
* Unlinks the task and adjusts run queue stats.
|
|
|
|
* A pointer to the task itself is returned.
|
|
|
|
*/
|
|
|
|
static inline struct task *task_delete(struct task *t)
|
|
|
|
{
|
|
|
|
task_dequeue(t);
|
2008-08-29 16:19:04 +00:00
|
|
|
if (t->state & TASK_IN_RUNQUEUE) {
|
2008-06-29 20:40:23 +00:00
|
|
|
run_queue--;
|
2008-06-30 05:51:00 +00:00
|
|
|
if (likely(t->nice))
|
|
|
|
niced_tasks--;
|
|
|
|
}
|
2008-06-24 06:17:16 +00:00
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize a new task. The bare minimum is performed (queue pointers and state).
|
|
|
|
* The task is returned.
|
|
|
|
*/
|
|
|
|
static inline struct task *task_init(struct task *t)
|
|
|
|
{
|
|
|
|
t->eb.node.leaf_p = NULL;
|
2008-08-29 16:19:04 +00:00
|
|
|
t->state = TASK_SLEEPING;
|
2008-06-30 05:51:00 +00:00
|
|
|
t->nice = 0;
|
2006-06-26 00:48:02 +00:00
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* frees a task. Its context must have been freed since it will be lost.
|
|
|
|
*/
|
|
|
|
static inline void task_free(struct task *t)
|
|
|
|
{
|
2007-05-13 17:43:47 +00:00
|
|
|
pool_free2(pool2_task, t);
|
2006-06-26 00:48:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* inserts <task> into its assigned wait queue, where it may already be. In this case, it
|
|
|
|
* may be only moved or left where it was, depending on its timing requirements.
|
|
|
|
* <task> is returned.
|
|
|
|
*/
|
|
|
|
struct task *task_queue(struct task *task);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This does 4 things :
|
|
|
|
* - wake up all expired tasks
|
|
|
|
* - call all runnable tasks
|
|
|
|
* - call maintain_proxies() to enable/disable the listeners
|
2007-05-12 20:35:00 +00:00
|
|
|
* - return the date of next event in <next> or eternity.
|
2006-06-26 00:48:02 +00:00
|
|
|
*/
|
|
|
|
|
2008-07-06 22:09:58 +00:00
|
|
|
void process_runnable_tasks(int *next);
|
2006-06-26 00:48:02 +00:00
|
|
|
|
2008-06-29 20:40:23 +00:00
|
|
|
/*
|
|
|
|
* Extract all expired timers from the timer queue, and wakes up all
|
|
|
|
* associated tasks. Returns the date of next event (or eternity).
|
|
|
|
*/
|
2008-07-06 22:09:58 +00:00
|
|
|
void wake_expired_tasks(int *next);
|
2008-06-29 20:40:23 +00:00
|
|
|
|
2006-06-26 00:48:02 +00:00
|
|
|
|
|
|
|
#endif /* _PROTO_TASK_H */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* c-indent-level: 8
|
|
|
|
* c-basic-offset: 8
|
|
|
|
* End:
|
|
|
|
*/
|