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