Line data Source code
1 : /*
2 : * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
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 :
11 : #include "webrtc/system_wrappers/include/atomic32.h"
12 :
13 : #include <assert.h>
14 : #include <inttypes.h>
15 :
16 : #include "webrtc/common_types.h"
17 :
18 : namespace webrtc {
19 :
20 0 : Atomic32::Atomic32(int32_t initial_value)
21 0 : : value_(initial_value) {
22 0 : assert(Is32bitAligned());
23 0 : }
24 :
25 0 : Atomic32::~Atomic32() {
26 0 : }
27 :
28 0 : int32_t Atomic32::operator++() {
29 0 : return __sync_fetch_and_add(&value_, 1) + 1;
30 : }
31 :
32 0 : int32_t Atomic32::operator--() {
33 0 : return __sync_fetch_and_sub(&value_, 1) - 1;
34 : }
35 :
36 0 : int32_t Atomic32::operator+=(int32_t value) {
37 0 : int32_t return_value = __sync_fetch_and_add(&value_, value);
38 0 : return_value += value;
39 0 : return return_value;
40 : }
41 :
42 0 : int32_t Atomic32::operator-=(int32_t value) {
43 0 : int32_t return_value = __sync_fetch_and_sub(&value_, value);
44 0 : return_value -= value;
45 0 : return return_value;
46 : }
47 :
48 0 : bool Atomic32::CompareExchange(int32_t new_value, int32_t compare_value) {
49 0 : return __sync_bool_compare_and_swap(&value_, compare_value, new_value);
50 : }
51 :
52 : } // namespace webrtc
|