1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
|
/* Copyright (C) 2008 MySQL AB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include <atomic.h>
#define MY_ATOMIC_MODE "solaris-atomic"
/*
* This is defined to indicate we fully define the my_atomic_* (inline)
* functions here, so there is no need to "make" them in my_atomic.h
* using make_atomic_* and make_atomic_*_body.
*/
#define MY_ATOMICS_MADE
STATIC_INLINE int
my_atomic_cas8(int8 volatile *a, int8 *cmp, int8 set)
{
int ret;
int8 sav;
sav = (int8) atomic_cas_8((volatile uint8_t *)a, (uint8_t)*cmp,
(uint8_t)set);
if (! (ret = (sav == *cmp)))
*cmp = sav;
return ret;
}
STATIC_INLINE int
my_atomic_cas16(int16 volatile *a, int16 *cmp, int16 set)
{
int ret;
int16 sav;
sav = (int16) atomic_cas_16((volatile uint16_t *)a, (uint16_t)*cmp,
(uint16_t)set);
if (! (ret = (sav == *cmp)))
*cmp = sav;
return ret;
}
STATIC_INLINE int
my_atomic_cas32(int32 volatile *a, int32 *cmp, int32 set)
{
int ret;
int32 sav;
sav = (int32) atomic_cas_32((volatile uint32_t *)a, (uint32_t)*cmp,
(uint32_t)set);
if (! (ret = (sav == *cmp)))
*cmp = sav;
return ret;
}
STATIC_INLINE int
my_atomic_casptr(void * volatile *a, void **cmp, void *set)
{
int ret;
void *sav;
sav = atomic_cas_ptr(a, *cmp, set);
if (! (ret = (sav == *cmp)))
*cmp = sav;
return ret;
}
/* ------------------------------------------------------------------------ */
STATIC_INLINE int8
my_atomic_add8(int8 volatile *a, int8 v)
{
int8 nv;
nv = atomic_add_8_nv((volatile uint8_t *)a, v);
return (nv - v);
}
STATIC_INLINE int16
my_atomic_add16(int16 volatile *a, int16 v)
{
int16 nv;
nv = atomic_add_16_nv((volatile uint16_t *)a, v);
return (nv - v);
}
STATIC_INLINE int32
my_atomic_add32(int32 volatile *a, int32 v)
{
int32 nv;
nv = atomic_add_32_nv((volatile uint32_t *)a, v);
return (nv - v);
}
/* ------------------------------------------------------------------------ */
#ifdef MY_ATOMIC_MODE_DUMMY
STATIC_INLINE int8
my_atomic_load8(int8 volatile *a) { return (*a); }
STATIC_INLINE int16
my_atomic_load16(int16 volatile *a) { return (*a); }
STATIC_INLINE int32
my_atomic_load32(int32 volatile *a) { return (*a); }
STATIC_INLINE void *
my_atomic_loadptr(void * volatile *a) { return (*a); }
/* ------------------------------------------------------------------------ */
STATIC_INLINE void
my_atomic_store8(int8 volatile *a, int8 v) { *a = v; }
STATIC_INLINE void
my_atomic_store16(int16 volatile *a, int16 v) { *a = v; }
STATIC_INLINE void
my_atomic_store32(int32 volatile *a, int32 v) { *a = v; }
STATIC_INLINE void
my_atomic_storeptr(void * volatile *a, void *v) { *a = v; }
/* ------------------------------------------------------------------------ */
#else /* MY_ATOMIC_MODE_DUMMY */
STATIC_INLINE int8
my_atomic_load8(int8 volatile *a)
{
return ((int8) atomic_or_8_nv((volatile uint8_t *)a, 0));
}
STATIC_INLINE int16
my_atomic_load16(int16 volatile *a)
{
return ((int16) atomic_or_16_nv((volatile uint16_t *)a, 0));
}
STATIC_INLINE int32
my_atomic_load32(int32 volatile *a)
{
return ((int32) atomic_or_32_nv((volatile uint32_t *)a, 0));
}
STATIC_INLINE void *
my_atomic_loadptr(void * volatile *a)
{
return ((void *) atomic_or_ulong_nv((volatile ulong_t *)a, 0));
}
/* ------------------------------------------------------------------------ */
STATIC_INLINE void
my_atomic_store8(int8 volatile *a, int8 v)
{
(void) atomic_swap_8((volatile uint8_t *)a, (uint8_t)v);
}
STATIC_INLINE void
my_atomic_store16(int16 volatile *a, int16 v)
{
(void) atomic_swap_16((volatile uint16_t *)a, (uint16_t)v);
}
STATIC_INLINE void
my_atomic_store32(int32 volatile *a, int32 v)
{
(void) atomic_swap_32((volatile uint32_t *)a, (uint32_t)v);
}
STATIC_INLINE void
my_atomic_storeptr(void * volatile *a, void *v)
{
(void) atomic_swap_ptr(a, v);
}
#endif
/* ------------------------------------------------------------------------ */
STATIC_INLINE int8
my_atomic_fas8(int8 volatile *a, int8 v)
{
return ((int8) atomic_swap_8((volatile uint8_t *)a, (uint8_t)v));
}
STATIC_INLINE int16
my_atomic_fas16(int16 volatile *a, int16 v)
{
return ((int16) atomic_swap_16((volatile uint16_t *)a, (uint16_t)v));
}
STATIC_INLINE int32
my_atomic_fas32(int32 volatile *a, int32 v)
{
return ((int32) atomic_swap_32((volatile uint32_t *)a, (uint32_t)v));
}
STATIC_INLINE void *
my_atomic_fasptr(void * volatile *a, void *v)
{
return (atomic_swap_ptr(a, v));
}
|