1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2009 Sun Microsystems
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.
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.
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
20
#ifndef DRIZZLED_ATOMIC_SUN_STUDIO_H
21
#define DRIZZLED_ATOMIC_SUN_STUDIO_H
27
inline bool __sync_add_and_fetch(volatile bool* ptr, bool val)
29
(val == true) ? atomic_inc_8((volatile uint8_t *)ptr) : atomic_add_8((volatile uint8_t *)ptr, (int8_t)val);
33
inline int8_t __sync_add_and_fetch(volatile int8_t* ptr, int8_t val)
35
(val == 1) ? atomic_inc_8((volatile uint8_t*)ptr) : atomic_add_8((volatile uint8_t*)ptr, val);
39
inline int16_t __sync_add_and_fetch(volatile int16_t* ptr, int16_t val)
41
(val == 1) ? atomic_inc_16((volatile uint16_t*)ptr) : atomic_add_16((volatile uint16_t*)ptr, val);
45
inline int32_t __sync_add_and_fetch(volatile int32_t* ptr, int32_t val)
47
(val == 1) ? atomic_inc_32((volatile uint32_t*)ptr) : atomic_add_32((volatile uint32_t*)ptr, val);
51
inline uint8_t __sync_add_and_fetch(volatile uint8_t* ptr, uint8_t val)
53
(val == 1) ? atomic_inc_8(ptr) : atomic_add_8(ptr, (int8_t)val);
57
inline uint16_t __sync_add_and_fetch(volatile uint16_t* ptr, uint16_t val)
59
(val == 1) ? atomic_inc_16(ptr) : atomic_add_16(ptr, (int16_t)val);
63
inline uint32_t __sync_add_and_fetch(volatile uint32_t* ptr, uint32_t val)
65
(val == 1) ? atomic_inc_32(ptr) : atomic_add_32(ptr, (int32_t)val);
69
# if defined(_KERNEL) || defined(_INT64_TYPE)
70
inline uint64_t __sync_add_and_fetch(volatile uint64_t* ptr, uint64_t val)
72
(val == 1) ? atomic_inc_64(ptr) : atomic_add_64(ptr, (int64_t)val);
76
inline int64_t __sync_add_and_fetch(volatile int64_t* ptr, int64_t val)
78
(val == 1) ? atomic_inc_64((volatile uint64_t*)ptr) : atomic_add_64((volatile uint64_t*)ptr, val);
81
# endif /* defined(_KERNEL) || defined(_INT64_TYPE) */
84
inline uint8_t __sync_sub_and_fetch(volatile uint8_t* ptr, uint8_t val)
86
(val == 1) ? atomic_dec_8(ptr) : atomic_add_8(ptr, 0-(int8_t)val);
90
inline uint16_t __sync_sub_and_fetch(volatile uint16_t* ptr, uint16_t val)
92
(val == 1) ? atomic_dec_16(ptr) : atomic_add_16(ptr, 0-(int16_t)val);
96
inline uint32_t __sync_sub_and_fetch(volatile uint32_t* ptr, uint32_t val)
98
(val == 1) ? atomic_dec_32(ptr) : atomic_add_32(ptr, 0-(int32_t)val);
102
# if defined(_KERNEL) || defined(_INT64_TYPE)
103
inline uint64_t __sync_sub_and_fetch(volatile uint64_t* ptr, uint64_t val)
105
(val == 1) ? atomic_dec_64(ptr) : atomic_add_64(ptr, 0-(int64_t)val);
108
inline int64_t __sync_sub_and_fetch(volatile int64_t* ptr, uint64_t val)
110
(val == 1) ? atomic_dec_64((volatile uint64_t *) ptr) : atomic_add_64((volatile uint64_t *) ptr, 0-(int64_t)val);
113
# endif /* defined(_KERNEL) || defined(_INT64_TYPE) */
115
inline uint8_t __sync_lock_test_and_set(volatile uint8_t* ptr, uint8_t val)
117
atomic_swap_8(ptr, val);
121
inline uint16_t __sync_lock_test_and_set(volatile uint16_t* ptr, uint16_t val)
123
atomic_swap_16(ptr, val);
127
inline uint32_t __sync_lock_test_and_set(volatile uint32_t* ptr, uint32_t val)
129
atomic_swap_32(ptr, val);
133
# if defined(_KERNEL) || defined(_INT64_TYPE)
134
inline uint64_t __sync_lock_test_and_set(volatile uint64_t* ptr, uint64_t val)
136
atomic_swap_64(ptr, val);
139
#endif /* defined(_KERNEL) || defined(_INT64_TYPE) */
141
inline int8_t __sync_val_compare_and_swap(volatile int8_t* ptr,
142
int8_t old_val, int8_t val)
144
atomic_cas_8((volatile uint8_t *)ptr, old_val, val);
148
inline uint8_t __sync_val_compare_and_swap(volatile uint8_t* ptr,
149
uint8_t old_val, uint8_t val)
151
atomic_cas_8(ptr, old_val, val);
155
inline uint16_t __sync_val_compare_and_swap(volatile uint16_t* ptr,
156
uint16_t old_val, uint16_t val)
158
atomic_cas_16(ptr, old_val, val);
162
inline uint32_t __sync_val_compare_and_swap(volatile uint32_t* ptr,
163
uint32_t old_val, uint32_t val)
165
atomic_cas_32(ptr, old_val, val);
169
# if defined(_KERNEL) || defined(_INT64_TYPE)
170
inline uint64_t __sync_val_compare_and_swap(volatile uint64_t* ptr,
171
uint64_t old_val, uint64_t val)
173
atomic_cas_64(ptr, old_val, val);
176
#endif /* defined(_KERNEL) || defined(_INT64_TYPE) */
178
#endif /* DRIZZLED_ATOMIC_SUN_STUDIO_H */