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