xref: /f-stack/tools/compat/include/sys/_task.h (revision 1eaf0ac3)
1*1eaf0ac3Slogwang /*-
2*1eaf0ac3Slogwang  * Copyright (c) 2000 Doug Rabson
3*1eaf0ac3Slogwang  * All rights reserved.
4*1eaf0ac3Slogwang  *
5*1eaf0ac3Slogwang  * Redistribution and use in source and binary forms, with or without
6*1eaf0ac3Slogwang  * modification, are permitted provided that the following conditions
7*1eaf0ac3Slogwang  * are met:
8*1eaf0ac3Slogwang  * 1. Redistributions of source code must retain the above copyright
9*1eaf0ac3Slogwang  *    notice, this list of conditions and the following disclaimer.
10*1eaf0ac3Slogwang  * 2. Redistributions in binary form must reproduce the above copyright
11*1eaf0ac3Slogwang  *    notice, this list of conditions and the following disclaimer in the
12*1eaf0ac3Slogwang  *    documentation and/or other materials provided with the distribution.
13*1eaf0ac3Slogwang  *
14*1eaf0ac3Slogwang  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15*1eaf0ac3Slogwang  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16*1eaf0ac3Slogwang  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17*1eaf0ac3Slogwang  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18*1eaf0ac3Slogwang  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19*1eaf0ac3Slogwang  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20*1eaf0ac3Slogwang  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21*1eaf0ac3Slogwang  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22*1eaf0ac3Slogwang  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23*1eaf0ac3Slogwang  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24*1eaf0ac3Slogwang  * SUCH DAMAGE.
25*1eaf0ac3Slogwang  *
26*1eaf0ac3Slogwang  * $FreeBSD$
27*1eaf0ac3Slogwang  */
28*1eaf0ac3Slogwang 
29*1eaf0ac3Slogwang #ifndef _SYS__TASK_H_
30*1eaf0ac3Slogwang #define _SYS__TASK_H_
31*1eaf0ac3Slogwang 
32*1eaf0ac3Slogwang #include <sys/queue.h>
33*1eaf0ac3Slogwang 
34*1eaf0ac3Slogwang /*
35*1eaf0ac3Slogwang  * Each task includes a function which is called from
36*1eaf0ac3Slogwang  * taskqueue_run().  The first argument is taken from the 'ta_context'
37*1eaf0ac3Slogwang  * field of struct task and the second argument is a count of how many
38*1eaf0ac3Slogwang  * times the task was enqueued before the call to taskqueue_run().
39*1eaf0ac3Slogwang  *
40*1eaf0ac3Slogwang  * List of locks
41*1eaf0ac3Slogwang  * (c)	const after init
42*1eaf0ac3Slogwang  * (q)	taskqueue lock
43*1eaf0ac3Slogwang  */
44*1eaf0ac3Slogwang typedef void task_fn_t(void *context, int pending);
45*1eaf0ac3Slogwang typedef void gtask_fn_t(void *context);
46*1eaf0ac3Slogwang 
47*1eaf0ac3Slogwang struct task {
48*1eaf0ac3Slogwang 	STAILQ_ENTRY(task) ta_link;	/* (q) link for queue */
49*1eaf0ac3Slogwang 	uint16_t ta_pending;		/* (q) count times queued */
50*1eaf0ac3Slogwang 	u_short	ta_priority;		/* (c) Priority */
51*1eaf0ac3Slogwang 	task_fn_t *ta_func;		/* (c) task handler */
52*1eaf0ac3Slogwang 	void	*ta_context;		/* (c) argument for handler */
53*1eaf0ac3Slogwang };
54*1eaf0ac3Slogwang 
55*1eaf0ac3Slogwang struct gtask {
56*1eaf0ac3Slogwang 	STAILQ_ENTRY(gtask) ta_link;	/* (q) link for queue */
57*1eaf0ac3Slogwang 	uint16_t ta_flags;		/* (q) state flags */
58*1eaf0ac3Slogwang 	u_short	ta_priority;		/* (c) Priority */
59*1eaf0ac3Slogwang 	gtask_fn_t *ta_func;		/* (c) task handler */
60*1eaf0ac3Slogwang 	void	*ta_context;		/* (c) argument for handler */
61*1eaf0ac3Slogwang };
62*1eaf0ac3Slogwang 
63*1eaf0ac3Slogwang struct grouptask {
64*1eaf0ac3Slogwang 	struct	gtask		gt_task;
65*1eaf0ac3Slogwang 	void			*gt_taskqueue;
66*1eaf0ac3Slogwang 	LIST_ENTRY(grouptask)	gt_list;
67*1eaf0ac3Slogwang 	void			*gt_uniq;
68*1eaf0ac3Slogwang 	char			*gt_name;
69*1eaf0ac3Slogwang 	int16_t			gt_irq;
70*1eaf0ac3Slogwang 	int16_t			gt_cpu;
71*1eaf0ac3Slogwang };
72*1eaf0ac3Slogwang 
73*1eaf0ac3Slogwang #endif /* !_SYS__TASK_H_ */
74