blob: 581c13e0c3f0940ac0057ad7c4a11d7af9a48587 [file] [log] [blame]
tommi@webrtc.orge84373c2012-04-19 14:28:45 +00001/*
Yuwei Huang160c0202017-10-20 15:47:42 -07002 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
tommi@webrtc.orge84373c2012-04-19 14:28:45 +00003 *
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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "system_wrappers/include/atomic32.h"
tommi@webrtc.orge84373c2012-04-19 14:28:45 +000012
13#include <assert.h>
tommi@webrtc.orge84373c2012-04-19 14:28:45 +000014
Mirko Bonadei71207422017-09-15 13:58:09 +020015#include "common_types.h" // NOLINT(build/include)
tommi@webrtc.orge84373c2012-04-19 14:28:45 +000016
17namespace webrtc {
18
Yuwei Huang160c0202017-10-20 15:47:42 -070019Atomic32::Atomic32(int32_t initial_value) : value_(initial_value) {}
tommi@webrtc.orge84373c2012-04-19 14:28:45 +000020
Yuwei Huang160c0202017-10-20 15:47:42 -070021Atomic32::~Atomic32() {}
tommi@webrtc.orge84373c2012-04-19 14:28:45 +000022
pbos@webrtc.org046deb92013-04-09 09:06:11 +000023int32_t Atomic32::operator++() {
Yuwei Huang160c0202017-10-20 15:47:42 -070024 return ++value_;
tommi@webrtc.orge84373c2012-04-19 14:28:45 +000025}
26
pbos@webrtc.org046deb92013-04-09 09:06:11 +000027int32_t Atomic32::operator--() {
Yuwei Huang160c0202017-10-20 15:47:42 -070028 return --value_;
tommi@webrtc.orge84373c2012-04-19 14:28:45 +000029}
30
pbos@webrtc.org046deb92013-04-09 09:06:11 +000031int32_t Atomic32::operator+=(int32_t value) {
Yuwei Huang160c0202017-10-20 15:47:42 -070032 return value_ += value;
tommi@webrtc.orge84373c2012-04-19 14:28:45 +000033}
34
pbos@webrtc.org046deb92013-04-09 09:06:11 +000035int32_t Atomic32::operator-=(int32_t value) {
Yuwei Huang160c0202017-10-20 15:47:42 -070036 return value_ -= value;
tommi@webrtc.orge84373c2012-04-19 14:28:45 +000037}
38
pbos@webrtc.org046deb92013-04-09 09:06:11 +000039bool Atomic32::CompareExchange(int32_t new_value, int32_t compare_value) {
Yuwei Huang160c0202017-10-20 15:47:42 -070040 return value_.compare_exchange_strong(compare_value, new_value);
41}
42
43int32_t Atomic32::Value() const {
44 return value_.load();
tommi@webrtc.orge84373c2012-04-19 14:28:45 +000045}
46
tommi@webrtc.orge84373c2012-04-19 14:28:45 +000047} // namespace webrtc