~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/atomic/sun_studio.h

  • Committer: Lee
  • Date: 2008-10-30 22:02:01 UTC
  • mto: (572.1.2 devel)
  • mto: This revision was merged to the branch mainline in revision 573.
  • Revision ID: lbieber@lbieber-desktop-20081030220201-elb6qprbzpn7c5a4
add my name to the AUTHORS file

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2009 Sun Microsystems, Inc.
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; version 2 of the License.
9
 
 *
10
 
 *  This program is distributed in the hope that it will be useful,
11
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *  GNU General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with this program; if not, write to the Free Software
17
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 
 */
19
 
 
20
 
#ifndef DRIZZLED_ATOMIC_SUN_STUDIO_H
21
 
#define DRIZZLED_ATOMIC_SUN_STUDIO_H
22
 
 
23
 
#define _KERNEL
24
 
#include <atomic.h>
25
 
#undef _KERNEL
26
 
 
27
 
inline bool __sync_fetch_and_add(volatile bool* ptr, bool val)
28
 
{
29
 
  bool ret= *ptr;
30
 
  (val == true) ? atomic_inc_8((volatile uint8_t *)ptr) : atomic_add_8((volatile uint8_t *)ptr, (int8_t)val);
31
 
  return ret;
32
 
}
33
 
 
34
 
inline int8_t __sync_fetch_and_add(volatile int8_t* ptr, int8_t val)
35
 
{
36
 
  int8_t ret= *ptr; 
37
 
  (val == 1) ? atomic_inc_8((volatile uint8_t*)ptr) : atomic_add_8((volatile uint8_t*)ptr, val);
38
 
  return ret;
39
 
}
40
 
 
41
 
inline int16_t __sync_fetch_and_add(volatile int16_t* ptr, int16_t val)
42
 
{
43
 
  int16_t ret= *ptr;
44
 
  (val == 1) ? atomic_inc_16((volatile uint16_t*)ptr) : atomic_add_16((volatile uint16_t*)ptr, val);
45
 
  return ret;
46
 
}
47
 
 
48
 
inline int32_t __sync_fetch_and_add(volatile int32_t* ptr, int32_t val)
49
 
{
50
 
  int32_t ret= *ptr;
51
 
  (val == 1) ? atomic_inc_32((volatile uint32_t*)ptr) : atomic_add_32((volatile uint32_t*)ptr, val);
52
 
  return ret;
53
 
}
54
 
 
55
 
inline uint8_t __sync_fetch_and_add(volatile uint8_t* ptr, uint8_t val)
56
 
{
57
 
  uint8_t ret= *ptr;
58
 
  (val == 1) ? atomic_inc_8(ptr) : atomic_add_8(ptr, (int8_t)val);
59
 
  return ret;
60
 
}
61
 
 
62
 
inline uint16_t __sync_fetch_and_add(volatile uint16_t* ptr, uint16_t val)
63
 
{
64
 
  uint16_t ret= *ptr;
65
 
  (val == 1) ? atomic_inc_16(ptr) : atomic_add_16(ptr, (int16_t)val);
66
 
  return ret;
67
 
}
68
 
 
69
 
inline uint32_t __sync_fetch_and_add(volatile uint32_t* ptr, uint32_t val)
70
 
{
71
 
  uint32_t ret= *ptr;
72
 
  (val == 1) ? atomic_inc_32(ptr) : atomic_add_32(ptr, (int32_t)val);
73
 
  return ret;
74
 
}
75
 
 
76
 
# if defined(_KERNEL) || defined(_INT64_TYPE)
77
 
inline uint64_t __sync_fetch_and_add(volatile uint64_t* ptr, uint64_t val)
78
 
{
79
 
  uint64_t ret= *ptr;
80
 
  (val == 1) ? atomic_inc_64(ptr) : atomic_add_64(ptr, (int64_t)val);
81
 
  return ret;
82
 
}
83
 
 
84
 
