From 9cb9fc17b1e9484f7628eddfa8b23b3a7ff8b0da Mon Sep 17 00:00:00 2001 From: "phoglund@webrtc.org" Date: Fri, 9 Nov 2012 08:57:25 +0000 Subject: [PATCH] Reformatted atomic32 files. BUG= Review URL: https://webrtc-codereview.appspot.com/937016 git-svn-id: http://webrtc.googlecode.com/svn/trunk@3067 4adac7df-926f-26a2-2b94-8c16560cd09d --- webrtc/system_wrappers/interface/atomic32.h | 52 +++++++------- webrtc/system_wrappers/source/atomic32_mac.cc | 42 +++++------- .../system_wrappers/source/atomic32_posix.cc | 50 ++++++-------- webrtc/system_wrappers/source/atomic32_win.cc | 67 +++++++++---------- 4 files changed, 97 insertions(+), 114 deletions(-) diff --git a/webrtc/system_wrappers/interface/atomic32.h b/webrtc/system_wrappers/interface/atomic32.h index e2b12589d..2e9865df9 100644 --- a/webrtc/system_wrappers/interface/atomic32.h +++ b/webrtc/system_wrappers/interface/atomic32.h @@ -27,39 +27,39 @@ namespace webrtc { // align the 32 bit value correctly (on a 32 bit boundary), so as long as you're // not doing things like reinterpret_cast over some custom allocated memory // without being careful with alignment, you should be fine. -class Atomic32 -{ -public: - Atomic32(WebRtc_Word32 initialValue = 0); - ~Atomic32(); +class Atomic32 { + public: + Atomic32(WebRtc_Word32 initial_value = 0); + ~Atomic32(); - // Prefix operator! - WebRtc_Word32 operator++(); - WebRtc_Word32 operator--(); + // Prefix operator! + WebRtc_Word32 operator++(); + WebRtc_Word32 operator--(); - WebRtc_Word32 operator+=(WebRtc_Word32 value); - WebRtc_Word32 operator-=(WebRtc_Word32 value); + WebRtc_Word32 operator+=(WebRtc_Word32 value); + WebRtc_Word32 operator-=(WebRtc_Word32 value); - // Sets the value atomically to newValue if the value equals compare value. - // The function returns true if the exchange happened. - bool CompareExchange(WebRtc_Word32 newValue, WebRtc_Word32 compareValue); - WebRtc_Word32 Value() const; + // Sets the value atomically to new_value if the value equals compare value. + // The function returns true if the exchange happened. + bool CompareExchange(WebRtc_Word32 new_value, WebRtc_Word32 compare_value); + WebRtc_Word32 Value() const; -private: - // Disable the + and - operator since it's unclear what these operations - // should do. - Atomic32 operator+(const Atomic32& other); - Atomic32 operator-(const Atomic32& other); + private: + // Disable the + and - operator since it's unclear what these operations + // should do. + Atomic32 operator+(const Atomic32& other); + Atomic32 operator-(const Atomic32& other); - // Checks if |_value| is 32bit aligned. - inline bool Is32bitAligned() const { - return (reinterpret_cast(&_value) & 3) == 0; - } + // Checks if |_value| is 32bit aligned. + inline bool Is32bitAligned() const { + return (reinterpret_cast(&value_) & 3) == 0; + } - DISALLOW_COPY_AND_ASSIGN(Atomic32); + DISALLOW_COPY_AND_ASSIGN(Atomic32); - WebRtc_Word32 _value; + WebRtc_Word32 value_; }; + } // namespace webrtc -#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_ATOMIC32_H_ +#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_ATOMIC32_H_ diff --git a/webrtc/system_wrappers/source/atomic32_mac.cc b/webrtc/system_wrappers/source/atomic32_mac.cc index 9a493b580..d816e19b3 100644 --- a/webrtc/system_wrappers/source/atomic32_mac.cc +++ b/webrtc/system_wrappers/source/atomic32_mac.cc @@ -18,43 +18,37 @@ namespace webrtc { -Atomic32::Atomic32(WebRtc_Word32 initialValue) : _value(initialValue) -{ - assert(Is32bitAligned()); +Atomic32::Atomic32(WebRtc_Word32 initial_value) + : value_(initial_value) { + assert(Is32bitAligned()); } -Atomic32::~Atomic32() -{ +Atomic32::~Atomic32() { } -WebRtc_Word32 Atomic32::operator++() -{ - return OSAtomicIncrement32Barrier(&_value); +WebRtc_Word32 Atomic32::operator++() { + return OSAtomicIncrement32Barrier(&value_); } -WebRtc_Word32 Atomic32::operator--() -{ - return OSAtomicDecrement32Barrier(&_value); +WebRtc_Word32 Atomic32::operator--() { + return OSAtomicDecrement32Barrier(&value_); } -WebRtc_Word32 Atomic32::operator+=(WebRtc_Word32 value) -{ - return OSAtomicAdd32Barrier(value, &_value); +WebRtc_Word32 Atomic32::operator+=(WebRtc_Word32 value) { + return OSAtomicAdd32Barrier(value, &value_); } -WebRtc_Word32 Atomic32::operator-=(WebRtc_Word32 value) -{ - return OSAtomicAdd32Barrier(-value, &_value); +WebRtc_Word32 Atomic32::operator-=(WebRtc_Word32 value) { + return OSAtomicAdd32Barrier(-value, &value_); } -bool Atomic32::CompareExchange(WebRtc_Word32 newValue, - WebRtc_Word32 compareValue) -{ - return OSAtomicCompareAndSwap32Barrier(compareValue, newValue, &_value); +bool Atomic32::CompareExchange(WebRtc_Word32 new_value, + WebRtc_Word32 compare_value) { + return OSAtomicCompareAndSwap32Barrier(compare_value, new_value, &value_); } -WebRtc_Word32 Atomic32::Value() const -{ - return _value; +WebRtc_Word32 Atomic32::Value() const { + return value_; } + } // namespace webrtc diff --git a/webrtc/system_wrappers/source/atomic32_posix.cc b/webrtc/system_wrappers/source/atomic32_posix.cc index 05b0e5745..8a52617ef 100644 --- a/webrtc/system_wrappers/source/atomic32_posix.cc +++ b/webrtc/system_wrappers/source/atomic32_posix.cc @@ -18,47 +18,41 @@ namespace webrtc { -Atomic32::Atomic32(WebRtc_Word32 initialValue) : _value(initialValue) -{ - assert(Is32bitAligned()); +Atomic32::Atomic32(WebRtc_Word32 initial_value) + : value_(initial_value) { + assert(Is32bitAligned()); } -Atomic32::~Atomic32() -{ +Atomic32::~Atomic32() { } -WebRtc_Word32 Atomic32::operator++() -{ - return __sync_fetch_and_add(&_value, 1) + 1; +WebRtc_Word32 Atomic32::operator++() { + return __sync_fetch_and_add(&value_, 1) + 1; } -WebRtc_Word32 Atomic32::operator--() -{ - return __sync_fetch_and_sub(&_value, 1) - 1; +WebRtc_Word32 Atomic32::operator--() { + return __sync_fetch_and_sub(&value_, 1) - 1; } -WebRtc_Word32 Atomic32::operator+=(WebRtc_Word32 value) -{ - WebRtc_Word32 returnValue = __sync_fetch_and_add(&_value, value); - returnValue += value; - return returnValue; +WebRtc_Word32 Atomic32::operator+=(WebRtc_Word32 value) { + WebRtc_Word32 return_value = __sync_fetch_and_add(&value_, value); + return_value += value; + return return_value; } -WebRtc_Word32 Atomic32::operator-=(WebRtc_Word32 value) -{ - WebRtc_Word32 returnValue = __sync_fetch_and_sub(&_value, value); - returnValue -= value; - return returnValue; +WebRtc_Word32 Atomic32::operator-=(WebRtc_Word32 value) { + WebRtc_Word32 return_value = __sync_fetch_and_sub(&value_, value); + return_value -= value; + return return_value; } -bool Atomic32::CompareExchange(WebRtc_Word32 newValue, - WebRtc_Word32 compareValue) -{ - return __sync_bool_compare_and_swap(&_value, compareValue, newValue); +bool Atomic32::CompareExchange(WebRtc_Word32 new_value, + WebRtc_Word32 compare_value) { + return __sync_bool_compare_and_swap(&value_, compare_value, new_value); } -WebRtc_Word32 Atomic32::Value() const -{ - return _value; +WebRtc_Word32 Atomic32::Value() const { + return value_; } + } // namespace webrtc diff --git a/webrtc/system_wrappers/source/atomic32_win.cc b/webrtc/system_wrappers/source/atomic32_win.cc index 2fa9d3dd5..db16bbd91 100644 --- a/webrtc/system_wrappers/source/atomic32_win.cc +++ b/webrtc/system_wrappers/source/atomic32_win.cc @@ -18,55 +18,50 @@ namespace webrtc { -Atomic32::Atomic32(WebRtc_Word32 initialValue) : _value(initialValue) -{ - // Make sure that the counter variable we're using is of the same size - // as what the API expects. - COMPILE_ASSERT(sizeof(_value) == sizeof(LONG)); - assert(Is32bitAligned()); +Atomic32::Atomic32(WebRtc_Word32 initial_value) + : value_(initial_value) { + // Make sure that the counter variable we're using is of the same size + // as what the API expects. + COMPILE_ASSERT(sizeof(value_) == sizeof(LONG)); + assert(Is32bitAligned()); } -Atomic32::~Atomic32() -{ +Atomic32::~Atomic32() { } -WebRtc_Word32 Atomic32::operator++() -{ - return static_cast(InterlockedIncrement( - reinterpret_cast(&_value))); +WebRtc_Word32 Atomic32::operator++() { + return static_cast(InterlockedIncrement( + reinterpret_cast(&value_))); } -WebRtc_Word32 Atomic32::operator--() -{ - return static_cast(InterlockedDecrement( - reinterpret_cast(&_value))); +WebRtc_Word32 Atomic32::operator--() { + return static_cast(InterlockedDecrement( + reinterpret_cast(&value_))); } -WebRtc_Word32 Atomic32::operator+=(WebRtc_Word32 value) -{ - return InterlockedExchangeAdd(reinterpret_cast(&_value), - value); +WebRtc_Word32 Atomic32::operator+=(WebRtc_Word32 value) { + return InterlockedExchangeAdd(reinterpret_cast(&value_), + value); } -WebRtc_Word32 Atomic32::operator-=(WebRtc_Word32 value) -{ - return InterlockedExchangeAdd(reinterpret_cast(&_value), - -value); +WebRtc_Word32 Atomic32::operator-=(WebRtc_Word32 value) { + return InterlockedExchangeAdd(reinterpret_cast(&value_), + -value); } -bool Atomic32::CompareExchange(WebRtc_Word32 newValue, - WebRtc_Word32 compareValue) -{ - const LONG oldValue = InterlockedCompareExchange( - reinterpret_cast(&_value), - newValue, - compareValue); - // If the old value and the compare value is the same an exchange happened. - return (oldValue == compareValue); +bool Atomic32::CompareExchange(WebRtc_Word32 new_value, + WebRtc_Word32 compare_value) { + const LONG old_value = InterlockedCompareExchange( + reinterpret_cast(&value_), + new_value, + compare_value); + + // If the old value and the compare value is the same an exchange happened. + return (old_value == compare_value); } -WebRtc_Word32 Atomic32::Value() const -{ - return _value; +WebRtc_Word32 Atomic32::Value() const { + return value_; } + } // namespace webrtc