10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 54570Sraf * Common Development and Distribution License (the "License"). 64570Sraf * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 214570Sraf 220Sstevel@tonic-gate /* 234570Sraf * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #ifndef _SYS_SYNCH_H 280Sstevel@tonic-gate #define _SYS_SYNCH_H 290Sstevel@tonic-gate 300Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 310Sstevel@tonic-gate 320Sstevel@tonic-gate #ifndef _ASM 330Sstevel@tonic-gate #include <sys/types.h> 340Sstevel@tonic-gate #include <sys/int_types.h> 350Sstevel@tonic-gate #endif /* _ASM */ 360Sstevel@tonic-gate 370Sstevel@tonic-gate #ifdef __cplusplus 380Sstevel@tonic-gate extern "C" { 390Sstevel@tonic-gate #endif 400Sstevel@tonic-gate 410Sstevel@tonic-gate #ifndef _ASM 420Sstevel@tonic-gate /* 430Sstevel@tonic-gate * Thread and LWP mutexes have the same type 440Sstevel@tonic-gate * definitions. 450Sstevel@tonic-gate * 460Sstevel@tonic-gate * NOTE: 470Sstevel@tonic-gate * 480Sstevel@tonic-gate * POSIX requires that <pthread.h> define the structures pthread_mutex_t 490Sstevel@tonic-gate * and pthread_cond_t. Although these structures are identical to mutex_t 500Sstevel@tonic-gate * (lwp_mutex_t) and cond_t (lwp_cond_t), defined here, a typedef of these 510Sstevel@tonic-gate * types would require including <synch.h> in <pthread.h>, pulling in 520Sstevel@tonic-gate * non-posix symbols/constants, violating POSIX namespace restrictions. Hence, 530Sstevel@tonic-gate * pthread_mutex_t/pthread_cond_t have been redefined (in <sys/types.h>). 540Sstevel@tonic-gate * Any modifications done to mutex_t/lwp_mutex_t or cond_t/lwp_cond_t must 550Sstevel@tonic-gate * also be done to pthread_mutex_t/pthread_cond_t. 560Sstevel@tonic-gate */ 570Sstevel@tonic-gate typedef struct _lwp_mutex { 580Sstevel@tonic-gate struct { 590Sstevel@tonic-gate uint16_t flag1; 600Sstevel@tonic-gate uint8_t flag2; 610Sstevel@tonic-gate uint8_t ceiling; 620Sstevel@tonic-gate union { 630Sstevel@tonic-gate uint16_t bcptype; 640Sstevel@tonic-gate struct { 650Sstevel@tonic-gate uint8_t count_type1; 660Sstevel@tonic-gate uint8_t count_type2; 670Sstevel@tonic-gate } mtype_rcount; 680Sstevel@tonic-gate } mbcp_type_un; 690Sstevel@tonic-gate uint16_t magic; 700Sstevel@tonic-gate } flags; 710Sstevel@tonic-gate union { 720Sstevel@tonic-gate struct { 730Sstevel@tonic-gate uint8_t pad[8]; 740Sstevel@tonic-gate } lock64; 750Sstevel@tonic-gate struct { 760Sstevel@tonic-gate uint32_t ownerpid; 770Sstevel@tonic-gate uint32_t lockword; 780Sstevel@tonic-gate } lock32; 790Sstevel@tonic-gate upad64_t owner64; 800Sstevel@tonic-gate } lock; 810Sstevel@tonic-gate upad64_t data; 820Sstevel@tonic-gate } lwp_mutex_t; 830Sstevel@tonic-gate 840Sstevel@tonic-gate /* 850Sstevel@tonic-gate * Thread and LWP condition variables have the same 860Sstevel@tonic-gate * type definition. 870Sstevel@tonic-gate * NOTE: 880Sstevel@tonic-gate * The layout of the following structure should be kept in sync with the 890Sstevel@tonic-gate * layout of pthread_cond_t in sys/types.h. See NOTE above for lwp_mutex_t. 900Sstevel@tonic-gate */ 910Sstevel@tonic-gate typedef struct _lwp_cond { 920Sstevel@tonic-gate struct { 930Sstevel@tonic-gate uint8_t flag[4]; 940Sstevel@tonic-gate uint16_t type; 950Sstevel@tonic-gate uint16_t magic; 960Sstevel@tonic-gate } flags; 970Sstevel@tonic-gate upad64_t data; 980Sstevel@tonic-gate } lwp_cond_t; 990Sstevel@tonic-gate 1000Sstevel@tonic-gate /* 1010Sstevel@tonic-gate * LWP semaphores 1020Sstevel@tonic-gate */ 1030Sstevel@tonic-gate typedef struct _lwp_sema { 1040Sstevel@tonic-gate uint32_t count; /* semaphore count */ 1050Sstevel@tonic-gate uint16_t type; 1060Sstevel@tonic-gate uint16_t magic; 1070Sstevel@tonic-gate uint8_t flags[8]; /* last byte reserved for waiters */ 1080Sstevel@tonic-gate upad64_t data; /* optional data */ 1090Sstevel@tonic-gate } lwp_sema_t; 1100Sstevel@tonic-gate 1110Sstevel@tonic-gate /* 1120Sstevel@tonic-gate * Thread and LWP rwlocks have the same type definition. 1130Sstevel@tonic-gate * NOTE: The layout of this structure should be kept in sync with the layout 1140Sstevel@tonic-gate * of the correponding structure of pthread_rwlock_t in sys/types.h. 1150Sstevel@tonic-gate * Also, because we have to deal with C++, there is an identical structure 1160Sstevel@tonic-gate * for rwlock_t in head/sync.h that we cannot change. 1170Sstevel@tonic-gate */ 1180Sstevel@tonic-gate typedef struct _lwp_rwlock { 1194570Sraf int32_t readers; /* rwstate word */ 1200Sstevel@tonic-gate uint16_t type; 1210Sstevel@tonic-gate uint16_t magic; 1224570Sraf lwp_mutex_t mutex; /* used with process-shared rwlocks */ 1234570Sraf lwp_cond_t readercv; /* used only to indicate ownership */ 1244570Sraf lwp_cond_t writercv; /* used only to indicate ownership */ 1250Sstevel@tonic-gate } lwp_rwlock_t; 1260Sstevel@tonic-gate 1270Sstevel@tonic-gate #endif /* _ASM */ 1280Sstevel@tonic-gate /* 1290Sstevel@tonic-gate * Definitions of synchronization types. 1300Sstevel@tonic-gate */ 1310Sstevel@tonic-gate #define USYNC_THREAD 0x00 /* private to a process */ 1320Sstevel@tonic-gate #define USYNC_PROCESS 0x01 /* shared by processes */ 1330Sstevel@tonic-gate 134*4574Sraf /* Keep the following values in sync with pthread.h */ 135*4574Sraf #define LOCK_NORMAL 0x00 /* same as USYNC_THREAD */ 136*4574Sraf #define LOCK_SHARED 0x01 /* same as USYNC_PROCESS */ 137*4574Sraf #define LOCK_ERRORCHECK 0x02 /* error check lock */ 138*4574Sraf #define LOCK_RECURSIVE 0x04 /* recursive lock */ 139*4574Sraf #define LOCK_PRIO_INHERIT 0x10 /* priority inheritance lock */ 140*4574Sraf #define LOCK_PRIO_PROTECT 0x20 /* priority ceiling lock */ 141*4574Sraf #define LOCK_ROBUST 0x40 /* robust lock */ 1420Sstevel@tonic-gate 143*4574Sraf /* 144*4574Sraf * USYNC_PROCESS_ROBUST is a deprecated historical type. It is mapped 145*4574Sraf * into (USYNC_PROCESS | LOCK_ROBUST) by mutex_init(). Application code 146*4574Sraf * should be revised to use (USYNC_PROCESS | LOCK_ROBUST) rather than this. 147*4574Sraf */ 148*4574Sraf #define USYNC_PROCESS_ROBUST 0x08 1490Sstevel@tonic-gate 1500Sstevel@tonic-gate /* 1510Sstevel@tonic-gate * lwp_mutex_t flags 1520Sstevel@tonic-gate */ 1530Sstevel@tonic-gate #define LOCK_OWNERDEAD 0x1 1540Sstevel@tonic-gate #define LOCK_NOTRECOVERABLE 0x2 1550Sstevel@tonic-gate #define LOCK_INITED 0x4 1560Sstevel@tonic-gate #define LOCK_UNMAPPED 0x8 1570Sstevel@tonic-gate 1580Sstevel@tonic-gate #ifdef __cplusplus 1590Sstevel@tonic-gate } 1600Sstevel@tonic-gate #endif 1610Sstevel@tonic-gate 1620Sstevel@tonic-gate #endif /* _SYS_SYNCH_H */ 163