inline int64_t __sync_fetch_and_add(volatile int64_t* ptr, int64_t val)
85
 
{
86
 
  int64_t ret= *ptr;
87
 
  (val == 1) ? atomic_inc_64((volatile uint64_t*)ptr) : atomic_add_64((volatile uint64_t*)ptr, val);
88
 
  return ret;
89
 
}
90
 
# endif /* defined(_KERNEL) || defined(_INT64_TYPE) */
91
 
 
92
 
inline uint8_t __sync_fetch_and_sub(volatile uint8_t* ptr, uint8_t val)
93
 
{
94
 
  uint8_t ret= *ptr;
95
 
  (val == 1) ? atomic_dec_8(ptr) : atomic_add_8(ptr, 0-(int8_t)val);
96
 
  return ret;
97
 
}
98
 
 
99
 
inline uint16_t __sync_fetch_and_sub(volatile uint16_t* ptr, uint16_t val)
100
 
{
101
 
  uint16_t ret= *ptr;
102
 
  (val == 1) ? atomic_dec_16(ptr) : atomic_add_16(ptr, 0-(int16_t)val);
103
 
  return ret;
104
 
}
105
 
 
106
 
inline uint32_t __sync_fetch_and_sub(volatile uint32_t* ptr, uint32_t val)
107
 
{
108
 
  uint32_t ret= *ptr;
109
 
  (val == 1) ? atomic_dec_32(ptr) : atomic_add_32(ptr, 0-(int32_t)val);
110
 
  return ret;
111
 
}
112
 
 
113
 
# if defined(_KERNEL) || defined(_INT64_TYPE)
114
 
inline uint64_t __sync_fetch_and_sub(volatile uint64_t* ptr, uint64_t val)
115
 
{
116
 
  uint64_t ret= *ptr;
117
 
  (val == 1) ? atomic_dec_64(ptr) : atomic_add_64(ptr, 0-(int64_t)val);
118
 
  return ret;
119
 
}
120
 
inline int64_t __sync_fetch_and_sub(volatile int64_t* ptr, uint64_t val)
121
 
{
122
 
  int64_t ret= *ptr;
123
 
  (val == 1) ? atomic_dec_64((volatile uint64_t *) ptr) : atomic_add_64((volatile uint64_t *) ptr, 0-(int64_t)val);
124
 
  return ret;
125
 
}
126
 
# endif /* defined(_KERNEL) || defined(_INT64_TYPE) */
127
 
 
128
 
inline bool __sync_add_and_fetch(volatile bool* ptr, bool val)
129
 
{
130
 
  return (val == true) ? atomic_inc_8_nv((volatile uint8_t *)ptr) : atomic_add_8_nv((volatile uint8_t *)ptr, (int8_t)val);
131
 
}
132
 
 
133
 
inline int8_t __sync_add_and_fetch(volatile int8_t* ptr, int8_t val)
134
 
{
135
 
  return (val == 1) ? atomic_inc_8_nv((volatile uint8_t*)ptr) : atomic_add_8_nv((volatile uint8_t*)ptr, val);
136
 
}
137
 
 
138
 
inline int16_t __sync_add_and_fetch(volatile int16_t* ptr, int16_t val)
139
 
{
140
 
  return (val == 1) ? atomic_inc_16_nv((volatile uint16_t*)ptr) : atomic_add_16_nv((volatile uint16_t*)ptr, val);
141
 
}
142
 
 
143
 
inline int32_t __sync_add_and_fetch(volatile int32_t* ptr, int32_t val)
144
 
{
145
 
  return (val == 1) ? atomic_inc_32_nv((volatile uint32_t*)ptr) : atomic_add_32_nv((volatile uint32_t*)ptr, val);
146
 
}
147
 
 
148
 
inline uint8_t __sync_add_and_fetch(volatile uint8_t* ptr, uint8_t val)
149
 
{
150
 
  return (val == 1) ? atomic_inc_8_nv(ptr) : atomic_add_8_nv(ptr, (int8_t)val);
151
 
}
152
 
 
153
 
