Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(740)

Side by Side Diff: base/atomicops_internals_mips_gcc.h

Issue 16001009: [MIPS] Fix memory barriers for atomic operations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove no longer used macro. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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, use base/atomicops.h instead. 5 // This file is an internal atomic implementation, use base/atomicops.h instead.
6 // 6 //
7 // LinuxKernelCmpxchg and Barrier_AtomicIncrement are from Google Gears. 7 // LinuxKernelCmpxchg and Barrier_AtomicIncrement are from Google Gears.
8 8
9 #ifndef BASE_ATOMICOPS_INTERNALS_MIPS_GCC_H_ 9 #ifndef BASE_ATOMICOPS_INTERNALS_MIPS_GCC_H_
10 #define BASE_ATOMICOPS_INTERNALS_MIPS_GCC_H_ 10 #define BASE_ATOMICOPS_INTERNALS_MIPS_GCC_H_
11 11
12 #define ATOMICOPS_COMPILER_BARRIER() __asm__ __volatile__("" : : : "memory")
13
14 namespace base { 12 namespace base {
15 namespace subtle { 13 namespace subtle {
16 14
17 // Atomically execute: 15 // Atomically execute:
18 // result = *ptr; 16 // result = *ptr;
19 // if (*ptr == old_value) 17 // if (*ptr == old_value)
20 // *ptr = new_value; 18 // *ptr = new_value;
21 // return result; 19 // return result;
22 // 20 //
23 // I.e., replace "*ptr" with "new_value" if "*ptr" used to be "old_value". 21 // I.e., replace "*ptr" with "new_value" if "*ptr" used to be "old_value".
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 ".set pop\n" 81 ".set pop\n"
84 : "=&r" (temp), "=&r" (temp2), "=m" (*ptr) 82 : "=&r" (temp), "=&r" (temp2), "=m" (*ptr)
85 : "Ir" (increment), "m" (*ptr) 83 : "Ir" (increment), "m" (*ptr)
86 : "memory"); 84 : "memory");
87 // temp2 now holds the final value. 85 // temp2 now holds the final value.
88 return temp2; 86 return temp2;
89 } 87 }
90 88
91 inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr, 89 inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr,
92 Atomic32 increment) { 90 Atomic32 increment) {
93 ATOMICOPS_COMPILER_BARRIER(); 91 MemoryBarrier();
94 Atomic32 res = NoBarrier_AtomicIncrement(ptr, increment); 92 Atomic32 res = NoBarrier_AtomicIncrement(ptr, increment);
95 ATOMICOPS_COMPILER_BARRIER(); 93 MemoryBarrier();
96 return res; 94 return res;
97 } 95 }
98 96
99 // "Acquire" operations 97 // "Acquire" operations
100 // ensure that no later memory access can be reordered ahead of the operation. 98 // ensure that no later memory access can be reordered ahead of the operation.
101 // "Release" operations ensure that no previous memory access can be reordered 99 // "Release" operations ensure that no previous memory access can be reordered
102 // after the operation. "Barrier" operations have both "Acquire" and "Release" 100 // after the operation. "Barrier" operations have both "Acquire" and "Release"
103 // semantics. A MemoryBarrier() has "Barrier" semantics, but does no memory 101 // semantics. A MemoryBarrier() has "Barrier" semantics, but does no memory
104 // access. 102 // access.
105 inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr, 103 inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr,
106 Atomic32 old_value, 104 Atomic32 old_value,
107 Atomic32 new_value) { 105 Atomic32 new_value) {
108 ATOMICOPS_COMPILER_BARRIER();
109 Atomic32 res = NoBarrier_CompareAndSwap(ptr, old_value, new_value); 106 Atomic32 res = NoBarrier_CompareAndSwap(ptr, old_value, new_value);
110 ATOMICOPS_COMPILER_BARRIER(); 107 MemoryBarrier();
111 return res; 108 return res;
112 } 109 }
113 110
114 inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr, 111 inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr,
115 Atomic32 old_value, 112 Atomic32 old_value,
116 Atomic32 new_value) { 113 Atomic32 new_value) {
117 ATOMICOPS_COMPILER_BARRIER(); 114 MemoryBarrier();
118 Atomic32 res = NoBarrier_CompareAndSwap(ptr, old_value, new_value); 115 return NoBarrier_CompareAndSwap(ptr, old_value, new_value);
119 ATOMICOPS_COMPILER_BARRIER();
120 return res;
121 } 116 }
122 117
123 inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) { 118 inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) {
124 *ptr = value; 119 *ptr = value;
125 } 120 }
126 121
127 inline void MemoryBarrier() { 122 inline void MemoryBarrier() {
128 __asm__ __volatile__("sync" : : : "memory"); 123 __asm__ __volatile__("sync" : : : "memory");
129 } 124 }
130 125
(...skipping 18 matching lines...) Expand all
149 } 144 }
150 145
151 inline Atomic32 Release_Load(volatile const Atomic32* ptr) { 146 inline Atomic32 Release_Load(volatile const Atomic32* ptr) {
152 MemoryBarrier(); 147 MemoryBarrier();
153 return *ptr; 148 return *ptr;
154 } 149 }
155 150
156 } // namespace base::subtle 151 } // namespace base::subtle
157 } // namespace base 152 } // namespace base
158 153
159 #undef ATOMICOPS_COMPILER_BARRIER
160
161 #endif // BASE_ATOMICOPS_INTERNALS_MIPS_GCC_H_ 154 #endif // BASE_ATOMICOPS_INTERNALS_MIPS_GCC_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698