1 /* atomic.c -- implement atomic routines for Go.
3 Copyright 2011 The Go Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style
5 license that can be found in the LICENSE file. */
11 _Bool CompareAndSwapInt32 (int32_t *, int32_t, int32_t)
12 __asm__ (GOSYM_PREFIX "sync_atomic.CompareAndSwapInt32");
15 CompareAndSwapInt32 (int32_t *val, int32_t old, int32_t new)
17 return __sync_bool_compare_and_swap (val, old, new);
20 _Bool CompareAndSwapInt64 (int64_t *, int64_t, int64_t)
21 __asm__ (GOSYM_PREFIX "sync_atomic.CompareAndSwapInt64");
24 CompareAndSwapInt64 (int64_t *val, int64_t old, int64_t new)
26 return __sync_bool_compare_and_swap (val, old, new);
29 _Bool CompareAndSwapUint32 (uint32_t *, uint32_t, uint32_t)
30 __asm__ (GOSYM_PREFIX "sync_atomic.CompareAndSwapUint32");
33 CompareAndSwapUint32 (uint32_t *val, uint32_t old, uint32_t new)
35 return __sync_bool_compare_and_swap (val, old, new);
38 _Bool CompareAndSwapUint64 (uint64_t *, uint64_t, uint64_t)
39 __asm__ (GOSYM_PREFIX "sync_atomic.CompareAndSwapUint64");
42 CompareAndSwapUint64 (uint64_t *val, uint64_t old, uint64_t new)
44 return __sync_bool_compare_and_swap (val, old, new);
47 _Bool CompareAndSwapUintptr (uintptr_t *, uintptr_t, uintptr_t)
48 __asm__ (GOSYM_PREFIX "sync_atomic.CompareAndSwapUintptr");
51 CompareAndSwapUintptr (uintptr_t *val, uintptr_t old, uintptr_t new)
53 return __sync_bool_compare_and_swap (val, old, new);
56 _Bool CompareAndSwapPointer (void **, void *, void *)
57 __asm__ (GOSYM_PREFIX "sync_atomic.CompareAndSwapPointer");
60 CompareAndSwapPointer (void **val, void *old, void *new)
62 return __sync_bool_compare_and_swap (val, old, new);
65 int32_t AddInt32 (int32_t *, int32_t)
66 __asm__ (GOSYM_PREFIX "sync_atomic.AddInt32");
69 AddInt32 (int32_t *val, int32_t delta)
71 return __sync_add_and_fetch (val, delta);
74 uint32_t AddUint32 (uint32_t *, uint32_t)
75 __asm__ (GOSYM_PREFIX "sync_atomic.AddUint32");
78 AddUint32 (uint32_t *val, uint32_t delta)
80 return __sync_add_and_fetch (val, delta);
83 int64_t AddInt64 (int64_t *, int64_t)
84 __asm__ (GOSYM_PREFIX "sync_atomic.AddInt64");
87 AddInt64 (int64_t *val, int64_t delta)
89 return __sync_add_and_fetch (val, delta);
92 uint64_t AddUint64 (uint64_t *, uint64_t)
93 __asm__ (GOSYM_PREFIX "sync_atomic.AddUint64");
96 AddUint64 (uint64_t *val, uint64_t delta)
98 return __sync_add_and_fetch (val, delta);
101 uintptr_t AddUintptr (uintptr_t *, uintptr_t)
102 __asm__ (GOSYM_PREFIX "sync_atomic.AddUintptr");
105 AddUintptr (uintptr_t *val, uintptr_t delta)
107 return __sync_add_and_fetch (val, delta);
110 int32_t LoadInt32 (int32_t *addr)
111 __asm__ (GOSYM_PREFIX "sync_atomic.LoadInt32");
114 LoadInt32 (int32_t *addr)
119 while (! __sync_bool_compare_and_swap (addr, v, v))
124 int64_t LoadInt64 (int64_t *addr)
125 __asm__ (GOSYM_PREFIX "sync_atomic.LoadInt64");
128 LoadInt64 (int64_t *addr)
133 while (! __sync_bool_compare_and_swap (addr, v, v))
138 uint32_t LoadUint32 (uint32_t *addr)
139 __asm__ (GOSYM_PREFIX "sync_atomic.LoadUint32");
142 LoadUint32 (uint32_t *addr)
147 while (! __sync_bool_compare_and_swap (addr, v, v))
152 uint64_t LoadUint64 (uint64_t *addr)
153 __asm__ (GOSYM_PREFIX "sync_atomic.LoadUint64");
156 LoadUint64 (uint64_t *addr)
161 while (! __sync_bool_compare_and_swap (addr, v, v))
166 uintptr_t LoadUintptr (uintptr_t *addr)
167 __asm__ (GOSYM_PREFIX "sync_atomic.LoadUintptr");
170 LoadUintptr (uintptr_t *addr)
175 while (! __sync_bool_compare_and_swap (addr, v, v))
180 void *LoadPointer (void **addr)
181 __asm__ (GOSYM_PREFIX "sync_atomic.LoadPointer");
184 LoadPointer (void **addr)
189 while (! __sync_bool_compare_and_swap (addr, v, v))
194 void StoreInt32 (int32_t *addr, int32_t val)
195 __asm__ (GOSYM_PREFIX "sync_atomic.StoreInt32");
198 StoreInt32 (int32_t *addr, int32_t val)
203 while (! __sync_bool_compare_and_swap (addr, v, val))
207 void StoreInt64 (int64_t *addr, int64_t val)
208 __asm__ (GOSYM_PREFIX "sync_atomic.StoreInt64");
211 StoreInt64 (int64_t *addr, int64_t val)
216 while (! __sync_bool_compare_and_swap (addr, v, val))
220 void StoreUint32 (uint32_t *addr, uint32_t val)
221 __asm__ (GOSYM_PREFIX "sync_atomic.StoreUint32");
224 StoreUint32 (uint32_t *addr, uint32_t val)
229 while (! __sync_bool_compare_and_swap (addr, v, val))
233 void StoreUint64 (uint64_t *addr, uint64_t val)
234 __asm__ (GOSYM_PREFIX "sync_atomic.StoreUint64");
237 StoreUint64 (uint64_t *addr, uint64_t val)
242 while (! __sync_bool_compare_and_swap (addr, v, val))
246 void StoreUintptr (uintptr_t *addr, uintptr_t val)
247 __asm__ (GOSYM_PREFIX "sync_atomic.StoreUintptr");
250 StoreUintptr (uintptr_t *addr, uintptr_t val)
255 while (! __sync_bool_compare_and_swap (addr, v, val))
259 void StorePointer (void **addr, void *val)
260 __asm__ (GOSYM_PREFIX "sync_atomic.StorePointer");
263 StorePointer (void **addr, void *val)
268 while (! __sync_bool_compare_and_swap (addr, v, val))