xref: /illumos-gate/usr/src/uts/common/sys/sobject.h (revision 2d6eb4a5)
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 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SYS_SOBJECT_H
28 #define	_SYS_SOBJECT_H
29 
30 #include <sys/types.h>
31 #include <sys/thread.h>
32 
33 #ifdef	__cplusplus
34 extern "C" {
35 #endif
36 
37 /*
38  * Type-number definitions for the various synchronization
39  * objects defined for the system. The numeric values
40  * assigned to the various definitions begin with zero, since
41  * the synch-object mapping array depends on these values.
42  */
43 #define	SOBJ_NONE	0	/* undefined synchonization object */
44 #define	SOBJ_MUTEX	1	/* mutex synchonization object */
45 #define	SOBJ_RWLOCK	2	/* readers/writer synchonization object */
46 #define	SOBJ_CV		3	/* cond. variable synchonization object */
47 #define	SOBJ_SEMA	4	/* semaphore synchonization object */
48 #define	SOBJ_USER	5	/* user-level synchronization object */
49 #define	SOBJ_USER_PI	6	/* user-level sobj having Prio Inheritance */
50 #define	SOBJ_SHUTTLE 	7	/* shuttle synchronization object */
51 
52 /*
53  * The following data structure is used to map
54  * synchronization object type numbers to the
55  * synchronization object's sleep queue number
56  * or the synch. object's owner function.
57  */
58 typedef struct _sobj_ops {
59 	int		sobj_type;
60 	kthread_t	*(*sobj_owner)();
61 	void		(*sobj_unsleep)(kthread_t *);
62 	void		(*sobj_change_pri)(kthread_t *, pri_t, pri_t *);
63 } sobj_ops_t;
64 
65 #ifdef	_KERNEL
66 
67 #define	SOBJ_TYPE(sobj_ops)		sobj_ops->sobj_type
68 #define	SOBJ_OWNER(sobj_ops, sobj)	(*(sobj_ops->sobj_owner))(sobj)
69 #define	SOBJ_UNSLEEP(sobj_ops, t)	(*(sobj_ops->sobj_unsleep))(t)
70 #define	SOBJ_CHANGE_PRI(sobj_ops, t, pri)	\
71 			(*(sobj_ops->sobj_change_pri))(t, pri, &t->t_pri)
72 #define	SOBJ_CHANGE_EPRI(sobj_ops, t, pri)	\
73 			(*(sobj_ops->sobj_change_pri))(t, pri, &t->t_epri)
74 
75 #endif	/* _KERNEL */
76 
77 #ifdef	__cplusplus
78 }
79 #endif
80 
81 #endif	/* _SYS_SOBJECT_H */
82