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 uint8_t __sync_add_and_fetch(volatile uint8_t* ptr, uint8_t val)
29
(val == 1) ? atomic_inc_8(ptr) : atomic_add_8(ptr, (int8_t)val);
33
inline uint16_t __sync_add_and_fetch(volatile uint16_t* ptr, uint16_t val)
35
(val == 1) ? atomic_inc_16(ptr) : atomic_add_16(ptr, (int16_t)val);
39
inline uint32_t __sync_add_and_fetch(volatile uint32_t* ptr, uint32_t val)
41
(val == 1) ? atomic_inc_32(ptr) : atomic_add_32(ptr, (int32_t)val);
45
# if defined(_KERNEL) || defined(_INT64_TYPE)
46
inline uint64_t __sync_add_and_fetch(volatile uint64_t* ptr, uint64_t val)
48
(val == 1) ? atomic_inc_64(ptr) : atomic_add_64(ptr, (int64_t)val);
51
# endif /* defined(_KERNEL) || defined(_INT64_TYPE) */
54
inline uint8_t __sync_sub_and_fetch(volatile uint8_t* ptr, uint8_t val)
56
(val == 1) ? atomic_dec_8(ptr) : atomic_add_8(ptr, 0-(int8_t)val);
60
inline uint16_t __sync_sub_and_fetch(volatile uint16_t* ptr, uint16_t val)
62
(val == 1) ? atomic_dec_16(ptr) : atomic_add_16(ptr, 0-(int16_t)val);
66
inline uint32_t __sync_sub_and_fetch(volatile uint32_t* ptr, uint32_t val)
68
(val == 1) ? atomic_dec_32(ptr) : atomic_add_32(ptr, 0-(int32_t)val);
72
# if defined(_KERNEL) || defined(_INT64_TYPE)
73
inline uint64_t __sync_sub_and_fetch(volatile uint64_t* ptr, uint64_t val)
75
(val == 1) ? atomic_dec_64(ptr) : atomic_add_64(ptr, 0-(int64_t)val);
78
# endif /* defined(_KERNEL) || defined(_INT64_TYPE) */
81
inline uint8_t __sync_lock_test_and_set(volatile uint8_t* ptr, uint8_t val)
83
atomic_swap_8(ptr, val);
87
inline uint16_t __sync_lock_test_and_set(volatile uint16_t* ptr, uint16_t val)
89
atomic_swap_16(ptr, val);
93
inline uint32_t __sync_lock_test_and_set(volatile uint32_t* ptr, uint32_t val)
95
atomic_swap_32(ptr, val);
99
# if defined(_KERNEL) || defined(_INT64_TYPE)
100
inline uint64_t __sync_lock_test_and_set(volatile uint64_t* ptr, uint64_t val)
102
atomic_swap_64(ptr, val);
105
#endif /* defined(_KERNEL) || defined(_INT64_TYPE) */
107
inline uint8_t __sync_val_compare_and_swap(volatile uint8_t* ptr,
108
uint8_t old_val, uint8_t val)
110
atomic_cas_8(ptr, old_val, val);
114
inline uint16_t __sync_val_compare_and_swap(volatile uint16_t* ptr,
115
uint16_t old_val, uint16_t val)
117
atomic_cas_16(ptr, old_val, val);
121
inline uint32_t __sync_val_compare_and_swap(volatile uint32_t* ptr,
122
uint32_t old_val, uint32_t val)
124
atomic_cas_32(ptr, old_val, val);
128
# if defined(_KERNEL) || defined(_INT64_TYPE)
129
inline uint64_t __sync_val_compare_and_swap(volatile uint64_t* ptr,
130
uint64_t old_val, uint64_t val)
132
atomic_cas_64(ptr, old_val, val);
135
#endif /* defined(_KERNEL) || defined(_INT64_TYPE) */
138
#endif /* DRIZZLED_ATOMIC_SOLARIS_H */