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

Side by Side Diff: webrtc/base/atomicops.h

Issue 1246073002: Implement store as an explicit atomic operation. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: s/Increment/ReleaseStore Created 5 years, 5 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 | webrtc/base/refcount.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2011 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 13 matching lines...) Expand all
24 class AtomicOps { 24 class AtomicOps {
25 public: 25 public:
26 #if defined(WEBRTC_WIN) 26 #if defined(WEBRTC_WIN)
27 // Assumes sizeof(int) == sizeof(LONG), which it is on Win32 and Win64. 27 // Assumes sizeof(int) == sizeof(LONG), which it is on Win32 and Win64.
28 static int Increment(volatile int* i) { 28 static int Increment(volatile int* i) {
29 return ::InterlockedIncrement(reinterpret_cast<volatile LONG*>(i)); 29 return ::InterlockedIncrement(reinterpret_cast<volatile LONG*>(i));
30 } 30 }
31 static int Decrement(volatile int* i) { 31 static int Decrement(volatile int* i) {
32 return ::InterlockedDecrement(reinterpret_cast<volatile LONG*>(i)); 32 return ::InterlockedDecrement(reinterpret_cast<volatile LONG*>(i));
33 } 33 }
34 static int Load(volatile const int* i) { 34 static int AcquireLoad(volatile const int* i) {
35 return *i; 35 return *i;
36 } 36 }
37 static void Store(volatile int* i, int value) { 37 static void ReleaseStore(volatile int* i, int value) {
38 *i = value; 38 *i = value;
39 } 39 }
40 static int CompareAndSwap(volatile int* i, int old_value, int new_value) { 40 static int CompareAndSwap(volatile int* i, int old_value, int new_value) {
41 return ::InterlockedCompareExchange(reinterpret_cast<volatile LONG*>(i), 41 return ::InterlockedCompareExchange(reinterpret_cast<volatile LONG*>(i),
42 new_value, 42 new_value,
43 old_value); 43 old_value);
44 } 44 }
45 #else 45 #else
46 static int Increment(volatile int* i) { 46 static int Increment(volatile int* i) {
47 return __sync_add_and_fetch(i, 1); 47 return __sync_add_and_fetch(i, 1);
48 } 48 }
49 static int Decrement(volatile int* i) { 49 static int Decrement(volatile int* i) {
50 return __sync_sub_and_fetch(i, 1); 50 return __sync_sub_and_fetch(i, 1);
51 } 51 }
52 static int Load(volatile const int* i) { 52 static int AcquireLoad(volatile const int* i) {
53 // Adding 0 is a no-op, so const_cast is fine. 53 return __atomic_load_n(i, __ATOMIC_ACQUIRE);
54 return __sync_add_and_fetch(const_cast<volatile int*>(i), 0);
55 } 54 }
56 static void Store(volatile int* i, int value) { 55 static void ReleaseStore(volatile int* i, int value) {
57 __sync_synchronize(); 56 __atomic_store_n(i, value, __ATOMIC_RELEASE);
58 *i = value;
59 } 57 }
60 static int CompareAndSwap(volatile int* i, int old_value, int new_value) { 58 static int CompareAndSwap(volatile int* i, int old_value, int new_value) {
61 return __sync_val_compare_and_swap(i, old_value, new_value); 59 return __sync_val_compare_and_swap(i, old_value, new_value);
62 } 60 }
63 #endif 61 #endif
64 }; 62 };
65 63
66 64
67 65
68 } 66 }
69 67
70 #endif // WEBRTC_BASE_ATOMICOPS_H_ 68 #endif // WEBRTC_BASE_ATOMICOPS_H_
OLDNEW
« no previous file with comments | « no previous file | webrtc/base/refcount.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698