1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // This file is an internal atomic implementation, use atomicops.h instead.
7 #ifndef V8_BASE_ATOMICOPS_INTERNALS_PORTABLE_H_
8 #define V8_BASE_ATOMICOPS_INTERNALS_PORTABLE_H_
13 inline void MemoryBarrier() { __sync_synchronize(); }
15 inline Atomic32 NoBarrier_CompareAndSwap(volatile Atomic32* ptr,
18 return __sync_val_compare_and_swap(ptr, old_value, new_value);
21 inline Atomic32 NoBarrier_AtomicExchange(volatile Atomic32* ptr,
23 return __sync_lock_test_and_set(ptr, new_value);
26 inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32* ptr,
28 return __sync_add_and_fetch(ptr, increment);
31 inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr,
33 return __sync_add_and_fetch(ptr, increment);
36 inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr,
37 Atomic32 old_value, Atomic32 new_value) {
38 return __sync_val_compare_and_swap(ptr, old_value, new_value);
41 inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr,
42 Atomic32 old_value, Atomic32 new_value) {
43 return __sync_val_compare_and_swap(ptr, old_value, new_value);
46 inline void NoBarrier_Store(volatile Atomic8* ptr, Atomic8 value) {
47 __sync_lock_test_and_set(ptr, value);
50 inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) {
51 __sync_lock_test_and_set(ptr, value);
54 inline void Acquire_Store(volatile Atomic32* ptr, Atomic32 value) {
55 __sync_lock_test_and_set(ptr, value);
58 inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) {
59 __sync_lock_test_and_set(ptr, value);
62 inline Atomic8 NoBarrier_Load(volatile const Atomic8* ptr) {
63 return __sync_add_and_fetch(ptr, 0);
66 inline Atomic32 NoBarrier_Load(volatile const Atomic32* ptr) {
67 return __sync_add_and_fetch(ptr, 0);
70 inline Atomic32 Acquire_Load(volatile const Atomic32* ptr) {
71 return __sync_add_and_fetch(ptr, 0);
74 inline Atomic32 Release_Load(volatile const Atomic32* ptr) {
75 return __sync_add_and_fetch(ptr, 0);
78 // 64-bit versions of the operations.
79 // See the 32-bit versions for comments.
81 inline Atomic64 NoBarrier_CompareAndSwap(volatile Atomic64* ptr,
84 return __sync_val_compare_and_swap(ptr, old_value, new_value);
87 inline Atomic64 NoBarrier_AtomicExchange(volatile Atomic64* ptr,
89 return __sync_lock_test_and_set(ptr, new_value);
92 inline Atomic64 NoBarrier_AtomicIncrement(volatile Atomic64* ptr,
94 return __sync_add_and_fetch(ptr, increment);
97 inline Atomic64 Barrier_AtomicIncrement(volatile Atomic64* ptr,
99 return __sync_add_and_fetch(ptr, increment);
102 inline Atomic64 Acquire_CompareAndSwap(volatile Atomic64* ptr,
103 Atomic64 old_value, Atomic64 new_value) {
104 return __sync_val_compare_and_swap(ptr, old_value, new_value);
107 inline Atomic64 Release_CompareAndSwap(volatile Atomic64* ptr,
108 Atomic64 old_value, Atomic64 new_value) {
109 return __sync_val_compare_and_swap(ptr, old_value, new_value);
112 inline void NoBarrier_Store(volatile Atomic64* ptr, Atomic64 value) {
113 __sync_lock_test_and_set(ptr, value);
116 inline void Acquire_Store(volatile Atomic64* ptr, Atomic64 value) {
117 __sync_lock_test_and_set(ptr, value);
120 inline void Release_Store(volatile Atomic64* ptr, Atomic64 value) {
121 __sync_lock_test_and_set(ptr, value);
124 inline Atomic64 NoBarrier_Load(volatile const Atomic64* ptr) {
125 return __sync_add_and_fetch(ptr, 0);
128 inline Atomic64 Acquire_Load(volatile const Atomic64* ptr) {
129 return __sync_add_and_fetch(ptr, 0);
132 inline Atomic64 Release_Load(volatile const Atomic64* ptr) {
133 return __sync_add_and_fetch(ptr, 0);
136 } // namespace v8::base
138 #endif // V8_BASE_ATOMICOPS_INTERNALS_PORTABLE_H_