tommi@webrtc.org | e84373c | 2012-04-19 14:28:45 +0000 | [diff] [blame] | 1 | /* |
Yuwei Huang | 160c020 | 2017-10-20 15:47:42 -0700 | [diff] [blame] | 2 | * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
tommi@webrtc.org | e84373c | 2012-04-19 14:28:45 +0000 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "system_wrappers/include/atomic32.h" |
tommi@webrtc.org | e84373c | 2012-04-19 14:28:45 +0000 | [diff] [blame] | 12 | |
| 13 | #include <assert.h> |
tommi@webrtc.org | e84373c | 2012-04-19 14:28:45 +0000 | [diff] [blame] | 14 | |
Mirko Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame] | 15 | #include "common_types.h" // NOLINT(build/include) |
tommi@webrtc.org | e84373c | 2012-04-19 14:28:45 +0000 | [diff] [blame] | 16 | |
| 17 | namespace webrtc { |
| 18 | |
Yuwei Huang | 160c020 | 2017-10-20 15:47:42 -0700 | [diff] [blame] | 19 | Atomic32::Atomic32(int32_t initial_value) : value_(initial_value) {} |
tommi@webrtc.org | e84373c | 2012-04-19 14:28:45 +0000 | [diff] [blame] | 20 | |
Yuwei Huang | 160c020 | 2017-10-20 15:47:42 -0700 | [diff] [blame] | 21 | Atomic32::~Atomic32() {} |
tommi@webrtc.org | e84373c | 2012-04-19 14:28:45 +0000 | [diff] [blame] | 22 | |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 +0000 | [diff] [blame] | 23 | int32_t Atomic32::operator++() { |
Yuwei Huang | 160c020 | 2017-10-20 15:47:42 -0700 | [diff] [blame] | 24 | return ++value_; |
tommi@webrtc.org | e84373c | 2012-04-19 14:28:45 +0000 | [diff] [blame] | 25 | } |
| 26 | |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 +0000 | [diff] [blame] | 27 | int32_t Atomic32::operator--() { |
Yuwei Huang | 160c020 | 2017-10-20 15:47:42 -0700 | [diff] [blame] | 28 | return --value_; |
tommi@webrtc.org | e84373c | 2012-04-19 14:28:45 +0000 | [diff] [blame] | 29 | } |
| 30 | |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 +0000 | [diff] [blame] | 31 | int32_t Atomic32::operator+=(int32_t value) { |
Yuwei Huang | 160c020 | 2017-10-20 15:47:42 -0700 | [diff] [blame] | 32 | return value_ += value; |
tommi@webrtc.org | e84373c | 2012-04-19 14:28:45 +0000 | [diff] [blame] | 33 | } |
| 34 | |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 +0000 | [diff] [blame] | 35 | int32_t Atomic32::operator-=(int32_t value) { |
Yuwei Huang | 160c020 | 2017-10-20 15:47:42 -0700 | [diff] [blame] | 36 | return value_ -= value; |
tommi@webrtc.org | e84373c | 2012-04-19 14:28:45 +0000 | [diff] [blame] | 37 | } |
| 38 | |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 +0000 | [diff] [blame] | 39 | bool Atomic32::CompareExchange(int32_t new_value, int32_t compare_value) { |
Yuwei Huang | 160c020 | 2017-10-20 15:47:42 -0700 | [diff] [blame] | 40 | return value_.compare_exchange_strong(compare_value, new_value); |
| 41 | } |
| 42 | |
| 43 | int32_t Atomic32::Value() const { |
| 44 | return value_.load(); |
tommi@webrtc.org | e84373c | 2012-04-19 14:28:45 +0000 | [diff] [blame] | 45 | } |
| 46 | |
tommi@webrtc.org | e84373c | 2012-04-19 14:28:45 +0000 | [diff] [blame] | 47 | } // namespace webrtc |