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
This commit is contained in:
phoglund@webrtc.org 2012-11-09 08:57:25 +00:00
parent fa65c851fe
commit 9cb9fc17b1
4 changed files with 97 additions and 114 deletions

View File

@ -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<ptrdiff_t>(&_value) & 3) == 0;
}
// Checks if |_value| is 32bit aligned.
inline bool Is32bitAligned() const {
return (reinterpret_cast<ptrdiff_t>(&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_

View File

@ -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

View File

@ -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

View File

@ -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<WebRtc_Word32>(InterlockedIncrement(
reinterpret_cast<volatile LONG*>(&_value)));
WebRtc_Word32 Atomic32::operator++() {
return static_cast<WebRtc_Word32>(InterlockedIncrement(
reinterpret_cast<volatile LONG*>(&value_)));
}
WebRtc_Word32 Atomic32::operator--()
{
return static_cast<WebRtc_Word32>(InterlockedDecrement(
reinterpret_cast<volatile LONG*>(&_value)));
WebRtc_Word32 Atomic32::operator--() {
return static_cast<WebRtc_Word32>(InterlockedDecrement(
reinterpret_cast<volatile LONG*>(&value_)));
}
WebRtc_Word32 Atomic32::operator+=(WebRtc_Word32 value)
{
return InterlockedExchangeAdd(reinterpret_cast<volatile LONG*>(&_value),
value);
WebRtc_Word32 Atomic32::operator+=(WebRtc_Word32 value) {
return InterlockedExchangeAdd(reinterpret_cast<volatile LONG*>(&value_),
value);
}
WebRtc_Word32 Atomic32::operator-=(WebRtc_Word32 value)
{
return InterlockedExchangeAdd(reinterpret_cast<volatile LONG*>(&_value),
-value);
WebRtc_Word32 Atomic32::operator-=(WebRtc_Word32 value) {
return InterlockedExchangeAdd(reinterpret_cast<volatile LONG*>(&value_),
-value);
}
bool Atomic32::CompareExchange(WebRtc_Word32 newValue,
WebRtc_Word32 compareValue)
{
const LONG oldValue = InterlockedCompareExchange(
reinterpret_cast<volatile LONG*>(&_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<volatile LONG*>(&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