1 /* 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. 3 * 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 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #include "atomic32_wrapper.h" 12 13 #if defined(_WIN32) 14 #include "atomic32_win.h" 15 #elif defined(WEBRTC_LINUX) 16 #include "atomic32_linux.h" 17 #elif defined(WEBRTC_MAC) 18 #include "atomic32_mac.h" 19 #else 20 #error unsupported os! 21 #endif 22 23 namespace webrtc { Atomic32Wrapper(WebRtc_Word32 initialValue)24Atomic32Wrapper::Atomic32Wrapper(WebRtc_Word32 initialValue) 25 : _impl(*new Atomic32Impl(initialValue)) 26 { 27 } 28 ~Atomic32Wrapper()29Atomic32Wrapper::~Atomic32Wrapper() 30 { 31 delete &_impl; 32 } 33 operator ++()34WebRtc_Word32 Atomic32Wrapper::operator++() 35 { 36 return ++_impl; 37 } 38 operator --()39WebRtc_Word32 Atomic32Wrapper::operator--() 40 { 41 return --_impl; 42 } 43 44 // Read and write to properly aligned variables are atomic operations. 45 // Ex reference (for Windows): http://msdn.microsoft.com/en-us/library/ms684122(v=VS.85).aspx 46 // TODO (hellner) operator= and Atomic32Wrapper::Value() can be fully 47 // implemented here. operator =(const Atomic32Wrapper & rhs)48Atomic32Wrapper& Atomic32Wrapper::operator=(const Atomic32Wrapper& rhs) 49 { 50 if(this == &rhs) 51 { 52 return *this; 53 } 54 _impl = rhs._impl; 55 return *this; 56 } 57 operator =(WebRtc_Word32 rhs)58Atomic32Wrapper& Atomic32Wrapper::operator=(WebRtc_Word32 rhs) 59 { 60 _impl = rhs; 61 return *this; 62 } 63 operator +=(WebRtc_Word32 rhs)64WebRtc_Word32 Atomic32Wrapper::operator+=(WebRtc_Word32 rhs) 65 { 66 return _impl += rhs; 67 } 68 operator -=(WebRtc_Word32 rhs)69WebRtc_Word32 Atomic32Wrapper::operator-=(WebRtc_Word32 rhs) 70 { 71 return _impl -= rhs; 72 } 73 CompareExchange(WebRtc_Word32 newValue,WebRtc_Word32 compareValue)74bool Atomic32Wrapper::CompareExchange(WebRtc_Word32 newValue, 75 WebRtc_Word32 compareValue) 76 { 77 return _impl.CompareExchange(newValue,compareValue); 78 } 79 Value() const80WebRtc_Word32 Atomic32Wrapper::Value() const 81 { 82 return _impl.Value(); 83 } 84 } // namespace webrtc 85