• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "atomic32.h"
12 
13 #include <assert.h>
14 #include <libkern/OSAtomic.h>
15 #include <stdlib.h>
16 
17 #include "common_types.h"
18 
19 namespace webrtc {
20 
Atomic32(WebRtc_Word32 initialValue)21 Atomic32::Atomic32(WebRtc_Word32 initialValue) : _value(initialValue)
22 {
23     assert(Is32bitAligned());
24 }
25 
~Atomic32()26 Atomic32::~Atomic32()
27 {
28 }
29 
operator ++()30 WebRtc_Word32 Atomic32::operator++()
31 {
32     return OSAtomicIncrement32Barrier(&_value);
33 }
34 
operator --()35 WebRtc_Word32 Atomic32::operator--()
36 {
37     return OSAtomicDecrement32Barrier(&_value);
38 }
39 
operator +=(WebRtc_Word32 value)40 WebRtc_Word32 Atomic32::operator+=(WebRtc_Word32 value)
41 {
42     return OSAtomicAdd32Barrier(value, &_value);
43 }
44 
operator -=(WebRtc_Word32 value)45 WebRtc_Word32 Atomic32::operator-=(WebRtc_Word32 value)
46 {
47     return OSAtomicAdd32Barrier(-value, &_value);
48 }
49 
CompareExchange(WebRtc_Word32 newValue,WebRtc_Word32 compareValue)50 bool Atomic32::CompareExchange(WebRtc_Word32 newValue,
51                                WebRtc_Word32 compareValue)
52 {
53     return OSAtomicCompareAndSwap32Barrier(compareValue, newValue, &_value);
54 }
55 
Value() const56 WebRtc_Word32 Atomic32::Value() const
57 {
58     return _value;
59 }
60 }  // namespace webrtc
61