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_SYNCH_H 28 #define _SYS_SYNCH_H 29 30 #pragma ident "%Z%%M% %I% %E% SMI" 31 32 #ifndef _ASM 33 #include <sys/types.h> 34 #include <sys/int_types.h> 35 #endif /* _ASM */ 36 37 #ifdef __cplusplus 38 extern "C" { 39 #endif 40 41 #ifndef _ASM 42 /* 43 * Thread and LWP mutexes have the same type 44 * definitions. 45 * 46 * NOTE: 47 * 48 * POSIX requires that <pthread.h> define the structures pthread_mutex_t 49 * and pthread_cond_t. Although these structures are identical to mutex_t 50 * (lwp_mutex_t) and cond_t (lwp_cond_t), defined here, a typedef of these 51 * types would require including <synch.h> in <pthread.h>, pulling in 52 * non-posix symbols/constants, violating POSIX namespace restrictions. Hence, 53 * pthread_mutex_t/pthread_cond_t have been redefined (in <sys/types.h>). 54 * Any modifications done to mutex_t/lwp_mutex_t or cond_t/lwp_cond_t must 55 * also be done to pthread_mutex_t/pthread_cond_t. 56 */ 57 typedef struct _lwp_mutex { 58 struct { 59 uint16_t flag1; 60 uint8_t flag2; 61 uint8_t ceiling; 62 union { 63 uint16_t bcptype; 64 struct { 65 uint8_t count_type1; 66 uint8_t count_type2; 67 } mtype_rcount; 68 } mbcp_type_un; 69 uint16_t magic; 70 } flags; 71 union { 72 struct { 73 uint8_t pad[8]; 74 } lock64; 75 struct { 76 uint32_t ownerpid; 77 uint32_t lockword; 78 } lock32; 79 upad64_t owner64; 80 } lock; 81 upad64_t data; 82 } lwp_mutex_t; 83 84 /* 85 * Thread and LWP condition variables have the same 86 * type definition. 87 * NOTE: 88 * The layout of the following structure should be kept in sync with the 89 * layout of pthread_cond_t in sys/types.h. See NOTE above for lwp_mutex_t. 90 */ 91 typedef struct _lwp_cond { 92 struct { 93 uint8_t flag[4]; 94 uint16_t type; 95 uint16_t magic; 96 } flags; 97 upad64_t data; 98 } lwp_cond_t; 99 100 /* 101 * LWP semaphores 102 */ 103 typedef struct _lwp_sema { 104 uint32_t count; /* semaphore count */ 105 uint16_t type; 106 uint16_t magic; 107 uint8_t flags[8]; /* last byte reserved for waiters */ 108 upad64_t data; /* optional data */ 109 } lwp_sema_t; 110 111 /* 112 * Thread and LWP rwlocks have the same type definition. 113 * NOTE: The layout of this structure should be kept in sync with the layout 114 * of the correponding structure of pthread_rwlock_t in sys/types.h. 115 * Also, because we have to deal with C++, there is an identical structure 116 * for rwlock_t in head/sync.h that we cannot change. 117 */ 118 typedef struct _lwp_rwlock { 119 int32_t readers; /* -1 == writer else # of readers */ 120 uint16_t type; 121 uint16_t magic; 122 lwp_mutex_t mutex; /* used to indicate ownership */ 123 lwp_cond_t readercv; /* unused */ 124 lwp_cond_t writercv; /* unused */ 125 } lwp_rwlock_t; 126 127 #endif /* _ASM */ 128 /* 129 * Definitions of synchronization types. 130 */ 131 #define USYNC_THREAD 0x00 /* private to a process */ 132 #define USYNC_PROCESS 0x01 /* shared by processes */ 133 134 /* Keep the following 3 fields in sync with pthread.h */ 135 #define LOCK_NORMAL 0x00 /* same as USYNC_THREAD */ 136 #define LOCK_ERRORCHECK 0x02 /* error check lock */ 137 #define LOCK_RECURSIVE 0x04 /* recursive lock */ 138 139 #define USYNC_PROCESS_ROBUST 0x08 /* shared by processes robustly */ 140 141 /* Keep the following 5 fields in sync with pthread.h */ 142 143 #define LOCK_PRIO_NONE 0x00 144 #define LOCK_PRIO_INHERIT 0x10 145 #define LOCK_PRIO_PROTECT 0x20 146 #define LOCK_STALL_NP 0x00 147 #define LOCK_ROBUST_NP 0x40 148 149 /* 150 * lwp_mutex_t flags 151 */ 152 #define LOCK_OWNERDEAD 0x1 153 #define LOCK_NOTRECOVERABLE 0x2 154 #define LOCK_INITED 0x4 155 #define LOCK_UNMAPPED 0x8 156 157 #ifdef __cplusplus 158 } 159 #endif 160 161 #endif /* _SYS_SYNCH_H */ 162