blob: 41f889c88c31e66f813b8988caa44b30d63930c2 [file] [log] [blame]
Willy Tarreaubaaee002006-06-26 02:48:02 +02001/*
2 include/types/task.h
3 Macros, variables and structures for task management.
4
Willy Tarreau4726f532009-03-07 17:25:21 +01005 Copyright (C) 2000-2009 Willy Tarreau - w@1wt.eu
Willy Tarreaubaaee002006-06-26 02:48:02 +02006
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 _TYPES_TASK_H
23#define _TYPES_TASK_H
24
Willy Tarreaubaaee002006-06-26 02:48:02 +020025#include <sys/time.h>
26
Willy Tarreaue3ba5f02006-06-29 18:54:54 +020027#include <common/config.h>
Willy Tarreau96bcfd72007-04-29 10:41:56 +020028#include <common/mini-clist.h>
Willy Tarreau45cb4fb2009-10-26 21:10:04 +010029#include <eb32tree.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020030
31/* values for task->state */
Willy Tarreaufdccded2008-08-29 18:19:04 +020032#define TASK_SLEEPING 0x00 /* task sleeping */
Willy Tarreau4726f532009-03-07 17:25:21 +010033#define TASK_RUNNING 0x01 /* the task is currently running */
Willy Tarreaufdccded2008-08-29 18:19:04 +020034#define TASK_WOKEN_INIT 0x02 /* woken up for initialisation purposes */
35#define TASK_WOKEN_TIMER 0x04 /* woken up because of expired timer */
36#define TASK_WOKEN_IO 0x08 /* woken up because of completed I/O */
37#define TASK_WOKEN_SIGNAL 0x10 /* woken up by a system signal */
38#define TASK_WOKEN_MSG 0x20 /* woken up by another task's message */
39#define TASK_WOKEN_RES 0x40 /* woken up because of available resource */
40#define TASK_WOKEN_OTHER 0x80 /* woken up for an unspecified reason */
41
42/* use this to check a task state or to clean it up before queueing */
43#define TASK_WOKEN_ANY (TASK_WOKEN_OTHER|TASK_WOKEN_INIT|TASK_WOKEN_TIMER| \
44 TASK_WOKEN_IO|TASK_WOKEN_SIGNAL|TASK_WOKEN_MSG| \
45 TASK_WOKEN_RES)
Willy Tarreaubaaee002006-06-26 02:48:02 +020046
47/* The base for all tasks */
48struct task {
Willy Tarreau4726f532009-03-07 17:25:21 +010049 struct eb32_node wq; /* ebtree node used to hold the task in the wait queue */
50 struct eb32_node rq; /* ebtree node used to hold the task in the run queue */
Willy Tarreaufdccded2008-08-29 18:19:04 +020051 int state; /* task state : bit field of TASK_* */
Willy Tarreaud0a201b2009-03-08 15:53:06 +010052 int expire; /* next expiration date for this task, in ticks */
Willy Tarreau3884cba2009-03-28 17:54:35 +010053 unsigned int calls; /* number of times ->process() was called */
Willy Tarreau26c25062009-03-08 09:38:41 +010054 struct task * (*process)(struct task *t); /* the function which processes the task */
Willy Tarreaubaaee002006-06-26 02:48:02 +020055 void *context; /* the task's context */
Willy Tarreau91e99932008-06-30 07:51:00 +020056 int nice; /* the task's current nice value from -1024 to +1024 */
Willy Tarreaubaaee002006-06-26 02:48:02 +020057};
58
Willy Tarreau26c25062009-03-08 09:38:41 +010059/*
60 * The task callback (->process) is responsible for updating ->expire. It must
61 * return a pointer to the task itself, except if the task has been deleted, in
62 * which case it returns NULL so that the scheduler knows it must not check the
63 * expire timer. The scheduler will requeue the task at the proper location.
64 */
65
Willy Tarreaubaaee002006-06-26 02:48:02 +020066#endif /* _TYPES_TASK_H */
67
68/*
69 * Local variables:
70 * c-indent-level: 8
71 * c-basic-offset: 8
72 * End:
73 */