1 /*
2  * Copyright (C) 2019 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 CHRE_PLATFORM_LINUX_ATOMIC_BASE_IMPL_H_
18 #define CHRE_PLATFORM_LINUX_ATOMIC_BASE_IMPL_H_
19 
20 #include "chre/platform/atomic.h"
21 
22 namespace chre {
23 
AtomicBool(bool startingValue)24 inline AtomicBool::AtomicBool(bool startingValue) {
25   std::atomic_init(&mAtomic, startingValue);
26 }
27 
28 inline bool AtomicBool::operator=(bool desired) {
29   return mAtomic = desired;
30 }
31 
load()32 inline bool AtomicBool::load() const {
33   return mAtomic.load();
34 }
35 
store(bool desired)36 inline void AtomicBool::store(bool desired) {
37   mAtomic.store(desired);
38 }
39 
exchange(bool desired)40 inline bool AtomicBool::exchange(bool desired) {
41   return mAtomic.exchange(desired);
42 }
43 
AtomicUint32(uint32_t startingValue)44 inline AtomicUint32::AtomicUint32(uint32_t startingValue) {
45   std::atomic_init(&mAtomic, startingValue);
46 }
47 
48 inline uint32_t AtomicUint32::operator=(uint32_t desired) {
49   return mAtomic = desired;
50 }
51 
load()52 inline uint32_t AtomicUint32::load() const {
53   return mAtomic.load();
54 }
55 
store(uint32_t desired)56 inline void AtomicUint32::store(uint32_t desired) {
57   mAtomic.store(desired);
58 }
59 
exchange(uint32_t desired)60 inline uint32_t AtomicUint32::exchange(uint32_t desired) {
61   return mAtomic.exchange(desired);
62 }
63 
fetch_add(uint32_t arg)64 inline uint32_t AtomicUint32::fetch_add(uint32_t arg) {
65   return mAtomic.fetch_add(arg);
66 }
67 
fetch_increment()68 inline uint32_t AtomicUint32::fetch_increment() {
69   return mAtomic.fetch_add(1);
70 }
71 
fetch_sub(uint32_t arg)72 inline uint32_t AtomicUint32::fetch_sub(uint32_t arg) {
73   return mAtomic.fetch_sub(arg);
74 }
75 
fetch_decrement()76 inline uint32_t AtomicUint32::fetch_decrement() {
77   return mAtomic.fetch_sub(1);
78 }
79 
80 }  // namespace chre
81 
82 #endif  // CHRE_PLATFORM_LINUX_ATOMIC_BASE_IMPL_H_
83