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 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
|
/* atomic.c -- implement atomic routines for Go.
Copyright 2011 The Go Authors. All rights reserved.
Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file. */
#include <stdint.h>
#include "runtime.h"
int32_t SwapInt32 (int32_t *, int32_t)
__asm__ (GOSYM_PREFIX "sync_atomic.SwapInt32")
__attribute__ ((no_split_stack));
int32_t
SwapInt32 (int32_t *addr, int32_t new)
{
return __atomic_exchange_n (addr, new, __ATOMIC_SEQ_CST);
}
int64_t SwapInt64 (int64_t *, int64_t)
__asm__ (GOSYM_PREFIX "sync_atomic.SwapInt64")
__attribute__ ((no_split_stack));
int64_t
SwapInt64 (int64_t *addr, int64_t new)
{
return __atomic_exchange_n (addr, new, __ATOMIC_SEQ_CST);
}
uint32_t SwapUint32 (uint32_t *, uint32_t)
__asm__ (GOSYM_PREFIX "sync_atomic.SwapUint32")
__attribute__ ((no_split_stack));
uint32_t
SwapUint32 (uint32_t *addr, uint32_t new)
{
return __atomic_exchange_n (addr, new, __ATOMIC_SEQ_CST);
}
uint64_t SwapUint64 (uint64_t *, uint64_t)
__asm__ (GOSYM_PREFIX "sync_atomic.SwapUint64")
__attribute__ ((no_split_stack));
uint64_t
SwapUint64 (uint64_t *addr, uint64_t new)
{
return __atomic_exchange_n (addr, new, __ATOMIC_SEQ_CST);
}
uintptr_t SwapUintptr (uintptr_t *, uintptr_t)
__asm__ (GOSYM_PREFIX "sync_atomic.SwapUintptr")
__attribute__ ((no_split_stack));
uintptr_t
SwapUintptr (uintptr_t *addr, uintptr_t new)
{
return __atomic_exchange_n (addr, new, __ATOMIC_SEQ_CST);
}
void *SwapPointer (void **, void *)
__asm__ (GOSYM_PREFIX "sync_atomic.SwapPointer")
__attribute__ ((no_split_stack));
void *
SwapPointer (void **addr, void *new)
{
return __atomic_exchange_n (addr, new, __ATOMIC_SEQ_CST);
}
_Bool CompareAndSwapInt32 (int32_t *, int32_t, int32_t)
__asm__ (GOSYM_PREFIX "sync_atomic.CompareAndSwapInt32")
__attribute__ ((no_split_stack));
_Bool
CompareAndSwapInt32 (int32_t *val, int32_t old, int32_t new)
{
return __sync_bool_compare_and_swap (val, old, new);
}
_Bool CompareAndSwapInt64 (int64_t *, int64_t, int64_t)
__asm__ (GOSYM_PREFIX "sync_atomic.CompareAndSwapInt64")
__attribute__ ((no_split_stack));
_Bool
CompareAndSwapInt64 (int64_t *val, int64_t old, int64_t new)
{
return __sync_bool_compare_and_swap (val, old, new);
}
_Bool CompareAndSwapUint32 (uint32_t *, uint32_t, uint32_t)
__asm__ (GOSYM_PREFIX "sync_atomic.CompareAndSwapUint32")
__attribute__ ((no_split_stack));
_Bool
CompareAndSwapUint32 (uint32_t *val, uint32_t old, uint32_t new)
{
return __sync_bool_compare_and_swap (val, old, new);
}
_Bool CompareAndSwapUint64 (uint64_t *, uint64_t, uint64_t)
__asm__ (GOSYM_PREFIX "sync_atomic.CompareAndSwapUint64")
__attribute__ ((no_split_stack));
_Bool
CompareAndSwapUint64 (uint64_t *val, uint64_t old, uint64_t new)
{
return __sync_bool_compare_and_swap (val, old, new);
}
_Bool CompareAndSwapUintptr (uintptr_t *, uintptr_t, uintptr_t)
__asm__ (GOSYM_PREFIX "sync_atomic.CompareAndSwapUintptr")
__attribute__ ((no_split_stack));
_Bool
CompareAndSwapUintptr (uintptr_t *val, uintptr_t old, uintptr_t new)
{
return __sync_bool_compare_and_swap (val, old, new);
}
_Bool CompareAndSwapPointer (void **, void *, void *)
__asm__ (GOSYM_PREFIX "sync_atomic.CompareAndSwapPointer")
__attribute__ ((no_split_stack));
_Bool
CompareAndSwapPointer (void **val, void *old, void *new)
{
return __sync_bool_compare_and_swap (val, old, new);
}
int32_t AddInt32 (int32_t *, int32_t)
__asm__ (GOSYM_PREFIX "sync_atomic.AddInt32")
__attribute__ ((no_split_stack));
int32_t
AddInt32 (int32_t *val, int32_t delta)
{
return __sync_add_and_fetch (val, delta);
}
uint32_t AddUint32 (uint32_t *, uint32_t)
__asm__ (GOSYM_PREFIX "sync_atomic.AddUint32")
__attribute__ ((no_split_stack));
uint32_t
AddUint32 (uint32_t *val, uint32_t delta)
{
return __sync_add_and_fetch (val, delta);
}
int64_t AddInt64 (int64_t *, int64_t)
__asm__ (GOSYM_PREFIX "sync_atomic.AddInt64")
__attribute__ ((no_split_stack));
int64_t
AddInt64 (int64_t *val, int64_t delta)
{
return __sync_add_and_fetch (val, delta);
}
uint64_t AddUint64 (uint64_t *, uint64_t)
__asm__ (GOSYM_PREFIX "sync_atomic.AddUint64")
__attribute__ ((no_split_stack));
uint64_t
AddUint64 (uint64_t *val, uint64_t delta)
{
return __sync_add_and_fetch (val, delta);
}
uintptr_t AddUintptr (uintptr_t *, uintptr_t)
__asm__ (GOSYM_PREFIX "sync_atomic.AddUintptr")
__attribute__ ((no_split_stack));
uintptr_t
AddUintptr (uintptr_t *val, uintptr_t delta)
{
return __sync_add_and_fetch (val, delta);
}
int32_t LoadInt32 (int32_t *addr)
__asm__ (GOSYM_PREFIX "sync_atomic.LoadInt32")
__attribute__ ((no_split_stack));
int32_t
LoadInt32 (int32_t *addr)
{
int32_t v;
v = *addr;
while (! __sync_bool_compare_and_swap (addr, v, v))
v = *addr;
return v;
}
int64_t LoadInt64 (int64_t *addr)
__asm__ (GOSYM_PREFIX "sync_atomic.LoadInt64")
__attribute__ ((no_split_stack));
int64_t
LoadInt64 (int64_t *addr)
{
int64_t v;
v = *addr;
while (! __sync_bool_compare_and_swap (addr, v, v))
v = *addr;
return v;
}
uint32_t LoadUint32 (uint32_t *addr)
__asm__ (GOSYM_PREFIX "sync_atomic.LoadUint32")
__attribute__ ((no_split_stack));
uint32_t
LoadUint32 (uint32_t *addr)
{
uint32_t v;
v = *addr;
while (! __sync_bool_compare_and_swap (addr, v, v))
v = *addr;
return v;
}
uint64_t LoadUint64 (uint64_t *addr)
__asm__ (GOSYM_PREFIX "sync_atomic.LoadUint64")
__attribute__ ((no_split_stack));
uint64_t
LoadUint64 (uint64_t *addr)
{
uint64_t v;
v = *addr;
while (! __sync_bool_compare_and_swap (addr, v, v))
v = *addr;
return v;
}
uintptr_t LoadUintptr (uintptr_t *addr)
__asm__ (GOSYM_PREFIX "sync_atomic.LoadUintptr")
__attribute__ ((no_split_stack));
uintptr_t
LoadUintptr (uintptr_t *addr)
{
uintptr_t v;
v = *addr;
while (! __sync_bool_compare_and_swap (addr, v, v))
v = *addr;
return v;
}
void *LoadPointer (void **addr)
__asm__ (GOSYM_PREFIX "sync_atomic.LoadPointer")
__attribute__ ((no_split_stack));
void *
LoadPointer (void **addr)
{
void *v;
v = *addr;
while (! __sync_bool_compare_and_swap (addr, v, v))
v = *addr;
return v;
}
void StoreInt32 (int32_t *addr, int32_t val)
__asm__ (GOSYM_PREFIX "sync_atomic.StoreInt32")
__attribute__ ((no_split_stack));
void
StoreInt32 (int32_t *addr, int32_t val)
{
int32_t v;
v = *addr;
while (! __sync_bool_compare_and_swap (addr, v, val))
v = *addr;
}
void StoreInt64 (int64_t *addr, int64_t val)
__asm__ (GOSYM_PREFIX "sync_atomic.StoreInt64")
__attribute__ ((no_split_stack));
void
StoreInt64 (int64_t *addr, int64_t val)
{
int64_t v;
v = *addr;
while (! __sync_bool_compare_and_swap (addr, v, val))
v = *addr;
}
void StoreUint32 (uint32_t *addr, uint32_t val)
__asm__ (GOSYM_PREFIX "sync_atomic.StoreUint32")
__attribute__ ((no_split_stack));
void
StoreUint32 (uint32_t *addr, uint32_t val)
{
uint32_t v;
v = *addr;
while (! __sync_bool_compare_and_swap (addr, v, val))
v = *addr;
}
void StoreUint64 (uint64_t *addr, uint64_t val)
__asm__ (GOSYM_PREFIX "sync_atomic.StoreUint64")
__attribute__ ((no_split_stack));
void
StoreUint64 (uint64_t *addr, uint64_t val)
{
uint64_t v;
v = *addr;
while (! __sync_bool_compare_and_swap (addr, v, val))
v = *addr;
}
void StoreUintptr (uintptr_t *addr, uintptr_t val)
__asm__ (GOSYM_PREFIX "sync_atomic.StoreUintptr")
__attribute__ ((no_split_stack));
void
StoreUintptr (uintptr_t *addr, uintptr_t val)
{
uintptr_t v;
v = *addr;
while (! __sync_bool_compare_and_swap (addr, v, val))
v = *addr;
}
void StorePointer (void **addr, void *val)
__asm__ (GOSYM_PREFIX "sync_atomic.StorePointer")
__attribute__ ((no_split_stack));
void
StorePointer (void **addr, void *val)
{
void *v;
v = *addr;
while (! __sync_bool_compare_and_swap (addr, v, val))
v = *addr;
}
|