xref: /onnv-gate/usr/src/uts/common/sys/sleepq.h (revision 8619:6381efc2ef79)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*8619SEthindra.Ramamurthy@Sun.COM  * Common Development and Distribution License (the "License").
6*8619SEthindra.Ramamurthy@Sun.COM  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*8619SEthindra.Ramamurthy@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #ifndef _SYS_SLEEPQ_H
270Sstevel@tonic-gate #define	_SYS_SLEEPQ_H
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #include <sys/machlock.h>
300Sstevel@tonic-gate 
310Sstevel@tonic-gate #ifdef	__cplusplus
320Sstevel@tonic-gate extern "C" {
330Sstevel@tonic-gate #endif
340Sstevel@tonic-gate 
350Sstevel@tonic-gate /*
360Sstevel@tonic-gate  * Common definition for a sleep queue,
370Sstevel@tonic-gate  * be it an old-style sleep queue, or
380Sstevel@tonic-gate  * a constituent of a turnstile.
390Sstevel@tonic-gate  */
400Sstevel@tonic-gate 
410Sstevel@tonic-gate typedef struct sleepq {
420Sstevel@tonic-gate 	struct _kthread *sq_first;
430Sstevel@tonic-gate } sleepq_t;
440Sstevel@tonic-gate 
450Sstevel@tonic-gate /*
460Sstevel@tonic-gate  * Definition of the head of a sleep queue hash bucket.
470Sstevel@tonic-gate  */
480Sstevel@tonic-gate typedef struct _sleepq_head {
490Sstevel@tonic-gate 	sleepq_t	sq_queue;
500Sstevel@tonic-gate 	disp_lock_t	sq_lock;
510Sstevel@tonic-gate } sleepq_head_t;
520Sstevel@tonic-gate 
530Sstevel@tonic-gate #ifdef	_KERNEL
540Sstevel@tonic-gate 
55*8619SEthindra.Ramamurthy@Sun.COM #define	NSLEEPQ		2048
560Sstevel@tonic-gate #define	SQHASHINDEX(X)	\
57*8619SEthindra.Ramamurthy@Sun.COM 	((((uintptr_t)(X) >> 2) ^ ((uintptr_t)(X) >> 13) ^	\
58*8619SEthindra.Ramamurthy@Sun.COM 	((uintptr_t)(X) >> 24)) & (NSLEEPQ - 1))
590Sstevel@tonic-gate #define	SQHASH(X)	(&sleepq_head[SQHASHINDEX(X)])
600Sstevel@tonic-gate 
610Sstevel@tonic-gate extern sleepq_head_t	sleepq_head[NSLEEPQ];
620Sstevel@tonic-gate 
630Sstevel@tonic-gate extern void		sleepq_insert(sleepq_t *, struct _kthread *);
640Sstevel@tonic-gate extern struct _kthread	*sleepq_wakeone_chan(sleepq_t *, void *);
650Sstevel@tonic-gate extern void		sleepq_wakeall_chan(sleepq_t *, void *);
660Sstevel@tonic-gate extern void		sleepq_unsleep(struct _kthread *);
670Sstevel@tonic-gate extern void		sleepq_dequeue(struct _kthread *);
680Sstevel@tonic-gate extern void		sleepq_unlink(struct _kthread **, struct _kthread *);
690Sstevel@tonic-gate 
700Sstevel@tonic-gate #endif	/* _KERNEL */
710Sstevel@tonic-gate 
720Sstevel@tonic-gate #ifdef	__cplusplus
730Sstevel@tonic-gate }
740Sstevel@tonic-gate #endif
750Sstevel@tonic-gate 
760Sstevel@tonic-gate #endif	/* _SYS_SLEEPQ_H */
77