| OLD | NEW |
| 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 26 matching lines...) Expand all Loading... |
| 37 static void ReleaseStore(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 // Pointer variants. | 45 // Pointer variants. |
| 46 template <typename T> | 46 template <typename T> |
| 47 static T* AtomicLoadPtr(T* volatile* ptr) { | 47 static T* AcquireLoadPtr(T* volatile* ptr) { |
| 48 return *ptr; | 48 return *ptr; |
| 49 } | 49 } |
| 50 template <typename T> | 50 template <typename T> |
| 51 static T* CompareAndSwapPtr(T* volatile* ptr, T* old_value, T* new_value) { | 51 static T* CompareAndSwapPtr(T* volatile* ptr, T* old_value, T* new_value) { |
| 52 return static_cast<T*>(::InterlockedCompareExchangePointer( | 52 return static_cast<T*>(::InterlockedCompareExchangePointer( |
| 53 reinterpret_cast<PVOID volatile*>(ptr), old_value, new_value)); | 53 reinterpret_cast<PVOID volatile*>(ptr), new_value, old_value)); |
| 54 } | 54 } |
| 55 #else | 55 #else |
| 56 static int Increment(volatile int* i) { | 56 static int Increment(volatile int* i) { |
| 57 return __sync_add_and_fetch(i, 1); | 57 return __sync_add_and_fetch(i, 1); |
| 58 } | 58 } |
| 59 static int Decrement(volatile int* i) { | 59 static int Decrement(volatile int* i) { |
| 60 return __sync_sub_and_fetch(i, 1); | 60 return __sync_sub_and_fetch(i, 1); |
| 61 } | 61 } |
| 62 static int AcquireLoad(volatile const int* i) { | 62 static int AcquireLoad(volatile const int* i) { |
| 63 return __atomic_load_n(i, __ATOMIC_ACQUIRE); | 63 return __atomic_load_n(i, __ATOMIC_ACQUIRE); |
| 64 } | 64 } |
| 65 static void ReleaseStore(volatile int* i, int value) { | 65 static void ReleaseStore(volatile int* i, int value) { |
| 66 __atomic_store_n(i, value, __ATOMIC_RELEASE); | 66 __atomic_store_n(i, value, __ATOMIC_RELEASE); |
| 67 } | 67 } |
| 68 static int CompareAndSwap(volatile int* i, int old_value, int new_value) { | 68 static int CompareAndSwap(volatile int* i, int old_value, int new_value) { |
| 69 return __sync_val_compare_and_swap(i, old_value, new_value); | 69 return __sync_val_compare_and_swap(i, old_value, new_value); |
| 70 } | 70 } |
| 71 // Pointer variants. | 71 // Pointer variants. |
| 72 template <typename T> | 72 template <typename T> |
| 73 static T* AtomicLoadPtr(T* volatile* ptr) { | 73 static T* AcquireLoadPtr(T* volatile* ptr) { |
| 74 return __atomic_load_n(ptr, __ATOMIC_ACQUIRE); | 74 return __atomic_load_n(ptr, __ATOMIC_ACQUIRE); |
| 75 } | 75 } |
| 76 template <typename T> | 76 template <typename T> |
| 77 static T* CompareAndSwapPtr(T* volatile* ptr, T* old_value, T* new_value) { | 77 static T* CompareAndSwapPtr(T* volatile* ptr, T* old_value, T* new_value) { |
| 78 return __sync_val_compare_and_swap(ptr, old_value, new_value); | 78 return __sync_val_compare_and_swap(ptr, old_value, new_value); |
| 79 } | 79 } |
| 80 #endif | 80 #endif |
| 81 }; | 81 }; |
| 82 | 82 |
| 83 | 83 |
| 84 | 84 |
| 85 } | 85 } |
| 86 | 86 |
| 87 #endif // WEBRTC_BASE_ATOMICOPS_H_ | 87 #endif // WEBRTC_BASE_ATOMICOPS_H_ |
| OLD | NEW |