Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1 | /* |
Willy Tarreau | 24f4efa | 2010-08-27 17:56:48 +0200 | [diff] [blame] | 2 | * include/types/task.h |
| 3 | * Macros, variables and structures for task management. |
| 4 | * |
| 5 | * Copyright (C) 2000-2010 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 | */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 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 | 96bcfd7 | 2007-04-29 10:41:56 +0200 | [diff] [blame] | 28 | #include <common/mini-clist.h> |
Willy Tarreau | 45cb4fb | 2009-10-26 21:10:04 +0100 | [diff] [blame] | 29 | #include <eb32tree.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 */ |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 33 | #define TASK_RUNNING 0x01 /* the task is currently running */ |
Willy Tarreau | fdccded | 2008-08-29 18:19:04 +0200 | [diff] [blame] | 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 | |
Willy Tarreau | 24f4efa | 2010-08-27 17:56:48 +0200 | [diff] [blame] | 47 | /* Additional wakeup info may be passed in the state by lef-shifting the value |
| 48 | * by this number of bits. Not more than 8 bits are guaranteed to be delivered. |
| 49 | * System signals may use that too. |
| 50 | */ |
| 51 | #define TASK_REASON_SHIFT 8 |
| 52 | |
Thierry FOURNIER | d697596 | 2017-07-12 14:31:10 +0200 | [diff] [blame] | 53 | struct notification { |
| 54 | struct list purge_me; /* Part of the list of signals to be purged in the |
| 55 | case of the LUA execution stack crash. */ |
| 56 | struct list wake_me; /* Part of list of signals to be targeted if an |
| 57 | event occurs. */ |
| 58 | struct task *task; /* The task to be wake if an event occurs. */ |
Thierry FOURNIER | 738a6d7 | 2017-07-17 00:14:07 +0200 | [diff] [blame] | 59 | #ifdef USE_THREAD |
| 60 | HA_SPINLOCK_T lock; |
| 61 | #endif |
Thierry FOURNIER | d697596 | 2017-07-12 14:31:10 +0200 | [diff] [blame] | 62 | }; |
| 63 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 64 | /* The base for all tasks */ |
| 65 | struct task { |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 66 | struct eb32_node rq; /* ebtree node used to hold the task in the run queue */ |
Willy Tarreau | 05efc0f | 2013-12-07 01:01:39 +0100 | [diff] [blame] | 67 | unsigned short state; /* task state : bit field of TASK_* */ |
Emeric Brun | 0194897 | 2017-03-30 15:37:25 +0200 | [diff] [blame] | 68 | unsigned short pending_state; /* pending states for running talk */ |
Willy Tarreau | 05efc0f | 2013-12-07 01:01:39 +0100 | [diff] [blame] | 69 | short nice; /* the task's current nice value from -1024 to +1024 */ |
Willy Tarreau | 3884cba | 2009-03-28 17:54:35 +0100 | [diff] [blame] | 70 | unsigned int calls; /* number of times ->process() was called */ |
Willy Tarreau | 26c2506 | 2009-03-08 09:38:41 +0100 | [diff] [blame] | 71 | struct task * (*process)(struct task *t); /* the function which processes the task */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 72 | void *context; /* the task's context */ |
Willy Tarreau | 05efc0f | 2013-12-07 01:01:39 +0100 | [diff] [blame] | 73 | struct eb32_node wq; /* ebtree node used to hold the task in the wait queue */ |
| 74 | int expire; /* next expiration date for this task, in ticks */ |
Emeric Brun | c60def8 | 2017-09-27 14:59:38 +0200 | [diff] [blame] | 75 | unsigned long process_mask; /* mask of thread IDs authorized to process the task */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 76 | }; |
| 77 | |
Willy Tarreau | 26c2506 | 2009-03-08 09:38:41 +0100 | [diff] [blame] | 78 | /* |
| 79 | * The task callback (->process) is responsible for updating ->expire. It must |
| 80 | * return a pointer to the task itself, except if the task has been deleted, in |
| 81 | * which case it returns NULL so that the scheduler knows it must not check the |
| 82 | * expire timer. The scheduler will requeue the task at the proper location. |
| 83 | */ |
| 84 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 85 | #endif /* _TYPES_TASK_H */ |
| 86 | |
| 87 | /* |
| 88 | * Local variables: |
| 89 | * c-indent-level: 8 |
| 90 | * c-basic-offset: 8 |
| 91 | * End: |
| 92 | */ |