xref: /illumos-gate/usr/src/contrib/ast/src/lib/libast/include/aso.h (revision b30d193948be5a7794d7ae3ba0ed9c2f72c88e0f)
1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *          Copyright (c) 1985-2011 AT&T Intellectual Property          *
5 *                      and is licensed under the                       *
6 *                 Eclipse Public License, Version 1.0                  *
7 *                    by AT&T Intellectual Property                     *
8 *                                                                      *
9 *                A copy of the License is available at                 *
10 *          http://www.eclipse.org/org/documents/epl-v10.html           *
11 *         (with md5 checksum b35adb5213ca9657e911e9befb180842)         *
12 *                                                                      *
13 *              Information and Software Systems Research               *
14 *                            AT&T Research                             *
15 *                           Florham Park NJ                            *
16 *                                                                      *
17 *                 Glenn Fowler <gsf@research.att.com>                  *
18 *                  David Korn <dgk@research.att.com>                   *
19 *                   Phong Vo <kpv@research.att.com>                    *
20 *                                                                      *
21 ***********************************************************************/
22 #pragma prototyped
23 
24 #ifndef _ASO_H
25 #define _ASO_H	1
26 
27 #define ASO_VERSION	20111111L
28 
29 #include <ast_common.h>
30 
31 /*
32  * ast atomic scalar operations interface definitions
33  */
34 
35 /* asometh() types (ordered mutually exclusive flags) */
36 #define ASO_NEXT	(-1)
37 #define ASO_SIGNAL	1
38 #define ASO_THREAD	2
39 #define ASO_PROCESS	4
40 #define ASO_INTRINSIC	8
41 
42 /* asolock() operations */
43 #define ASO_UNLOCK	0	/* unlock if key matches  		*/
44 #define ASO_TRYLOCK	1	/* matched key means successful attempt	*/
45 #define ASO_LOCK	2	/* matched key first, then spin-lock	*/
46 #define ASO_SPINLOCK	3	/* no matching of key before locking	*/
47 
48 /* Asoerror_f types */
49 #define ASO_EMETHOD	0	/* method specific error		*/
50 #define ASO_EHUNG	1	/* asoloop() possibly hung		*/
51 
52 /* for internal use, but standardized for libs such as CDT and Vmalloc */
53 #define ASO_RELAX	((1<<2)-1) /* cycles between spin-loop yield */
54 #define ASOLOOP(k)	asoloop(++(k))
55 
56 #define ASODISC(d,e)	(memset(d,0,sizeof(*(d))),(d)->version=ASO_VERSION,(d)->errorf=(e))
57 
58 typedef int (*Asoerror_f)(int, const char*);
59 typedef void* (*Asoinit_f)(void*, const char*);
60 typedef ssize_t (*Asolock_f)(void*, ssize_t, void volatile*);
61 
62 typedef struct Asodisc_s
63 {
64 	uint32_t	version;
65 	unsigned int	hung;
66 	Asoerror_f	errorf;
67 } Asodisc_t;
68 
69 typedef struct Asometh_s
70 {
71 	const char*	name;
72 	int		type;
73 	Asoinit_f	initf;
74 	Asolock_f	lockf;
75 	const char*	details;
76 } Asometh_t;
77 
78 #if (_BLD_aso || _BLD_taso) && defined(__EXPORT__)
79 #define extern	extern __EXPORT__
80 #endif
81 #if !(_BLD_aso || _BLD_taso) && defined(__IMPORT__)
82 #define extern	extern __IMPORT__
83 #endif
84 
85 extern Asometh_t*		asometh(int, void*);
86 
87 #undef	extern
88 
89 #if _BLD_aso && defined(__EXPORT__)
90 #define extern	extern __EXPORT__
91 #endif
92 #if !_BLD_aso && defined(__IMPORT__)
93 #define extern	extern __IMPORT__
94 #endif
95 
96 extern Asometh_t*		_asometh(int, void*);
97 extern int			asoinit(const char*, Asometh_t*, Asodisc_t*);
98 extern int			asolock(unsigned int volatile*, unsigned int, int);
99 extern int			asoloop(uintmax_t);
100 extern int			asorelax(long);
101 
102 extern uint8_t			asocas8(uint8_t volatile*, int, int);
103 extern uint8_t			asoget8(uint8_t volatile*);
104 extern uint8_t			asoinc8(uint8_t volatile*);
105 extern uint8_t			asodec8(uint8_t volatile*);
106 
107 #define asocaschar(p,o,n)	asocas8(p,o,n)
108 #define asogetchar(p)		asoget8(p)
109 #define asoincchar(p)		asoinc8(p)
110 #define asodecchar(p)		asodec8(p)
111 
112 extern uint16_t			asocas16(uint16_t volatile*, uint16_t, uint16_t);
113 extern uint16_t			asoget16(uint16_t volatile*);
114 extern uint16_t			asoinc16(uint16_t volatile*);
115 extern uint16_t			asodec16(uint16_t volatile*);
116 
117 #define asocasshort(p,o,n)	asocas16(p,o,n)
118 #define asogetshort(p)		asoget16(p)
119 #define asoincshort(p)		asoinc16(p)
120 #define asodecshort(p)		asodec16(p)
121 
122 extern uint32_t			asocas32(uint32_t volatile*, uint32_t, uint32_t);
123 extern uint32_t			asoget32(uint32_t volatile*);
124 extern uint32_t			asoinc32(uint32_t volatile*);
125 extern uint32_t			asodec32(uint32_t volatile*);
126 
127 #if _ast_sizeof_int == 4
128 #define asocasint(p,o,n)	asocas32((uint32_t volatile*)p,o,n)
129 #define asogetint(p)		asoget32((uint32_t volatile*)p)
130 #define asoincint(p)		asoinc32((uint32_t volatile*)p)
131 #define asodecint(p)		asodec32((uint32_t volatile*)p)
132 #endif
133 
134 #if _ast_sizeof_long == 4
135 #define asocaslong(p,o,n)	asocas32((uint32_t volatile*)p,o,n)
136 #define asogetlong(p)		asoget32((uint32_t volatile*)p)
137 #define asoinclong(p)		asoinc32((uint32_t volatile*)p)
138 #define asodeclong(p)		asodec32((uint32_t volatile*)p)
139 #endif
140 
141 #if _ast_sizeof_size_t == 4
142 #define asocassize(p,o,n)	asocas32((uint32_t volatile*)p,o,n)
143 #define asogetsize(p)		asoget32((uint32_t volatile*)p)
144 #define asoincsize(p)		asoinc32((uint32_t volatile*)p)
145 #define asodecsize(p)		asodec32((uint32_t volatile*)p)
146 #endif
147 
148 #ifdef _ast_int8_t
149 
150 extern uint64_t			asocas64(uint64_t volatile*, uint64_t, uint64_t);
151 extern uint64_t			asoget64(uint64_t volatile*);
152 extern uint64_t			asoinc64(uint64_t volatile*);
153 extern uint64_t			asodec64(uint64_t volatile*);
154 
155 #if _ast_sizeof_int == 8
156 #define asocasint(p,o,n)	asocas64((uint64_t volatile*)p,o,n)
157 #define asogetint(p)		asoget64((uint64_t volatile*)p)
158 #define asoincint(p)		asoinc64((uint64_t volatile*)p)
159 #define asodecint(p)		asodec64((uint64_t volatile*)p)
160 #endif
161 
162 #if _ast_sizeof_long == 8
163 #define asocaslong(p,o,n)	asocas64((uint64_t volatile*)p,o,n)
164 #define asogetlong(p)		asoget64((uint64_t volatile*)p)
165 #define asoinclong(p)		asoinc64((uint64_t volatile*)p)
166 #define asodeclong(p)		asodec64((uint64_t volatile*)p)
167 #endif
168 
169 #if _ast_sizeof_size_t == 8
170 #define asocassize(p,o,n)	asocas64((uint64_t volatile*)p,o,n)
171 #define asogetsize(p)		asoget64((uint64_t volatile*)p)
172 #define asoincsize(p)		asoinc64((uint64_t volatile*)p)
173 #define asodecsize(p)		asodec64((uint64_t volatile*)p)
174 #endif
175 
176 #endif
177 
178 extern void*			asocasptr(void volatile*, void*, void*);
179 extern void*			asogetptr(void volatile*);
180 
181 #undef	extern
182 
183 #endif
184