xref: /titanic_50/usr/src/uts/common/sys/waitq.h (revision 8a3c961b6b8e22607c570d092514b791eb1519e9)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #ifdef	__cplusplus
32 extern "C" {
33 #endif
34 
35 #ifdef	_KERNEL
36 
37 #include <sys/types.h>
38 #include <sys/machlock.h>
39 #include <sys/thread.h>
40 
41 typedef struct waitq {
42 	disp_lock_t	wq_lock;	/* protects all fields */
43 	kthread_t	*wq_first;	/* first thread on the queue */
44 	int		wq_count;	/* number of threads on the queue */
45 	boolean_t	wq_blocked;	/* True if threads can't be enqueued */
46 } waitq_t;
47 
48 extern void		waitq_init(waitq_t *);
49 extern void		waitq_fini(waitq_t *);
50 
51 /*
52  * Place the thread on the wait queue. An attempt to enqueue a thread onto a
53  * blocked queue fails and returns zero. Successful enqueue returns non-zero
54  * value.
55  */
56 extern int		waitq_enqueue(waitq_t *, kthread_t *);
57 
58 /*
59  * Take thread off its wait queue and make it runnable.
60  */
61 extern void		waitq_setrun(kthread_t *t);
62 
63 /*
64  * Change priority for the thread on wait queue.
65  */
66 extern void		waitq_change_pri(kthread_t *, pri_t);
67 
68 /*
69  * Take the first thread off the wait queue and make it runnable.
70  */
71 extern void		waitq_runone(waitq_t *);
72 
73 /*
74  * Return True if there are no threads on the queue.
75  */
76 extern boolean_t	waitq_isempty(waitq_t *);
77 
78 /*
79  * Prevent and allow placing new threads on wait queue.
80  */
81 extern void		waitq_block(waitq_t *);
82 extern void		waitq_unblock(waitq_t *);
83 
84 #endif	/* _KERNEL */
85 
86 #ifdef	__cplusplus
87 }
88 #endif
89 
90 #endif	/* _SYS_WAITQ_H */
91