xref: /illumos-gate/usr/src/uts/common/sys/waitq.h (revision 9164a50bf932130cbb5097a16f6986873ce0e6e5)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _SYS_WAITQ_H
27 #define	_SYS_WAITQ_H
28 
29 #ifdef	__cplusplus
30 extern "C" {
31 #endif
32 
33 #ifdef	_KERNEL
34 
35 #include <sys/types.h>
36 #include <sys/machlock.h>
37 #include <sys/thread.h>
38 
39 typedef struct waitq {
40 	disp_lock_t	wq_lock;	/* protects all fields */
41 	kthread_t	*wq_first;	/* first thread on the queue */
42 	int		wq_count;	/* number of threads on the queue */
43 	boolean_t	wq_blocked;	/* True if threads can't be enqueued */
44 } waitq_t;
45 
46 extern void		waitq_init(waitq_t *);
47 extern void		waitq_fini(waitq_t *);
48 
49 /*
50  * Place the thread on the wait queue. An attempt to enqueue a thread onto a
51  * blocked queue fails and returns zero. Successful enqueue returns non-zero
52  * value.
53  */
54 extern int		waitq_enqueue(waitq_t *, kthread_t *);
55 
56 /*
57  * Take thread off its wait queue and make it runnable.
58  */
59 extern void		waitq_setrun(kthread_t *t);
60 
61 /*
62  * Change priority for the thread on wait queue.
63  */
64 extern void		waitq_change_pri(kthread_t *, pri_t);
65 
66 /*
67  * Take the first thread off the wait queue and make it runnable.
68  */
69 extern void		waitq_runone(waitq_t *);
70 
71 /*
72  * Return True if there are no threads on the queue.
73  */
74 extern boolean_t	waitq_isempty(waitq_t *);
75 
76 /*
77  * Prevent and allow placing new threads on wait queue.
78  */
79 extern void		waitq_block(waitq_t *);
80 extern void		waitq_unblock(waitq_t *);
81 
82 #endif	/* _KERNEL */
83 
84 #ifdef	__cplusplus
85 }
86 #endif
87 
88 #endif	/* _SYS_WAITQ_H */
89