1/*
2 * Copyright 2022, Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef _OBSD_COMPAT_SYS_TASK_H_
6#define _OBSD_COMPAT_SYS_TASK_H_
7
8
9#include <sys/_task.h>
10#include <sys/taskqueue.h>
11
12
13struct taskq {
14	struct taskqueue* tq;
15};
16
17#define systq (struct taskq*)(0x1)
18
19
20static void
21task_set(struct task *t, void (*fn)(void *), void *arg)
22{
23	TASK_INIT(t, 0, fn, arg);
24}
25
26
27static int
28task_pending(struct task *t)
29{
30	return t->ta_pending > 0;
31}
32
33
34static int
35task_add(struct taskq* tasq, struct task *w)
36{
37	struct taskqueue* tq = (tasq == systq) ? taskqueue_fast : tasq->tq;
38	if (tq == taskqueue_fast)
39		w->ta_flags |= TASK_NEEDSGIANT;
40	if (task_pending(w))
41		return 0;
42	return (taskqueue_enqueue(tq, w) == 0);
43}
44
45
46static struct taskq*
47taskq_create(const char* name, unsigned int nthreads, int ipl, unsigned int flags)
48{
49	// For now, just use the system taskqueue.
50	return systq;
51}
52
53
54static int
55task_del(struct taskq* tasq, struct task *w)
56{
57	struct taskqueue* tq = (tasq == systq) ? taskqueue_fast : tasq->tq;
58	if (!task_pending(w))
59		return 0;
60	return (taskqueue_cancel(tq, w, NULL) == 0);
61}
62
63
64#endif	/* _OBSD_COMPAT_SYS_TASK_H_ */
65