xref: /illumos-gate/usr/src/uts/common/sys/lwp_upimutex_impl.h (revision 4de2612967d06c4fdbf524a62556a1e8118a006f)
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 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _SYS_LWP_UPIMUTEX_IMPL_H
28 #define	_SYS_LWP_UPIMUTEX_IMPL_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/thread.h>
33 #include <sys/lwp.h>
34 
35 #ifdef	__cplusplus
36 extern "C" {
37 #endif
38 
39 typedef struct upimutex upimutex_t;
40 typedef struct upib upib_t;
41 
42 struct upib {
43 	kmutex_t upib_lock;
44 	upimutex_t *upib_first;
45 };
46 
47 struct upimutex {
48 	struct _kthread *upi_owner;  /* owner */
49 	int	upi_waiter; /* wait bit */
50 	upib_t *upi_upibp; /* point back to upib bucket in hash chain */
51 	lwp_mutex_t *upi_vaddr;   /* virtual address, i.e. user lock ptr */
52 	lwpchan_t  upi_lwpchan;  /* lwpchan of virtual address */
53 	upimutex_t *upi_nextchain; /* next in hash chain */
54 	upimutex_t *upi_nextowned; /* list of mutexes owned by lwp */
55 };
56 
57 #define	UPILWPCHAN_BITS		9
58 #define	UPILWPCHAN_TABSIZ	(1 << UPILWPCHAN_BITS)
59 #define	UPIMUTEX_TABSIZE	UPILWPCHAN_TABSIZ
60 #define	UPILWPCHAN_HASH(lwpchan)	\
61 	(((uintptr_t)((lwpchan).lc_wchan0)^(uintptr_t)((lwpchan).lc_wchan)) ^ \
62 	(((uintptr_t)((lwpchan).lc_wchan0)^(uintptr_t)((lwpchan).lc_wchan)) >> \
63 	UPILWPCHAN_BITS)) & (UPIMUTEX_TABSIZE - 1)
64 #define	UPI_CHAIN(lwpchan)	upimutextab[UPILWPCHAN_HASH((lwpchan))]
65 
66 #define	UPIMUTEX_TRY	1
67 #define	UPIMUTEX_BLOCK	0
68 
69 #ifdef _KERNEL
70 extern void upimutex_cleanup();
71 #endif	/* _KERNEL */
72 
73 #ifdef	__cplusplus
74 }
75 #endif
76 
77 #endif	/* _SYS_LWP_UPIMUTEX_IMPL_H */
78