Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1 | /* |
| 2 | include/types/task.h |
| 3 | Macros, variables and structures for task management. |
| 4 | |
Willy Tarreau | 9789f7b | 2008-06-24 08:17:16 +0200 | [diff] [blame] | 5 | Copyright (C) 2000-2008 Willy Tarreau - w@1wt.eu |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 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 _TYPES_TASK_H |
| 23 | #define _TYPES_TASK_H |
| 24 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 25 | #include <sys/time.h> |
| 26 | |
Willy Tarreau | e3ba5f0 | 2006-06-29 18:54:54 +0200 | [diff] [blame] | 27 | #include <common/config.h> |
Willy Tarreau | 9789f7b | 2008-06-24 08:17:16 +0200 | [diff] [blame] | 28 | #include <common/eb32tree.h> |
Willy Tarreau | 96bcfd7 | 2007-04-29 10:41:56 +0200 | [diff] [blame] | 29 | #include <common/mini-clist.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 30 | |
| 31 | /* values for task->state */ |
Willy Tarreau | fdccded | 2008-08-29 18:19:04 +0200 | [diff] [blame] | 32 | #define TASK_SLEEPING 0x00 /* task sleeping */ |
| 33 | #define TASK_IN_RUNQUEUE 0x01 /* the task is in the run queue */ |
| 34 | #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 Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 46 | |
| 47 | /* The base for all tasks */ |
| 48 | struct task { |
Willy Tarreau | 9789f7b | 2008-06-24 08:17:16 +0200 | [diff] [blame] | 49 | struct eb32_node eb; /* ebtree node used to hold the task in the wait queue */ |
Willy Tarreau | fdccded | 2008-08-29 18:19:04 +0200 | [diff] [blame] | 50 | int state; /* task state : bit field of TASK_* */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 51 | unsigned int expire; /* next expiration time for this task */ |
| 52 | void (*process)(struct task *t, int *next); /* the function which processes the task */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 53 | void *context; /* the task's context */ |
Willy Tarreau | 91e9993 | 2008-06-30 07:51:00 +0200 | [diff] [blame] | 54 | int nice; /* the task's current nice value from -1024 to +1024 */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 55 | }; |
| 56 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 57 | #endif /* _TYPES_TASK_H */ |
| 58 | |
| 59 | /* |
| 60 | * Local variables: |
| 61 | * c-indent-level: 8 |
| 62 | * c-basic-offset: 8 |
| 63 | * End: |
| 64 | */ |