1/* $OpenBSD: task.h,v 1.18 2020/08/01 08:40:20 anton Exp $ */
2
3/*
4 * Copyright (c) 2013 David Gwynne <dlg@openbsd.org>
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19#ifndef _SYS_TASK_H_
20#define _SYS_TASK_H_
21
22#include <sys/queue.h>
23
24struct taskq;
25
26struct task {
27 TAILQ_ENTRY(task) t_entry;
28 void (*t_func)(void *);
29 void *t_arg;
30 unsigned int t_flags;
31#if 1 /* NKCOV > 0 */
32 struct process *t_process;
33#endif
34};
35
36#define TASK_ONQUEUE 1
37
38TAILQ_HEAD(task_list, task);
39
40#define TASKQ_MPSAFE (1 << 0)
41
42#define TASK_INITIALIZER(_f, _a) {{ NULL, NULL }, (_f), (_a), 0 }
43
44#ifdef _KERNEL
45extern struct taskq *const systq;
46extern struct taskq *const systqmp;
47
48struct taskq *taskq_create(const char *, unsigned int, int, unsigned int);
49void taskq_destroy(struct taskq *);
50void taskq_barrier(struct taskq *);
51
52void taskq_del_barrier(struct taskq *, struct task *);
53
54void task_set(struct task *, void (*)(void *), void *);
55int task_add(struct taskq *, struct task *);
56int task_del(struct taskq *, struct task *);
57
58#define task_pending(_t) ((_t)->t_flags & TASK_ONQUEUE)
59
60#endif /* _KERNEL */
61
62#endif /* _SYS_TASK_H_ */