xref: /illumos-gate/usr/src/uts/common/sys/turnstile.h (revision 2d6eb4a5)
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 #include <sys/types.h>
31 #include <sys/time.h>
32 #include <sys/param.h>
33 #include <sys/sleepq.h>
34 #include <sys/mutex.h>
35 #include <sys/lwp_timer_impl.h>
36 
37 #ifdef	__cplusplus
38 extern "C" {
39 #endif
40 
41 #define	TS_WRITER_Q	0	/* writer sleepq (exclusive access to sobj) */
42 #define	TS_READER_Q	1	/* reader sleepq (shared access to sobj) */
43 #define	TS_NUM_Q	2	/* number of sleep queues per turnstile */
44 
45 typedef struct turnstile turnstile_t;
46 struct _sobj_ops;
47 
48 struct turnstile {
49 	turnstile_t	*ts_next;	/* next on hash chain */
50 	turnstile_t	*ts_free;	/* next on freelist */
51 	void		*ts_sobj;	/* s-object threads are blocking on */
52 	int		ts_waiters;	/* number of blocked threads */
53 	pri_t		ts_epri;	/* max priority of blocked threads */
54 	struct _kthread	*ts_inheritor;	/* thread inheriting priority */
55 	turnstile_t	*ts_prioinv;	/* next in inheritor's t_prioinv list */
56 	sleepq_t	ts_sleepq[TS_NUM_Q]; /* read/write sleep queues */
57 };
58 
59 #ifdef	_KERNEL
60 
61 extern turnstile_t *turnstile_lookup(void *);
62 extern void turnstile_exit(void *);
63 extern int turnstile_block(turnstile_t *, int, void *, struct _sobj_ops *,
64     kmutex_t *, lwp_timer_t *);
65 extern void turnstile_wakeup(turnstile_t *, int, int, struct _kthread *);
66 extern void turnstile_change_pri(struct _kthread *, pri_t, pri_t *);
67 extern void turnstile_unsleep(struct _kthread *);
68 extern void turnstile_stay_asleep(struct _kthread *);
69 extern void turnstile_pi_recalc(void);
70 
71 #endif	/* _KERNEL */
72 
73 #ifdef	__cplusplus
74 }
75 #endif
76 
77 #endif	/* _SYS_TURNSTILE_H */
78