2012-04-19 14:28:45 +00:00
|
|
|
/*
|
2017-10-20 15:47:42 -07:00
|
|
|
* Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
|
2012-04-19 14:28:45 +00:00
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "system_wrappers/include/atomic32.h"
|
2012-04-19 14:28:45 +00:00
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
2017-09-15 13:58:09 +02:00
|
|
|
#include "common_types.h" // NOLINT(build/include)
|
2012-04-19 14:28:45 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
2017-10-20 15:47:42 -07:00
|
|
|
Atomic32::Atomic32(int32_t initial_value) : value_(initial_value) {}
|
2012-04-19 14:28:45 +00:00
|
|
|
|
2017-10-20 15:47:42 -07:00
|
|
|
Atomic32::~Atomic32() {}
|
2012-04-19 14:28:45 +00:00
|
|
|
|
2013-04-09 09:06:11 +00:00
|
|
|
int32_t Atomic32::operator++() {
|
2017-10-20 15:47:42 -07:00
|
|
|
return ++value_;
|
2012-04-19 14:28:45 +00:00
|
|
|
}
|
|
|
|
|
|
2013-04-09 09:06:11 +00:00
|
|
|
int32_t Atomic32::operator--() {
|
2017-10-20 15:47:42 -07:00
|
|
|
return --value_;
|
2012-04-19 14:28:45 +00:00
|
|
|
}
|
|
|
|
|
|
2013-04-09 09:06:11 +00:00
|
|
|
int32_t Atomic32::operator+=(int32_t value) {
|
2017-10-20 15:47:42 -07:00
|
|
|
return value_ += value;
|
2012-04-19 14:28:45 +00:00
|
|
|
}
|
|
|
|
|
|
2013-04-09 09:06:11 +00:00
|
|
|
int32_t Atomic32::operator-=(int32_t value) {
|
2017-10-20 15:47:42 -07:00
|
|
|
return value_ -= value;
|
2012-04-19 14:28:45 +00:00
|
|
|
}
|
|
|
|
|
|
2013-04-09 09:06:11 +00:00
|
|
|
bool Atomic32::CompareExchange(int32_t new_value, int32_t compare_value) {
|
2017-10-20 15:47:42 -07:00
|
|
|
return value_.compare_exchange_strong(compare_value, new_value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t Atomic32::Value() const {
|
|
|
|
|
return value_.load();
|
2012-04-19 14:28:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|