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