xref: /titanic_51/usr/src/uts/common/sys/synch.h (revision 883492d5a933deb34cd27521e7f2756773cd27af)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
541efec22Sraf  * Common Development and Distribution License (the "License").
641efec22Sraf  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
2141efec22Sraf 
227c478bd9Sstevel@tonic-gate /*
2341efec22Sraf  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #ifndef	_SYS_SYNCH_H
287c478bd9Sstevel@tonic-gate #define	_SYS_SYNCH_H
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #ifndef _ASM
337c478bd9Sstevel@tonic-gate #include <sys/types.h>
347c478bd9Sstevel@tonic-gate #include <sys/int_types.h>
357c478bd9Sstevel@tonic-gate #endif /* _ASM */
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
387c478bd9Sstevel@tonic-gate extern "C" {
397c478bd9Sstevel@tonic-gate #endif
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate #ifndef _ASM
427c478bd9Sstevel@tonic-gate /*
437c478bd9Sstevel@tonic-gate  * Thread and LWP mutexes have the same type
447c478bd9Sstevel@tonic-gate  * definitions.
457c478bd9Sstevel@tonic-gate  *
467c478bd9Sstevel@tonic-gate  * NOTE:
477c478bd9Sstevel@tonic-gate  *
487c478bd9Sstevel@tonic-gate  * POSIX requires that <pthread.h> define the structures pthread_mutex_t
497c478bd9Sstevel@tonic-gate  * and pthread_cond_t.  Although these structures are identical to mutex_t
507c478bd9Sstevel@tonic-gate  * (lwp_mutex_t) and cond_t (lwp_cond_t), defined here, a typedef of these
517c478bd9Sstevel@tonic-gate  * types would require including <synch.h> in <pthread.h>, pulling in
527c478bd9Sstevel@tonic-gate  * non-posix symbols/constants, violating POSIX namespace restrictions.  Hence,
537c478bd9Sstevel@tonic-gate  * pthread_mutex_t/pthread_cond_t have been redefined (in <sys/types.h>).
547c478bd9Sstevel@tonic-gate  * Any modifications done to mutex_t/lwp_mutex_t or cond_t/lwp_cond_t must
557c478bd9Sstevel@tonic-gate  * also be done to pthread_mutex_t/pthread_cond_t.
567c478bd9Sstevel@tonic-gate  */
577c478bd9Sstevel@tonic-gate typedef struct _lwp_mutex {
587c478bd9Sstevel@tonic-gate 	struct {
597c478bd9Sstevel@tonic-gate 		uint16_t	flag1;
607c478bd9Sstevel@tonic-gate 		uint8_t		flag2;
617c478bd9Sstevel@tonic-gate 		uint8_t		ceiling;
627c478bd9Sstevel@tonic-gate 		union {
637c478bd9Sstevel@tonic-gate 			uint16_t bcptype;
647c478bd9Sstevel@tonic-gate 			struct {
657c478bd9Sstevel@tonic-gate 				uint8_t	count_type1;
667c478bd9Sstevel@tonic-gate 				uint8_t	count_type2;
677c478bd9Sstevel@tonic-gate 			} mtype_rcount;
687c478bd9Sstevel@tonic-gate 		} mbcp_type_un;
697c478bd9Sstevel@tonic-gate 		uint16_t	magic;
707c478bd9Sstevel@tonic-gate 	} flags;
717c478bd9Sstevel@tonic-gate 	union {
727c478bd9Sstevel@tonic-gate 		struct {
737c478bd9Sstevel@tonic-gate 			uint8_t	pad[8];
747c478bd9Sstevel@tonic-gate 		} lock64;
757c478bd9Sstevel@tonic-gate 		struct {
767c478bd9Sstevel@tonic-gate 			uint32_t ownerpid;
777c478bd9Sstevel@tonic-gate 			uint32_t lockword;
787c478bd9Sstevel@tonic-gate 		} lock32;
797c478bd9Sstevel@tonic-gate 		upad64_t owner64;
807c478bd9Sstevel@tonic-gate 	} lock;
817c478bd9Sstevel@tonic-gate 	upad64_t data;
827c478bd9Sstevel@tonic-gate } lwp_mutex_t;
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate /*
857c478bd9Sstevel@tonic-gate  * Thread and LWP condition variables have the same
867c478bd9Sstevel@tonic-gate  * type definition.
877c478bd9Sstevel@tonic-gate  * NOTE:
887c478bd9Sstevel@tonic-gate  * The layout of the following structure should be kept in sync with the
897c478bd9Sstevel@tonic-gate  * layout of pthread_cond_t in sys/types.h. See NOTE above for lwp_mutex_t.
907c478bd9Sstevel@tonic-gate  */
917c478bd9Sstevel@tonic-gate typedef struct _lwp_cond {
927c478bd9Sstevel@tonic-gate 	struct {
937c478bd9Sstevel@tonic-gate 		uint8_t		flag[4];
947c478bd9Sstevel@tonic-gate 		uint16_t 	type;
957c478bd9Sstevel@tonic-gate 		uint16_t 	magic;
967c478bd9Sstevel@tonic-gate 	} flags;
977c478bd9Sstevel@tonic-gate 	upad64_t data;
987c478bd9Sstevel@tonic-gate } lwp_cond_t;
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate /*
1017c478bd9Sstevel@tonic-gate  * LWP semaphores
1027c478bd9Sstevel@tonic-gate  */
1037c478bd9Sstevel@tonic-gate typedef struct _lwp_sema {
1047c478bd9Sstevel@tonic-gate 	uint32_t	count;		/* semaphore count */
1057c478bd9Sstevel@tonic-gate 	uint16_t 	type;
1067c478bd9Sstevel@tonic-gate 	uint16_t 	magic;
1077c478bd9Sstevel@tonic-gate 	uint8_t		flags[8];	/* last byte reserved for waiters */
1087c478bd9Sstevel@tonic-gate 	upad64_t	data;		/* optional data */
1097c478bd9Sstevel@tonic-gate } lwp_sema_t;
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate /*
1127c478bd9Sstevel@tonic-gate  * Thread and LWP rwlocks have the same type definition.
1137c478bd9Sstevel@tonic-gate  * NOTE: The layout of this structure should be kept in sync with the layout
1147c478bd9Sstevel@tonic-gate  * of the correponding structure of pthread_rwlock_t in sys/types.h.
1157c478bd9Sstevel@tonic-gate  * Also, because we have to deal with C++, there is an identical structure
1167c478bd9Sstevel@tonic-gate  * for rwlock_t in head/sync.h that we cannot change.
1177c478bd9Sstevel@tonic-gate  */
1187c478bd9Sstevel@tonic-gate typedef struct _lwp_rwlock {
11941efec22Sraf 	int32_t		readers;	/* rwstate word */
1207c478bd9Sstevel@tonic-gate 	uint16_t	type;
1217c478bd9Sstevel@tonic-gate 	uint16_t	magic;
12241efec22Sraf 	lwp_mutex_t	mutex;		/* used with process-shared rwlocks */
12341efec22Sraf 	lwp_cond_t	readercv;	/* used only to indicate ownership */
12441efec22Sraf 	lwp_cond_t	writercv;	/* used only to indicate ownership */
1257c478bd9Sstevel@tonic-gate } lwp_rwlock_t;
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate #endif /* _ASM */
1287c478bd9Sstevel@tonic-gate /*
1297c478bd9Sstevel@tonic-gate  * Definitions of synchronization types.
1307c478bd9Sstevel@tonic-gate  */
1317c478bd9Sstevel@tonic-gate #define	USYNC_THREAD	0x00		/* private to a process */
1327c478bd9Sstevel@tonic-gate #define	USYNC_PROCESS	0x01		/* shared by processes */
1337c478bd9Sstevel@tonic-gate 
134*883492d5Sraf /* Keep the following values in sync with pthread.h */
1357c478bd9Sstevel@tonic-gate #define	LOCK_NORMAL		0x00		/* same as USYNC_THREAD */
136*883492d5Sraf #define	LOCK_SHARED		0x01		/* same as USYNC_PROCESS */
1377c478bd9Sstevel@tonic-gate #define	LOCK_ERRORCHECK		0x02		/* error check lock */
1387c478bd9Sstevel@tonic-gate #define	LOCK_RECURSIVE		0x04		/* recursive lock */
139*883492d5Sraf #define	LOCK_PRIO_INHERIT	0x10		/* priority inheritance lock */
140*883492d5Sraf #define	LOCK_PRIO_PROTECT	0x20		/* priority ceiling lock */
141*883492d5Sraf #define	LOCK_ROBUST		0x40		/* robust lock */
1427c478bd9Sstevel@tonic-gate 
143*883492d5Sraf /*
144*883492d5Sraf  * USYNC_PROCESS_ROBUST is a deprecated historical type.  It is mapped
145*883492d5Sraf  * into (USYNC_PROCESS | LOCK_ROBUST) by mutex_init().  Application code
146*883492d5Sraf  * should be revised to use (USYNC_PROCESS | LOCK_ROBUST) rather than this.
147*883492d5Sraf  */
148*883492d5Sraf #define	USYNC_PROCESS_ROBUST	0x08
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate /*
1517c478bd9Sstevel@tonic-gate  * lwp_mutex_t flags
1527c478bd9Sstevel@tonic-gate  */
1537c478bd9Sstevel@tonic-gate #define	LOCK_OWNERDEAD		0x1
1547c478bd9Sstevel@tonic-gate #define	LOCK_NOTRECOVERABLE	0x2
1557c478bd9Sstevel@tonic-gate #define	LOCK_INITED		0x4
1567c478bd9Sstevel@tonic-gate #define	LOCK_UNMAPPED		0x8
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1597c478bd9Sstevel@tonic-gate }
1607c478bd9Sstevel@tonic-gate #endif
1617c478bd9Sstevel@tonic-gate 
1627c478bd9Sstevel@tonic-gate #endif /* _SYS_SYNCH_H */
163