workqueue.h revision 1.6 1 1.2 riastrad /* $NetBSD: workqueue.h,v 1.6 2018/08/27 07:05:39 riastradh Exp $ */
2 1.1 skrll
3 1.1 skrll /*-
4 1.1 skrll * Copyright (c) 2013 The NetBSD Foundation, Inc.
5 1.1 skrll * All rights reserved.
6 1.1 skrll *
7 1.1 skrll * This code is derived from software contributed to The NetBSD Foundation
8 1.1 skrll * by Taylor R. Campbell.
9 1.1 skrll *
10 1.1 skrll * Redistribution and use in source and binary forms, with or without
11 1.1 skrll * modification, are permitted provided that the following conditions
12 1.1 skrll * are met:
13 1.1 skrll * 1. Redistributions of source code must retain the above copyright
14 1.1 skrll * notice, this list of conditions and the following disclaimer.
15 1.1 skrll * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 skrll * notice, this list of conditions and the following disclaimer in the
17 1.1 skrll * documentation and/or other materials provided with the distribution.
18 1.1 skrll *
19 1.1 skrll * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 skrll * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 skrll * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 skrll * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 skrll * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 skrll * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 skrll * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 skrll * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 skrll * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 skrll * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 skrll * POSSIBILITY OF SUCH DAMAGE.
30 1.1 skrll */
31 1.1 skrll
32 1.1 skrll #ifndef _LINUX_WORKQUEUE_H_
33 1.1 skrll #define _LINUX_WORKQUEUE_H_
34 1.1 skrll
35 1.1 skrll #include <sys/types.h>
36 1.1 skrll #include <sys/callout.h>
37 1.1 skrll #include <sys/queue.h>
38 1.1 skrll #include <sys/workqueue.h>
39 1.1 skrll
40 1.1 skrll #include <linux/kernel.h>
41 1.1 skrll
42 1.1 skrll #define INIT_DELAYED_WORK linux_INIT_DELAYED_WORK
43 1.1 skrll #define INIT_WORK linux_INIT_WORK
44 1.1 skrll #define alloc_ordered_workqueue linux_alloc_ordered_workqueue
45 1.1 skrll #define cancel_delayed_work linux_cancel_delayed_work
46 1.1 skrll #define cancel_delayed_work_sync linux_cancel_delayed_work_sync
47 1.1 skrll #define cancel_work linux_cancel_work
48 1.1 skrll #define cancel_work_sync linux_cancel_work_sync
49 1.4 riastrad #define current_work linux_current_work
50 1.1 skrll #define destroy_workqueue linux_destroy_workqueue
51 1.6 riastrad #define flush_delayed_work linux_flush_delayed_work
52 1.1 skrll #define flush_work linux_flush_work
53 1.1 skrll #define flush_workqueue linux_flush_workqueue
54 1.1 skrll #define queue_delayed_work linux_queue_delayed_work
55 1.1 skrll #define mod_delayed_work linux_mod_delayed_work
56 1.1 skrll #define queue_work linux_queue_work
57 1.1 skrll #define schedule_delayed_work linux_schedule_delayed_work
58 1.1 skrll #define schedule_work linux_schedule_work
59 1.1 skrll #define system_wq linux_system_wq
60 1.1 skrll #define to_delayed_work linux_to_delayed_work
61 1.1 skrll
62 1.1 skrll struct workqueue_struct;
63 1.1 skrll
64 1.1 skrll struct work_struct {
65 1.1 skrll struct work w_wk;
66 1.1 skrll __cpu_simple_lock_t w_lock; /* XXX */
67 1.1 skrll enum {
68 1.1 skrll WORK_IDLE,
69 1.1 skrll WORK_DELAYED,
70 1.1 skrll WORK_PENDING,
71 1.1 skrll WORK_INVOKED,
72 1.1 skrll WORK_CANCELLED,
73 1.1 skrll WORK_DELAYED_CANCELLED,
74 1.1 skrll } w_state;
75 1.1 skrll struct workqueue_struct *w_wq;
76 1.5 riastrad void (*func)(struct work_struct *);
77 1.1 skrll };
78 1.1 skrll
79 1.1 skrll struct delayed_work {
80 1.1 skrll /* Not dw_work; name must match Linux. */
81 1.1 skrll struct work_struct work;
82 1.1 skrll struct callout dw_callout;
83 1.1 skrll TAILQ_ENTRY(delayed_work) dw_entry;
84 1.1 skrll };
85 1.1 skrll
86 1.1 skrll static inline struct delayed_work *
87 1.1 skrll to_delayed_work(struct work_struct *work)
88 1.1 skrll {
89 1.1 skrll return container_of(work, struct delayed_work, work);
90 1.1 skrll }
91 1.1 skrll
92 1.1 skrll extern struct workqueue_struct *system_wq;
93 1.3 riastrad extern struct workqueue_struct *system_long_wq;
94 1.1 skrll
95 1.1 skrll int linux_workqueue_init(void);
96 1.1 skrll void linux_workqueue_fini(void);
97 1.1 skrll
98 1.1 skrll #define create_singlethread_workqueue(name) \
99 1.1 skrll alloc_ordered_workqueue((name), 0)
100 1.1 skrll
101 1.1 skrll struct workqueue_struct *
102 1.1 skrll alloc_ordered_workqueue(const char *, int);
103 1.1 skrll void destroy_workqueue(struct workqueue_struct *);
104 1.1 skrll void flush_workqueue(struct workqueue_struct *);
105 1.1 skrll void flush_scheduled_work(void);
106 1.1 skrll
107 1.1 skrll void INIT_WORK(struct work_struct *, void (*)(struct work_struct *));
108 1.1 skrll bool schedule_work(struct work_struct *);
109 1.1 skrll bool queue_work(struct workqueue_struct *, struct work_struct *);
110 1.1 skrll bool cancel_work_sync(struct work_struct *);
111 1.1 skrll void flush_work(struct work_struct *);
112 1.1 skrll
113 1.1 skrll void INIT_DELAYED_WORK(struct delayed_work *,
114 1.1 skrll void (*)(struct work_struct *));
115 1.1 skrll bool schedule_delayed_work(struct delayed_work *, unsigned long);
116 1.1 skrll bool queue_delayed_work(struct workqueue_struct *, struct delayed_work *,
117 1.1 skrll unsigned long ticks);
118 1.1 skrll bool mod_delayed_work(struct workqueue_struct *, struct delayed_work *,
119 1.1 skrll unsigned long ticks);
120 1.1 skrll bool cancel_delayed_work(struct delayed_work *);
121 1.1 skrll bool cancel_delayed_work_sync(struct delayed_work *);
122 1.6 riastrad void flush_delayed_work(struct delayed_work *);
123 1.1 skrll
124 1.4 riastrad struct work_struct *
125 1.4 riastrad current_work(void);
126 1.4 riastrad
127 1.2 riastrad #define INIT_WORK_ONSTACK INIT_WORK
128 1.2 riastrad
129 1.2 riastrad static inline void
130 1.2 riastrad destroy_work_on_stack(struct work_struct *work)
131 1.2 riastrad {
132 1.2 riastrad }
133 1.2 riastrad
134 1.1 skrll #endif /* _LINUX_WORKQUEUE_H_ */
135