Home | History | Annotate | Line # | Download | only in linux
workqueue.h revision 1.25
      1  1.25  riastrad /*	$NetBSD: workqueue.h,v 1.25 2021/12/19 11:40:13 riastradh Exp $	*/
      2   1.1     skrll 
      3   1.1     skrll /*-
      4   1.9  riastrad  * Copyright (c) 2013, 2018 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/queue.h>
     36   1.9  riastrad #include <sys/stdbool.h>
     37   1.1     skrll 
     38   1.9  riastrad #include <linux/kernel.h>	/* container_of */
     39  1.22  riastrad #include <linux/stringify.h>
     40   1.1     skrll 
     41   1.1     skrll #define	INIT_DELAYED_WORK		linux_INIT_DELAYED_WORK
     42  1.25  riastrad #define	INIT_RCU_WORK			linux_INIT_RCU_WORK
     43   1.1     skrll #define	INIT_WORK			linux_INIT_WORK
     44  1.25  riastrad #define	alloc_ordered_workqueue		linux_alloc_ordered_workqueue
     45  1.21  riastrad #define	alloc_workqueue			linux_alloc_workqueue
     46   1.1     skrll #define	cancel_delayed_work		linux_cancel_delayed_work
     47   1.1     skrll #define	cancel_delayed_work_sync	linux_cancel_delayed_work_sync
     48   1.1     skrll #define	cancel_work			linux_cancel_work
     49   1.1     skrll #define	cancel_work_sync		linux_cancel_work_sync
     50   1.4  riastrad #define	current_work			linux_current_work
     51  1.17  riastrad #define	delayed_work_pending		linux_delayed_work_pending
     52   1.1     skrll #define	destroy_workqueue		linux_destroy_workqueue
     53  1.18  riastrad #define	drain_workqueue			linux_drain_workqueue
     54   1.6  riastrad #define	flush_delayed_work		linux_flush_delayed_work
     55  1.10  riastrad #define	flush_scheduled_work		linux_flush_scheduled_work
     56   1.1     skrll #define	flush_work			linux_flush_work
     57   1.1     skrll #define	flush_workqueue			linux_flush_workqueue
     58  1.25  riastrad #define	mod_delayed_work		linux_mod_delayed_work
     59   1.1     skrll #define	queue_delayed_work		linux_queue_delayed_work
     60  1.25  riastrad #define	queue_rcu_work			linux_queue_rcu_work
     61   1.1     skrll #define	queue_work			linux_queue_work
     62   1.1     skrll #define	schedule_delayed_work		linux_schedule_delayed_work
     63   1.1     skrll #define	schedule_work			linux_schedule_work
     64  1.24  riastrad #define	system_highpri_wq		linux_system_highpri_wq
     65   1.7  riastrad #define	system_long_wq			linux_system_long_wq
     66   1.8  riastrad #define	system_power_efficient_wq	linux_system_power_efficient_wq
     67  1.15  riastrad #define	system_unbound_wq		linux_system_unbound_wq
     68   1.1     skrll #define	system_wq			linux_system_wq
     69   1.1     skrll #define	to_delayed_work			linux_to_delayed_work
     70  1.17  riastrad #define	work_pending			linux_work_pending
     71   1.1     skrll 
     72   1.1     skrll struct workqueue_struct;
     73   1.1     skrll 
     74   1.1     skrll struct work_struct {
     75  1.13  riastrad 	volatile uintptr_t		work_owner;
     76   1.9  riastrad 	TAILQ_ENTRY(work_struct)	work_entry;
     77   1.9  riastrad 	void	(*func)(struct work_struct *); /* Linux API name */
     78   1.1     skrll };
     79   1.1     skrll 
     80   1.1     skrll struct delayed_work {
     81   1.9  riastrad 	struct work_struct		work; /* Linux API name */
     82   1.1     skrll 	struct callout			dw_callout;
     83   1.1     skrll 	TAILQ_ENTRY(delayed_work)	dw_entry;
     84  1.12  riastrad 	int				dw_resched;
     85   1.9  riastrad 	enum {
     86   1.9  riastrad 		DELAYED_WORK_IDLE,
     87   1.9  riastrad 		DELAYED_WORK_SCHEDULED,
     88   1.9  riastrad 		DELAYED_WORK_RESCHEDULED,
     89   1.9  riastrad 		DELAYED_WORK_CANCELLED,
     90   1.9  riastrad 	}				dw_state;
     91   1.1     skrll };
     92   1.1     skrll 
     93  1.23  riastrad struct rcu_work {
     94  1.25  riastrad 	struct work_struct		work; /* Linux API name */
     95  1.25  riastrad 	struct rcu_head			rw_rcu;
     96  1.23  riastrad };
     97  1.23  riastrad 
     98  1.21  riastrad #define	WQ_FREEZABLE		__BIT(0)
     99  1.21  riastrad #define	WQ_HIGHPRI		__BIT(1)
    100  1.21  riastrad #define	WQ_MEM_RECLAIM		__BIT(2)
    101  1.21  riastrad #define	WQ_UNBOUND		__BIT(3)
    102  1.21  riastrad 
    103  1.24  riastrad #define	WQ_UNBOUND_MAX_ACTIVE	0
    104  1.24  riastrad 
    105   1.1     skrll static inline struct delayed_work *
    106   1.1     skrll to_delayed_work(struct work_struct *work)
    107   1.1     skrll {
    108   1.1     skrll 	return container_of(work, struct delayed_work, work);
    109   1.1     skrll }
    110   1.1     skrll 
    111  1.24  riastrad extern struct workqueue_struct	*system_highpri_wq;
    112   1.3  riastrad extern struct workqueue_struct	*system_long_wq;
    113   1.8  riastrad extern struct workqueue_struct	*system_power_efficient_wq;
    114  1.14  riastrad extern struct workqueue_struct	*system_unbound_wq;
    115  1.24  riastrad extern struct workqueue_struct	*system_wq;
    116   1.1     skrll 
    117   1.1     skrll int	linux_workqueue_init(void);
    118   1.1     skrll void	linux_workqueue_fini(void);
    119   1.1     skrll 
    120   1.1     skrll #define	create_singlethread_workqueue(name)				      \
    121   1.1     skrll 	alloc_ordered_workqueue((name), 0)
    122   1.1     skrll 
    123   1.1     skrll struct workqueue_struct *
    124  1.21  riastrad 	alloc_workqueue(const char *, int, unsigned);
    125  1.21  riastrad struct workqueue_struct *
    126   1.1     skrll 	alloc_ordered_workqueue(const char *, int);
    127   1.1     skrll void	destroy_workqueue(struct workqueue_struct *);
    128   1.1     skrll void	flush_workqueue(struct workqueue_struct *);
    129  1.18  riastrad void	drain_workqueue(struct workqueue_struct *);
    130   1.1     skrll void	flush_scheduled_work(void);
    131   1.1     skrll 
    132   1.1     skrll void	INIT_WORK(struct work_struct *, void (*)(struct work_struct *));
    133   1.1     skrll bool	schedule_work(struct work_struct *);
    134   1.1     skrll bool	queue_work(struct workqueue_struct *, struct work_struct *);
    135   1.9  riastrad bool	cancel_work(struct work_struct *);
    136   1.1     skrll bool	cancel_work_sync(struct work_struct *);
    137  1.16  riastrad bool	flush_work(struct work_struct *);
    138  1.19  riastrad bool	work_pending(const struct work_struct *);
    139   1.1     skrll 
    140   1.1     skrll void	INIT_DELAYED_WORK(struct delayed_work *,
    141   1.1     skrll 	    void (*)(struct work_struct *));
    142   1.1     skrll bool	schedule_delayed_work(struct delayed_work *, unsigned long);
    143   1.1     skrll bool	queue_delayed_work(struct workqueue_struct *, struct delayed_work *,
    144   1.1     skrll 	    unsigned long ticks);
    145   1.1     skrll bool	mod_delayed_work(struct workqueue_struct *, struct delayed_work *,
    146   1.1     skrll 	    unsigned long ticks);
    147   1.1     skrll bool	cancel_delayed_work(struct delayed_work *);
    148   1.1     skrll bool	cancel_delayed_work_sync(struct delayed_work *);
    149  1.16  riastrad bool	flush_delayed_work(struct delayed_work *);
    150  1.19  riastrad bool	delayed_work_pending(const struct delayed_work *);
    151   1.1     skrll 
    152  1.25  riastrad void	INIT_RCU_WORK(struct rcu_work *, void (*fn)(struct work_struct *));
    153  1.25  riastrad void	queue_rcu_work(struct workqueue_struct *, struct rcu_work *);
    154  1.25  riastrad 
    155   1.4  riastrad struct work_struct *
    156   1.4  riastrad 	current_work(void);
    157   1.4  riastrad 
    158   1.2  riastrad #define	INIT_WORK_ONSTACK		INIT_WORK
    159  1.20  riastrad #define	INIT_DELAYED_WORK_ONSTACK	INIT_DELAYED_WORK
    160  1.20  riastrad #define	destroy_delayed_work_on_stack(dw)	__nothing
    161   1.2  riastrad 
    162   1.2  riastrad static inline void
    163   1.2  riastrad destroy_work_on_stack(struct work_struct *work)
    164   1.2  riastrad {
    165   1.2  riastrad }
    166   1.2  riastrad 
    167   1.1     skrll #endif  /* _LINUX_WORKQUEUE_H_ */
    168