xref: /illumos-gate/usr/src/uts/common/sys/sleepq.h (revision 2bcbf80ce6c8a2fb827428428c350ebe4f91f7ab)
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 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _SYS_SLEEPQ_H
27 #define	_SYS_SLEEPQ_H
28 
29 #include <sys/machlock.h>
30 
31 #ifdef	__cplusplus
32 extern "C" {
33 #endif
34 
35 /*
36  * Common definition for a sleep queue,
37  * be it an old-style sleep queue, or
38  * a constituent of a turnstile.
39  */
40 
41 typedef struct sleepq {
42 	struct _kthread *sq_first;
43 } sleepq_t;
44 
45 /*
46  * Definition of the head of a sleep queue hash bucket.
47  */
48 typedef struct _sleepq_head {
49 	sleepq_t	sq_queue;
50 	disp_lock_t	sq_lock;
51 } sleepq_head_t;
52 
53 #ifdef	_KERNEL
54 
55 #define	NSLEEPQ		2048
56 #define	SQHASHINDEX(X)	\
57 	((((uintptr_t)(X) >> 2) ^ ((uintptr_t)(X) >> 13) ^	\
58 	((uintptr_t)(X) >> 24)) & (NSLEEPQ - 1))
59 #define	SQHASH(X)	(&sleepq_head[SQHASHINDEX(X)])
60 
61 extern sleepq_head_t	sleepq_head[NSLEEPQ];
62 
63 extern void		sleepq_insert(sleepq_t *, struct _kthread *);
64 extern struct _kthread	*sleepq_wakeone_chan(sleepq_t *, void *);
65 extern void		sleepq_wakeall_chan(sleepq_t *, void *);
66 extern void		sleepq_unsleep(struct _kthread *);
67 extern void		sleepq_dequeue(struct _kthread *);
68 extern void		sleepq_unlink(struct _kthread **, struct _kthread *);
69 
70 #endif	/* _KERNEL */
71 
72 #ifdef	__cplusplus
73 }
74 #endif
75 
76 #endif	/* _SYS_SLEEPQ_H */
77