inline uint16_t __sync_add_and_fetch(volatile uint16_t* ptr, uint16_t val)
154
 
{
155
 
  return (val == 1) ? atomic_inc_16_nv(ptr) : atomic_add_16_nv(ptr, (int16_t)val);
156
 
}
157
 
 
158
 
inline uint32_t __sync_add_and_fetch(volatile uint32_t* ptr, uint32_t val)
159
 
{
160
 
  return (val == 1) ? atomic_inc_32_nv(ptr) : atomic_add_32_nv(ptr, (int32_t)val);
161
 
}
162
 
 
163
 
# if defined(_KERNEL) || defined(_INT64_TYPE)
164
 
inline uint64_t __sync_add_and_fetch(volatile uint64_t* ptr, uint64_t val)
165
 
{
166
 
  return (val == 1) ? atomic_inc_64_nv(ptr) : atomic_add_64_nv(ptr, (int64_t)val);
167
 
}
168
 
 
169
 
inline int64_t __sync_add_and_fetch(volatile int64_t* ptr, int64_t val)
170
 
{
171
 
  return (val == 1) ? atomic_inc_64_nv((volatile uint64_t*)ptr) : atomic_add_64_nv((volatile uint64_t*)ptr, val);
172
 
}
173
 
# endif /* defined(_KERNEL) || defined(_INT64_TYPE) */
174
 
 
175
 
inline uint8_t __sync_sub_and_fetch(volatile uint8_t* ptr, uint8_t val)
176
 
{
177
 
  return (val == 1) ? atomic_dec_8_nv(ptr) : atomic_add_8_nv(ptr, 0-(int8_t)val);
178
 
}
179
 
 
180
 
inline uint16_t __sync_sub_and_fetch(volatile uint16_t* ptr, uint16_t val)
181
 
{
182
 
  return (val == 1) ? atomic_dec_16_nv(ptr) : atomic_add_16_nv(ptr, 0-(int16_t)val);
183
 
}
184
 
 
185
 
inline uint32_t __sync_sub_and_fetch(volatile uint32_t* ptr, uint32_t val)
186
 
{
187
 
  return (val == 1) ? atomic_dec_32_nv(ptr) : atomic_add_32_nv(ptr, 0-(int32_t)val);
188
 
}
189
 
 
190
 
# if defined(_KERNEL) || defined(_INT64_TYPE)
191
 
inline uint64_t __sync_sub_and_fetch(volatile uint64_t* ptr, uint64_t val)
192
 
{
193
 
  return (val == 1) ? atomic_dec_64_nv(ptr) : atomic_add_64_nv(ptr, 0-(int64_t)val);
194
 
}
195
 
inline int64_t __sync_sub_and_fetch(volatile int64_t* ptr, uint64_t val)
196
 
{
197
 
  return (val == 1) ? atomic_dec_64_nv((volatile uint64_t *) ptr) : atomic_add_64_nv((volatile uint64_t *) ptr, 0-(int64_t)val);
198
 
}
199
 
# endif /* defined(_KERNEL) || defined(_INT64_TYPE) */
200
 
 
201
 
inline uint8_t __sync_lock_test_and_set(volatile uint8_t* ptr, uint8_t val)
202
 
{
203
 
  atomic_swap_8(ptr, val);
204
 
  return *ptr;
205
 
}
206
 
 
207
 
inline uint16_t __sync_lock_test_and_set(volatile uint16_t* ptr, uint16_t val)
208
 
{
209
 
  atomic_swap_16(ptr, val);
210
 
  return *ptr;
211
 
}
212
 
 
213
 
inline uint32_t __sync_lock_test_and_set(volatile uint32_t* ptr, uint32_t val)
214
 
{
215
 
  atomic_swap_32(ptr, val);
216
 
  return *ptr;
217
 
}
218
 
 
219
 
