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