1 // Copyright 2023 The Pigweed Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not 4 // use this file except in compliance with the License. You may obtain a copy of 5 // the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 // License for the specific language governing permissions and limitations under 13 // the License. 14 15 #pragma once 16 17 #include "chre/platform/atomic.h" 18 19 namespace chre { 20 AtomicBool(bool starting_value)21inline AtomicBool::AtomicBool(bool starting_value) { 22 std::atomic_init(&atomic_, starting_value); 23 } 24 25 inline bool AtomicBool::operator=(bool desired) { return atomic_ = desired; } 26 load()27inline bool AtomicBool::load() const { return atomic_.load(); } 28 store(bool desired)29inline void AtomicBool::store(bool desired) { atomic_.store(desired); } 30 exchange(bool desired)31inline bool AtomicBool::exchange(bool desired) { 32 return atomic_.exchange(desired); 33 } 34 AtomicUint32(uint32_t startingValue)35inline AtomicUint32::AtomicUint32(uint32_t startingValue) { 36 std::atomic_init(&atomic_, startingValue); 37 } 38 39 inline uint32_t AtomicUint32::operator=(uint32_t desired) { 40 return atomic_ = desired; 41 } 42 load()43inline uint32_t AtomicUint32::load() const { return atomic_.load(); } 44 store(uint32_t desired)45inline void AtomicUint32::store(uint32_t desired) { atomic_.store(desired); } 46 exchange(uint32_t desired)47inline uint32_t AtomicUint32::exchange(uint32_t desired) { 48 return atomic_.exchange(desired); 49 } 50 fetch_add(uint32_t arg)51inline uint32_t AtomicUint32::fetch_add(uint32_t arg) { 52 return atomic_.fetch_add(arg); 53 } 54 fetch_increment()55inline uint32_t AtomicUint32::fetch_increment() { return atomic_.fetch_add(1); } 56 fetch_sub(uint32_t arg)57inline uint32_t AtomicUint32::fetch_sub(uint32_t arg) { 58 return atomic_.fetch_sub(arg); 59 } 60 fetch_decrement()61inline uint32_t AtomicUint32::fetch_decrement() { return atomic_.fetch_sub(1); } 62 63 } // namespace chre 64