# if defined(_KERNEL) || defined(_INT64_TYPE)
220
 
inline uint64_t __sync_lock_test_and_set(volatile uint64_t* ptr, uint64_t val)
221
 
{
222
 
  atomic_swap_64(ptr, val);
223
 
  return *ptr;
224
 
}
225
 
#endif /* defined(_KERNEL) || defined(_INT64_TYPE) */
226
 
 
227
 
inline int8_t __sync_val_compare_and_swap(volatile int8_t* ptr,
228
 
                                           int8_t old_val, int8_t val)
229
 
{
230
 
  atomic_cas_8((volatile uint8_t *)ptr, old_val, val);
231
 
  return *ptr;
232
 
}
233
 
 
234
 
inline uint8_t __sync_val_compare_and_swap(volatile uint8_t* ptr,
235
 
                                           uint8_t old_val, uint8_t val)
236
 
{
237
 
  atomic_cas_8(ptr, old_val, val);
238
 
  return *ptr;
239
 
}
240
 
 
241
 
inline uint16_t __sync_val_compare_and_swap(volatile uint16_t* ptr,
242
 
                                            uint16_t old_val, uint16_t val)
243
 
{
244
 
  atomic_cas_16(ptr, old_val, val);
245
 
  return *ptr;
246
 
}
247
 
 
248
 
inline uint32_t __sync_val_compare_and_swap(volatile uint32_t* ptr,
249
 
                                            uint32_t old_val, uint32_t val)
250
 
{
251
 
  atomic_cas_32(ptr, old_val, val);
252
 
  return *ptr;
253
 
}
254
 
 
255
 
# if defined(_KERNEL) || defined(_INT64_TYPE)
256
 
inline uint64_t __sync_val_compare_and_swap(volatile uint64_t* ptr,
257
 
                                            uint64_t old_val, uint64_t val)
258
 
{
259
 
  atomic_cas_64(ptr, old_val, val);
260
 
  return *ptr;
261
 
}
262
 
#endif /* defined(_KERNEL) || defined(_INT64_TYPE) */
263
 
 
264
 
inline int8_t __sync_bool_compare_and_swap(volatile int8_t* ptr,
265
 
                                           int8_t old_val, int8_t val)
266
 
{
267
 
  int8_t orig= *ptr;
268
 
  return orig == atomic_cas_8((volatile uint8_t *)ptr, old_val, val);
269
 
}
270
 
 
271
 
inline uint8_t __sync_bool_compare_and_swap(volatile uint8_t* ptr,
272
 
                                           uint8_t old_val, uint8_t val)
273
 
{
274
 
  uint8_t orig= *ptr;
275
 
  return orig == atomic_cas_8(ptr, old_val, val);
276
 
}
277
 
 
278
 
inline uint16_t __sync_bool_compare_and_swap(volatile uint16_t* ptr,
279
 
                                            uint16_t old_val, uint16_t val)
280
 
{
281
 
  uint16_t orig= *ptr;
282
 
  return orig == atomic_cas_16(ptr, old_val, val);
283
 
}
284
 
 
285
 
inline uint32_t __sync_bool_compare_and_swap(volatile uint32_t* ptr,
286
 
                                            uint32_t old_val, uint32_t val)
287
 
{
288
 
  uint32_t orig= *ptr;
289
 
  return orig == atomic_cas_32(ptr, old_val, val);
290
 
}
291
 
 
292
 
# if defined(_KERNEL) || defined(_INT64_TYPE)
293
 
inline uint64_t __sync_bool_compare_and_swap(volatile uint64_t* ptr,
294
 
                                            uint64_t old_val, uint64_t val)
295
 
{
296
 
  uint64_t orig= *ptr;
297
 
  return orig == atomic_cas_64(ptr, old_val, val);
298
 
}
299
 
#endif /* defined(_KERNEL) || defined(_INT64_TYPE) */
300
 
 
301
 
#endif /* DRIZZLED_ATOMIC_SUN_STUDIO_H */