OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // This file is an internal atomic implementation, include base/atomicops.h | 5 // This file is an internal atomic implementation, include base/atomicops.h |
6 // instead. This file is for platforms that use GCC intrinsics rather than | 6 // instead. This file is for platforms that use GCC intrinsics rather than |
7 // platform-specific assembly code for atomic operations. | 7 // platform-specific assembly code for atomic operations. |
8 | 8 |
9 #ifndef BASE_ATOMICOPS_INTERNALS_GCC_H_ | 9 #ifndef BASE_ATOMICOPS_INTERNALS_GCC_H_ |
10 #define BASE_ATOMICOPS_INTERNALS_GCC_H_ | 10 #define BASE_ATOMICOPS_INTERNALS_GCC_H_ |
11 | 11 |
12 namespace base { | 12 namespace base { |
13 namespace subtle { | 13 namespace subtle { |
14 | 14 |
15 inline Atomic32 NoBarrier_CompareAndSwap(volatile Atomic32* ptr, | 15 inline Atomic32 NoBarrier_CompareAndSwap(volatile Atomic32* ptr, |
16 Atomic32 old_value, | 16 Atomic32 old_value, |
17 Atomic32 new_value) { | 17 Atomic32 new_value) { |
18 Atomic32 prev_value; | 18 Atomic32 prev_value; |
19 do { | 19 do { |
20 prev_value = __sync_val_compare_and_swap(ptr, old_value, new_value); | 20 if (__sync_bool_compare_and_swap(ptr, old_value, new_value)) |
21 } while (prev_value != old_value); | 21 return old_value; |
22 return old_value; | 22 prev_value = *ptr; |
| 23 } while (prev_value == old_value); |
| 24 return prev_value; |
23 } | 25 } |
24 | 26 |
25 inline Atomic32 NoBarrier_AtomicExchange(volatile Atomic32* ptr, | 27 inline Atomic32 NoBarrier_AtomicExchange(volatile Atomic32* ptr, |
26 Atomic32 new_value) { | 28 Atomic32 new_value) { |
27 Atomic32 old_value; | 29 Atomic32 old_value; |
28 do { | 30 do { |
29 old_value = *ptr; | 31 old_value = *ptr; |
30 } while (!__sync_bool_compare_and_swap(ptr, old_value, new_value)); | 32 } while (!__sync_bool_compare_and_swap(ptr, old_value, new_value)); |
31 return old_value; | 33 return old_value; |
32 } | 34 } |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 inline Atomic32 Release_Load(volatile const Atomic32* ptr) { | 97 inline Atomic32 Release_Load(volatile const Atomic32* ptr) { |
96 MemoryBarrier(); | 98 MemoryBarrier(); |
97 return *ptr; | 99 return *ptr; |
98 } | 100 } |
99 | 101 |
100 } // namespace base::subtle | 102 } // namespace base::subtle |
101 } // namespace base | 103 } // namespace base |
102 | 104 |
103 #endif // BASE_ATOMICOPS_INTERNALS_GCC_H_ | 105 #endif // BASE_ATOMICOPS_INTERNALS_GCC_H_ |
104 | 106 |
OLD | NEW |