~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/atomic/sun_studio.h

  • Committer: Brian Aker
  • Date: 2010-02-07 01:33:54 UTC
  • Revision ID: brian@gaz-20100207013354-d2pg1n68u5c09pgo
Remove giant include header to its own 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
 
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_add_and_fetch(volatile bool* ptr, bool val)
 
28
{
 
29
  (val == true) ? atomic_inc_8((volatile uint8_t *)ptr) : atomic_add_8((volatile uint8_t *)ptr, (int8_t)val);
 
30
  return *ptr;
 
31
}
 
32
 
 
33
inline int8_t __sync_add_and_fetch(volatile int8_t* ptr, int8_t val)
 
34
{
 
35
  (val == 1) ? atomic_inc_8((volatile uint8_t*)ptr) : atomic_add_8((volatile uint8_t*)ptr, val);
 
36
  return *ptr;
 
37
}
 
38
 
 
39
inline int16_t __sync_add_and_fetch(volatile int16_t* ptr, int16_t val)
 
40
{
 
41
  (val == 1) ? atomic_inc_16((volatile uint16_t*)ptr) : atomic_add_16((volatile uint16_t*)ptr, val);
 
42
  return *ptr;
 
43
}
 
44
 
 
45
inline int32_t __sync_add_and_fetch(volatile int32_t* ptr, int32_t val)
 
46
{
 
47
  (val == 1) ? atomic_inc_32((volatile uint32_t*)ptr) : atomic_add_32((volatile uint32_t*)ptr, val);
 
48
  return *ptr;
 
49
}
 
50
 
 
51
inline uint8_t __sync_add_and_fetch(volatile uint8_t* ptr, uint8_t val)
 
52
{
 
53
  (val == 1) ? atomic_inc_8(ptr) : atomic_add_8(ptr, (int8_t)val);
 
54
  return *ptr;
 
55
}
 
56
 
 
57
inline uint16_t __sync_add_and_fetch(volatile uint16_t* ptr, uint16_t val)
 
58
{
 
59
  (val == 1) ? atomic_inc_16(ptr) : atomic_add_16(ptr, (int16_t)val);
 
60
  return *ptr;
 
61
}
 
62
 
 
63
inline uint32_t __sync_add_and_fetch(volatile uint32_t* ptr, uint32_t val)
 
64
{
 
65
  (val == 1) ? atomic_inc_32(ptr) : atomic_add_32(ptr, (int32_t)val);
 
66
  return *ptr;
 
67
}
 
68
 
 
69
# if defined(_KERNEL) || defined(_INT64_TYPE)
 
70
inline uint64_t __sync_add_and_fetch(volatile uint64_t* ptr, uint64_t val)
 
71
{
 
72
  (val == 1) ? atomic_inc_64(ptr) : atomic_add_64(ptr, (int64_t)val);
 
73
  return *ptr;
 
74
}
 
75
 
 
76
inline int64_t __sync_add_and_fetch(volatile int64_t* ptr, int64_t val)
 
77
{
 
78
  (val == 1) ? atomic_inc_64((volatile uint64_t*)ptr) : atomic_add_64((volatile uint64_t*)ptr, val);
 
79
  return *ptr;
 
80
}
 
81
# endif /* defined(_KERNEL) || defined(_INT64_TYPE) */
 
82
 
 
83
 
 
84
inline uint8_t __sync_sub_and_fetch(volatile uint8_t* ptr, uint8_t val)
 
85
{
 
86
  (val == 1) ? atomic_dec_8(ptr) : atomic_add_8(ptr, 0-(int8_t)val);
 
87
  return *ptr;
 
88
}
 
89
 
 
90
inline uint16_t __sync_sub_and_fetch(volatile uint16_t* ptr, uint16_t val)
 
91
{
 
92
  (val == 1) ? atomic_dec_16(ptr) : atomic_add_16(ptr, 0-(int16_t)val);
 
93
  return *ptr;
 
94
}
 
