blob: 61b93cca370881ef32e825acc68416faf67bbc84 [file] [log] [blame]
Mathieu Chartier2fde5332012-09-14 14:51:54 -07001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ART_SRC_ATOMIC_INTEGER_H_
18#define ART_SRC_ATOMIC_INTEGER_H_
19
20#include "atomic.h"
21
22namespace art {
23
24class AtomicInteger {
25 public:
26 AtomicInteger(int32_t value) : value_(value) { }
27
28 operator int32_t () const {
29 return get();
30 }
31
32 int32_t get() const {
33 return value_;
34 }
35
36 int32_t operator += (const int32_t value) {
37 return android_atomic_add(value, &value_);
38 }
39
40 int32_t operator -= (const int32_t value) {
41 return android_atomic_add(-value, &value_);
42 }
43
44 int32_t operator |= (const int32_t value) {
45 return android_atomic_or(value, &value_);
46 }
47
48 int32_t operator &= (const int32_t value) {
49 return android_atomic_and(-value, &value_);
50 }
51
52 int32_t operator ++ () {
53 return android_atomic_inc(&value_);
54 }
55
56 int32_t operator -- () {
57 return android_atomic_dec(&value_);
58 }
59 private:
60 int32_t value_;
61};
62
63}
64
65#endif // ART_SRC_ATOMIC_INTEGER_H_