aboutsummaryrefslogtreecommitdiff
path: root/src/system_wrappers/source/atomic32.cc
blob: 588dd3e07d87bddcc75bdcbde60c3d5f5a240d58 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
 *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
 *
 *  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.
 */

#include "atomic32_wrapper.h"

#if defined(_WIN32)
    #include "atomic32_win.h"
#elif defined(WEBRTC_LINUX)
    #include "atomic32_linux.h"
#elif defined(WEBRTC_MAC)
    #include "atomic32_mac.h"
#else
    #error unsupported os!
#endif

namespace webrtc {
Atomic32Wrapper::Atomic32Wrapper(WebRtc_Word32 initialValue)
    : _impl(*new Atomic32Impl(initialValue))
{
}

Atomic32Wrapper::~Atomic32Wrapper()
{
    delete &_impl;
}

WebRtc_Word32 Atomic32Wrapper::operator++()
{
    return ++_impl;
}

WebRtc_Word32 Atomic32Wrapper::operator--()
{
    return --_impl;
}

// Read and write to properly aligned variables are atomic operations.
// Ex reference (for Windows): http://msdn.microsoft.com/en-us/library/ms684122(v=VS.85).aspx
// TODO (hellner) operator= and Atomic32Wrapper::Value() can be fully
// implemented here.
Atomic32Wrapper& Atomic32Wrapper::operator=(const Atomic32Wrapper& rhs)
{
    if(this == &rhs)
    {
        return *this;
    }
    _impl = rhs._impl;
    return *this;
}

Atomic32Wrapper& Atomic32Wrapper::operator=(WebRtc_Word32 rhs)
{
    _impl = rhs;
    return *this;
}

WebRtc_Word32 Atomic32Wrapper::operator+=(WebRtc_Word32 rhs)
{
    return _impl += rhs;
}

WebRtc_Word32 Atomic32Wrapper::operator-=(WebRtc_Word32 rhs)
{
    return _impl -= rhs;
}

bool Atomic32Wrapper::CompareExchange(WebRtc_Word32 newValue,
                                      WebRtc_Word32 compareValue)
{
    return _impl.CompareExchange(newValue,compareValue);
}

WebRtc_Word32 Atomic32Wrapper::Value() const
{
    return _impl.Value();
}
} // namespace webrtc