95
 
 
96
inline uint32_t __sync_sub_and_fetch(volatile uint32_t* ptr, uint32_t val)
 
97
{
 
98
  (val == 1) ? atomic_dec_32(ptr) : atomic_add_32(ptr, 0-(int32_t)val);
 
99
  return *ptr;
 
100
}
 
101
 
 
102
# if defined(_KERNEL) || defined(_INT64_TYPE)
 
103
inline uint64_t __sync_sub_and_fetch(volatile uint64_t* ptr, uint64_t val)
 
104
{
 
105
  (val == 1) ? atomic_dec_64(ptr) : atomic_add_64(ptr, 0-(int64_t)val);
 
106
  return *ptr;
 
107
}
 
108
inline int64_t __sync_sub_and_fetch(volatile int64_t* ptr, uint64_t val)
 
109
{
 
110
  (val == 1) ? atomic_dec_64((volatile uint64_t *) ptr) : atomic_add_64((volatile uint64_t *) ptr, 0-(int64_t)val);
 
111
  return *ptr;
 
112
}
 
113
# endif /* defined(_KERNEL) || defined(_INT64_TYPE) */
 
114
 
 
115
inline uint8_t __sync_lock_test_and_set(volatile uint8_t* ptr, uint8_t val)
 
116
{
 
117
  atomic_swap_8(ptr, val);
 
118
  return *ptr;
 
119
}
 
120
 
 
121
inline uint16_t __sync_lock_test_and_set(volatile uint16_t* ptr, uint16_t val)
 
122
{
 
123
  atomic_swap_16(ptr, val);
 
124
  return *ptr;
 
125
}
 
126
 
 
127
inline uint32_t __sync_lock_test_and_set(volatile uint32_t* ptr, uint32_t val)
 
128
{
 
129
  atomic_swap_32(ptr, val);
 
130
  return *ptr;
 
131
}
 
132
 
 
133
# if defined(_KERNEL) || defined(_INT64_TYPE)
 
134
inline uint64_t __sync_lock_test_and_set(volatile uint64_t* ptr, uint64_t val)
 
135
{
 
136
  atomic_swap_64(ptr, val);
 
137
  return *ptr;
 
138
}
 
139
#endif /* defined(_KERNEL) || defined(_INT64_TYPE) */
 
140
 
 
141
inline int8_t __sync_val_compare_and_swap(volatile int8_t* ptr,
 
142
                                           int8_t old_val, int8_t val)
 
143
{
 
144
  atomic_cas_8((volatile uint8_t *)ptr, old_val, val);
 
145
  return *ptr;
 
146
}
 
147
 
 
148
inline uint8_t __sync_val_compare_and_swap(volatile uint8_t* ptr,
 
149
                                           uint8_t old_val, uint8_t val)
 
150
{
 
151
  atomic_cas_8(ptr, old_val, val);
 
152
  return *ptr;
 
153
}
 
154
 
 
155
inline uint16_t __sync_val_compare_and_swap(volatile uint16_t* ptr,
 
156
                                            uint16_t old_val, uint16_t val)
 
157
{
 
158
  atomic_cas_16(ptr, old_val, val);
 
159
  return *ptr;
 
160
}
 
161
 
 
162
inline uint32_t __sync_val_compare_and_swap(volatile uint32_t* ptr,
 
163
                                            uint32_t old_val, uint32_t val)
 
164
{
 
165
  atomic_cas_32(ptr, old_val, val);
 
166
  return *ptr;
 
167
}
 
168
 
 
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)
 
172
{
 
173
  atomic_cas_64(ptr, old_val, val);
 
174
  return *ptr;
 
175
}
 
176
#endif /* defined(_KERNEL) || defined(_INT64_TYPE) */
 
177
 
 
178
#endif /* DRIZZLED_ATOMIC_SUN_STUDIO_H */