xref: /titanic_44/usr/src/uts/common/sys/turnstile.h (revision fb3fb4f3d76d55b64440afd0af72775dfad3bd1d)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _SYS_TURNSTILE_H
28 #define	_SYS_TURNSTILE_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/types.h>
33 #include <sys/time.h>
34 #include <sys/param.h>
35 #include <sys/sleepq.h>
36 #include <sys/mutex.h>
37 #include <sys/lwp_timer_impl.h>
38 
39 #ifdef	__cplusplus
40 extern "C" {
41 #endif
42 
43 #define	TS_WRITER_Q	0	/* writer sleepq (exclusive access to sobj) */
44 #define	TS_READER_Q	1	/* reader sleepq (shared access to sobj) */
45 #define	TS_NUM_Q	2	/* number of sleep queues per turnstile */
46 
47 typedef struct turnstile turnstile_t;
48 struct _sobj_ops;
49 
50 struct turnstile {
51 	turnstile_t	*ts_next;	/* next on hash chain */
52 	turnstile_t	*ts_free;	/* next on freelist */
53 	void		*ts_sobj;	/* s-object threads are blocking on */
54 	int		ts_waiters;	/* number of blocked threads */
55 	pri_t		ts_epri;	/* max priority of blocked threads */
56 	struct _kthread	*ts_inheritor;	/* thread inheriting priority */
57 	turnstile_t	*ts_prioinv;	/* next in inheritor's t_prioinv list */
58 	sleepq_t	ts_sleepq[TS_NUM_Q]; /* read/write sleep queues */
59 };
60 
61 #ifdef	_KERNEL
62 
63 extern turnstile_t *turnstile_lookup(void *);
64 extern void turnstile_exit(void *);
65 extern int turnstile_block(turnstile_t *, int, void *, struct _sobj_ops *,
66     kmutex_t *, lwp_timer_t *);
67 extern void turnstile_wakeup(turnstile_t *, int, int, struct _kthread *);
68 extern void turnstile_change_pri(struct _kthread *, pri_t, pri_t *);
69 extern void turnstile_unsleep(struct _kthread *);
70 extern void turnstile_stay_asleep(struct _kthread *);
71 extern void turnstile_pi_recalc(void);
72 
73 #endif	/* _KERNEL */
74 
75 #ifdef	__cplusplus
76 }
77 #endif
78 
79 #endif	/* _SYS_TURNSTILE_H */
80