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