diff options
Diffstat (limited to 'webrtc/base/atomicops.h')
-rw-r--r-- | webrtc/base/atomicops.h | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/webrtc/base/atomicops.h b/webrtc/base/atomicops.h index a863566a67..a286bf01cc 100644 --- a/webrtc/base/atomicops.h +++ b/webrtc/base/atomicops.h @@ -42,6 +42,16 @@ class AtomicOps { new_value, old_value); } + // Pointer variants. + template <typename T> + static T* AcquireLoadPtr(T* volatile* ptr) { + return *ptr; + } + template <typename T> + static T* CompareAndSwapPtr(T* volatile* ptr, T* old_value, T* new_value) { + return static_cast<T*>(::InterlockedCompareExchangePointer( + reinterpret_cast<PVOID volatile*>(ptr), new_value, old_value)); + } #else static int Increment(volatile int* i) { return __sync_add_and_fetch(i, 1); @@ -58,6 +68,15 @@ class AtomicOps { static int CompareAndSwap(volatile int* i, int old_value, int new_value) { return __sync_val_compare_and_swap(i, old_value, new_value); } + // Pointer variants. + template <typename T> + static T* AcquireLoadPtr(T* volatile* ptr) { + return __atomic_load_n(ptr, __ATOMIC_ACQUIRE); + } + template <typename T> + static T* CompareAndSwapPtr(T* volatile* ptr, T* old_value, T* new_value) { + return __sync_val_compare_and_swap(ptr, old_value, new_value); + } #endif }; |