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

Side by Side Diff: base/atomicops_internals_nacl.h

Issue 10831358: Fix atomic ops on ARM to compile in NaCl untrusted targets. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « base/atomicops.h ('k') | chrome/nacl.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 // This file is an internal atomic implementation, use base/atomicops.h instead.
6
7 #ifndef BASE_ATOMICOPS_INTERNALS_NACL_H_
8 #define BASE_ATOMICOPS_INTERNALS_NACL_H_
9
10 // For Native Client, use GCC atomic op intrinsics.
bbudge 2012/08/16 20:44:17 This file is a copy of base/atomicops_internals_ar
jar (doing other things) 2012/08/16 22:47:21 You should at a minimum put this comment in the co
Mark Seaborn 2012/08/17 00:08:24 Is there any reason you can't modify the existing
bbudge 2012/08/21 02:02:07 Done. I added conditional expressions to switch be
bbudge 2012/08/21 02:02:07 Since I have no idea what the strange Linux code t
11
12 namespace base {
13 namespace subtle {
14
15 inline Atomic32 NoBarrier_CompareAndSwap(volatile Atomic32* ptr,
16 Atomic32 old_value,
17 Atomic32 new_value) {
18 Atomic32 prev_value = *ptr;
19 do {
20 if (!__sync_val_compare_and_swap(const_cast<Atomic32*>(ptr),
21 old_value, new_value)) {
22 return old_value;
23 }
24 prev_value = *ptr;
25 } while (prev_value == old_value);
26 return prev_value;
27 }
28
29 inline Atomic32 NoBarrier_AtomicExchange(volatile Atomic32* ptr,
30 Atomic32 new_value) {
31 Atomic32 old_value;
32 do {
33 old_value = *ptr;
34 } while (__sync_val_compare_and_swap(const_cast<Atomic32*>(ptr),
35 old_value, new_value));
36 return old_value;
37 }
38
39 inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32* ptr,
40 Atomic32 increment) {
41 return Barrier_AtomicIncrement(ptr, increment);
42 }
43
44 inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr,
45 Atomic32 increment) {
46 for (;;) {
47 // Atomic exchange the old value with an incremented one.
48 Atomic32 old_value = *ptr;
49 Atomic32 new_value = old_value + increment;
50 if (__sync_val_compare_and_swap(const_cast<Atomic32*>(ptr),
51 old_value, new_value) == 0) {
52 // The exchange took place as expected.
53 return new_value;
54 }
55 // Otherwise, *ptr changed mid-loop and we need to retry.
56 }
57
58 }
59
60 inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr,
61 Atomic32 old_value,
62 Atomic32 new_value) {
63 return NoBarrier_CompareAndSwap(ptr, old_value, new_value);
jar (doing other things) 2012/08/16 22:47:21 This was confusing, since Acquire semantics requir
bbudge 2012/08/21 21:49:02 This code is indeed confusing. I succeeded in merg
64 }
65
66 inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr,
67 Atomic32 old_value,
68 Atomic32 new_value) {
69 return NoBarrier_CompareAndSwap(ptr, old_value, new_value);
70 }
71
72 inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) {
73 *ptr = value;
74 }
75
76 inline void MemoryBarrier() {
77 __sync_synchronize();
78 }
79
80 inline void Acquire_Store(volatile Atomic32* ptr, Atomic32 value) {
81 *ptr = value;
82 MemoryBarrier();
83 }
84
85 inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) {
86 MemoryBarrier();
87 *ptr = value;
88 }
89
90 inline Atomic32 NoBarrier_Load(volatile const Atomic32* ptr) {
91 return *ptr;
92 }
93
94 inline Atomic32 Acquire_Load(volatile const Atomic32* ptr) {
95 Atomic32 value = *ptr;
96 MemoryBarrier();
97 return value;
98 }
99
100 inline Atomic32 Release_Load(volatile const Atomic32* ptr) {
101 MemoryBarrier();
102 return *ptr;
103 }
104
105 } // namespace base::subtle
106 } // namespace base
107
108 #endif // BASE_ATOMICOPS_INTERNALS_NACL_H_
OLDNEW
« no previous file with comments | « base/atomicops.h ('k') | chrome/nacl.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698