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
13 struct taskq {
14 struct taskqueue* tq;
15 };
16
17 #define systq (struct taskq*)(0x1)
18
19
20 static void
task_set(struct task * t,void (* fn)(void *),void * arg)21 task_set(struct task *t, void (*fn)(void *), void *arg)
22 {
23 TASK_INIT(t, 0, (task_fn_t*)fn, arg);
24 }
25
26
27 static int
task_pending(struct task * t)28 task_pending(struct task *t)
29 {
30 return t->ta_pending > 0;
31 }
32
33
34 static int
task_add(struct taskq * tasq,struct task * w)35 task_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
46 static struct taskq*
taskq_create(const char * name,unsigned int nthreads,int ipl,unsigned int flags)47 taskq_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
54 static int
task_del(struct taskq * tasq,struct task * w)55 task_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