PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/third_party/gofrontend/libgo/go/sync/atomic/atomic.c

http://github.com/axw/llgo
C | 353 lines | 276 code | 72 blank | 5 comment | 12 complexity | d84813f4138c1c250bc493aaa621a176 MD5 | raw file
Possible License(s): BSD-3-Clause, MIT
  1. /* atomic.c -- implement atomic routines for Go.
  2. Copyright 2011 The Go Authors. All rights reserved.
  3. Use of this source code is governed by a BSD-style
  4. license that can be found in the LICENSE file. */
  5. #include <stdint.h>
  6. #include "runtime.h"
  7. int32_t SwapInt32 (int32_t *, int32_t)
  8. __asm__ (GOSYM_PREFIX "sync_atomic.SwapInt32")
  9. __attribute__ ((no_split_stack));
  10. int32_t
  11. SwapInt32 (int32_t *addr, int32_t new)
  12. {
  13. return __atomic_exchange_n (addr, new, __ATOMIC_SEQ_CST);
  14. }
  15. int64_t SwapInt64 (int64_t *, int64_t)
  16. __asm__ (GOSYM_PREFIX "sync_atomic.SwapInt64")
  17. __attribute__ ((no_split_stack));
  18. int64_t
  19. SwapInt64 (int64_t *addr, int64_t new)
  20. {
  21. return __atomic_exchange_n (addr, new, __ATOMIC_SEQ_CST);
  22. }
  23. uint32_t SwapUint32 (uint32_t *, uint32_t)
  24. __asm__ (GOSYM_PREFIX "sync_atomic.SwapUint32")
  25. __attribute__ ((no_split_stack));
  26. uint32_t
  27. SwapUint32 (uint32_t *addr, uint32_t new)
  28. {
  29. return __atomic_exchange_n (addr, new, __ATOMIC_SEQ_CST);
  30. }
  31. uint64_t SwapUint64 (uint64_t *, uint64_t)
  32. __asm__ (GOSYM_PREFIX "sync_atomic.SwapUint64")
  33. __attribute__ ((no_split_stack));
  34. uint64_t
  35. SwapUint64 (uint64_t *addr, uint64_t new)
  36. {
  37. return __atomic_exchange_n (addr, new, __ATOMIC_SEQ_CST);
  38. }
  39. uintptr_t SwapUintptr (uintptr_t *, uintptr_t)
  40. __asm__ (GOSYM_PREFIX "sync_atomic.SwapUintptr")
  41. __attribute__ ((no_split_stack));
  42. uintptr_t
  43. SwapUintptr (uintptr_t *addr, uintptr_t new)
  44. {
  45. return __atomic_exchange_n (addr, new, __ATOMIC_SEQ_CST);
  46. }
  47. void *SwapPointer (void **, void *)
  48. __asm__ (GOSYM_PREFIX "sync_atomic.SwapPointer")
  49. __attribute__ ((no_split_stack));
  50. void *
  51. SwapPointer (void **addr, void *new)
  52. {
  53. return __atomic_exchange_n (addr, new, __ATOMIC_SEQ_CST);
  54. }
  55. _Bool CompareAndSwapInt32 (int32_t *, int32_t, int32_t)
  56. __asm__ (GOSYM_PREFIX "sync_atomic.CompareAndSwapInt32")
  57. __attribute__ ((no_split_stack));
  58. _Bool
  59. CompareAndSwapInt32 (int32_t *val, int32_t old, int32_t new)
  60. {
  61. return __sync_bool_compare_and_swap (val, old, new);
  62. }
  63. _Bool CompareAndSwapInt64 (int64_t *, int64_t, int64_t)
  64. __asm__ (GOSYM_PREFIX "sync_atomic.CompareAndSwapInt64")
  65. __attribute__ ((no_split_stack));
  66. _Bool
  67. CompareAndSwapInt64 (int64_t *val, int64_t old, int64_t new)
  68. {
  69. return __sync_bool_compare_and_swap (val, old, new);
  70. }
  71. _Bool CompareAndSwapUint32 (uint32_t *, uint32_t, uint32_t)
  72. __asm__ (GOSYM_PREFIX "sync_atomic.CompareAndSwapUint32")
  73. __attribute__ ((no_split_stack));
  74. _Bool
  75. CompareAndSwapUint32 (uint32_t *val, uint32_t old, uint32_t new)
  76. {
  77. return __sync_bool_compare_and_swap (val, old, new);
  78. }
  79. _Bool CompareAndSwapUint64 (uint64_t *, uint64_t, uint64_t)
  80. __asm__ (GOSYM_PREFIX "sync_atomic.CompareAndSwapUint64")
  81. __attribute__ ((no_split_stack));
  82. _Bool
  83. CompareAndSwapUint64 (uint64_t *val, uint64_t old, uint64_t new)
  84. {
  85. return __sync_bool_compare_and_swap (val, old, new);
  86. }
  87. _Bool CompareAndSwapUintptr (uintptr_t *, uintptr_t, uintptr_t)
  88. __asm__ (GOSYM_PREFIX "sync_atomic.CompareAndSwapUintptr")
  89. __attribute__ ((no_split_stack));
  90. _Bool
  91. CompareAndSwapUintptr (uintptr_t *val, uintptr_t old, uintptr_t new)
  92. {
  93. return __sync_bool_compare_and_swap (val, old, new);
  94. }
  95. _Bool CompareAndSwapPointer (void **, void *, void *)
  96. __asm__ (GOSYM_PREFIX "sync_atomic.CompareAndSwapPointer")
  97. __attribute__ ((no_split_stack));
  98. _Bool
  99. CompareAndSwapPointer (void **val, void *old, void *new)
  100. {
  101. return __sync_bool_compare_and_swap (val, old, new);
  102. }
  103. int32_t AddInt32 (int32_t *, int32_t)
  104. __asm__ (GOSYM_PREFIX "sync_atomic.AddInt32")
  105. __attribute__ ((no_split_stack));
  106. int32_t
  107. AddInt32 (int32_t *val, int32_t delta)
  108. {
  109. return __sync_add_and_fetch (val, delta);
  110. }
  111. uint32_t AddUint32 (uint32_t *, uint32_t)
  112. __asm__ (GOSYM_PREFIX "sync_atomic.AddUint32")
  113. __attribute__ ((no_split_stack));
  114. uint32_t
  115. AddUint32 (uint32_t *val, uint32_t delta)
  116. {
  117. return __sync_add_and_fetch (val, delta);
  118. }
  119. int64_t AddInt64 (int64_t *, int64_t)
  120. __asm__ (GOSYM_PREFIX "sync_atomic.AddInt64")
  121. __attribute__ ((no_split_stack));
  122. int64_t
  123. AddInt64 (int64_t *val, int64_t delta)
  124. {
  125. return __sync_add_and_fetch (val, delta);
  126. }
  127. uint64_t AddUint64 (uint64_t *, uint64_t)
  128. __asm__ (GOSYM_PREFIX "sync_atomic.AddUint64")
  129. __attribute__ ((no_split_stack));
  130. uint64_t
  131. AddUint64 (uint64_t *val, uint64_t delta)
  132. {
  133. return __sync_add_and_fetch (val, delta);
  134. }
  135. uintptr_t AddUintptr (uintptr_t *, uintptr_t)
  136. __asm__ (GOSYM_PREFIX "sync_atomic.AddUintptr")
  137. __attribute__ ((no_split_stack));
  138. uintptr_t
  139. AddUintptr (uintptr_t *val, uintptr_t delta)
  140. {
  141. return __sync_add_and_fetch (val, delta);
  142. }
  143. int32_t LoadInt32 (int32_t *addr)
  144. __asm__ (GOSYM_PREFIX "sync_atomic.LoadInt32")
  145. __attribute__ ((no_split_stack));
  146. int32_t
  147. LoadInt32 (int32_t *addr)
  148. {
  149. int32_t v;
  150. v = *addr;
  151. while (! __sync_bool_compare_and_swap (addr, v, v))
  152. v = *addr;
  153. return v;
  154. }
  155. int64_t LoadInt64 (int64_t *addr)
  156. __asm__ (GOSYM_PREFIX "sync_atomic.LoadInt64")
  157. __attribute__ ((no_split_stack));
  158. int64_t
  159. LoadInt64 (int64_t *addr)
  160. {
  161. int64_t v;
  162. v = *addr;
  163. while (! __sync_bool_compare_and_swap (addr, v, v))
  164. v = *addr;
  165. return v;
  166. }
  167. uint32_t LoadUint32 (uint32_t *addr)
  168. __asm__ (GOSYM_PREFIX "sync_atomic.LoadUint32")
  169. __attribute__ ((no_split_stack));
  170. uint32_t
  171. LoadUint32 (uint32_t *addr)
  172. {
  173. uint32_t v;
  174. v = *addr;
  175. while (! __sync_bool_compare_and_swap (addr, v, v))
  176. v = *addr;
  177. return v;
  178. }
  179. uint64_t LoadUint64 (uint64_t *addr)
  180. __asm__ (GOSYM_PREFIX "sync_atomic.LoadUint64")
  181. __attribute__ ((no_split_stack));
  182. uint64_t
  183. LoadUint64 (uint64_t *addr)
  184. {
  185. uint64_t v;
  186. v = *addr;
  187. while (! __sync_bool_compare_and_swap (addr, v, v))
  188. v = *addr;
  189. return v;
  190. }
  191. uintptr_t LoadUintptr (uintptr_t *addr)
  192. __asm__ (GOSYM_PREFIX "sync_atomic.LoadUintptr")
  193. __attribute__ ((no_split_stack));
  194. uintptr_t
  195. LoadUintptr (uintptr_t *addr)
  196. {
  197. uintptr_t v;
  198. v = *addr;
  199. while (! __sync_bool_compare_and_swap (addr, v, v))
  200. v = *addr;
  201. return v;
  202. }
  203. void *LoadPointer (void **addr)
  204. __asm__ (GOSYM_PREFIX "sync_atomic.LoadPointer")
  205. __attribute__ ((no_split_stack));
  206. void *
  207. LoadPointer (void **addr)
  208. {
  209. void *v;
  210. v = *addr;
  211. while (! __sync_bool_compare_and_swap (addr, v, v))
  212. v = *addr;
  213. return v;
  214. }
  215. void StoreInt32 (int32_t *addr, int32_t val)
  216. __asm__ (GOSYM_PREFIX "sync_atomic.StoreInt32")
  217. __attribute__ ((no_split_stack));
  218. void
  219. StoreInt32 (int32_t *addr, int32_t val)
  220. {
  221. int32_t v;
  222. v = *addr;
  223. while (! __sync_bool_compare_and_swap (addr, v, val))
  224. v = *addr;
  225. }
  226. void StoreInt64 (int64_t *addr, int64_t val)
  227. __asm__ (GOSYM_PREFIX "sync_atomic.StoreInt64")
  228. __attribute__ ((no_split_stack));
  229. void
  230. StoreInt64 (int64_t *addr, int64_t val)
  231. {
  232. int64_t v;
  233. v = *addr;
  234. while (! __sync_bool_compare_and_swap (addr, v, val))
  235. v = *addr;
  236. }
  237. void StoreUint32 (uint32_t *addr, uint32_t val)
  238. __asm__ (GOSYM_PREFIX "sync_atomic.StoreUint32")
  239. __attribute__ ((no_split_stack));
  240. void
  241. StoreUint32 (uint32_t *addr, uint32_t val)
  242. {
  243. uint32_t v;
  244. v = *addr;
  245. while (! __sync_bool_compare_and_swap (addr, v, val))
  246. v = *addr;
  247. }
  248. void StoreUint64 (uint64_t *addr, uint64_t val)
  249. __asm__ (GOSYM_PREFIX "sync_atomic.StoreUint64")
  250. __attribute__ ((no_split_stack));
  251. void
  252. StoreUint64 (uint64_t *addr, uint64_t val)
  253. {
  254. uint64_t v;
  255. v = *addr;
  256. while (! __sync_bool_compare_and_swap (addr, v, val))
  257. v = *addr;
  258. }
  259. void StoreUintptr (uintptr_t *addr, uintptr_t val)
  260. __asm__ (GOSYM_PREFIX "sync_atomic.StoreUintptr")
  261. __attribute__ ((no_split_stack));
  262. void
  263. StoreUintptr (uintptr_t *addr, uintptr_t val)
  264. {
  265. uintptr_t v;
  266. v = *addr;
  267. while (! __sync_bool_compare_and_swap (addr, v, val))
  268. v = *addr;
  269. }
  270. void StorePointer (void **addr, void *val)
  271. __asm__ (GOSYM_PREFIX "sync_atomic.StorePointer")
  272. __attribute__ ((no_split_stack));
  273. void
  274. StorePointer (void **addr, void *val)
  275. {
  276. void *v;
  277. v = *addr;
  278. while (! __sync_bool_compare_and_swap (addr, v, val))
  279. v = *addr;
  280. }