1 /* 2 * Copyright 2016 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 NATIVEOBOE_FIFOCONTROLLERINDIRECT_H 18 #define NATIVEOBOE_FIFOCONTROLLERINDIRECT_H 19 20 #include <atomic> 21 #include <stdint.h> 22 23 #include "FifoControllerBase.h" 24 25 namespace oboe { 26 27 /** 28 * A FifoControllerBase with counters external to the class. 29 */ 30 class FifoControllerIndirect : public FifoControllerBase { 31 32 public: 33 FifoControllerIndirect(uint32_t bufferSize, 34 std::atomic<uint64_t> *readCounterAddress, 35 std::atomic<uint64_t> *writeCounterAddress); 36 virtual ~FifoControllerIndirect() = default; 37 getReadCounter()38 virtual uint64_t getReadCounter() const override { 39 return mReadCounterAddress->load(std::memory_order_acquire); 40 } setReadCounter(uint64_t n)41 virtual void setReadCounter(uint64_t n) override { 42 mReadCounterAddress->store(n, std::memory_order_release); 43 } incrementReadCounter(uint64_t n)44 virtual void incrementReadCounter(uint64_t n) override { 45 mReadCounterAddress->fetch_add(n, std::memory_order_acq_rel); 46 } getWriteCounter()47 virtual uint64_t getWriteCounter() const override { 48 return mWriteCounterAddress->load(std::memory_order_acquire); 49 } setWriteCounter(uint64_t n)50 virtual void setWriteCounter(uint64_t n) override { 51 mWriteCounterAddress->store(n, std::memory_order_release); 52 } incrementWriteCounter(uint64_t n)53 virtual void incrementWriteCounter(uint64_t n) override { 54 mWriteCounterAddress->fetch_add(n, std::memory_order_acq_rel); 55 } 56 57 private: 58 59 std::atomic<uint64_t> *mReadCounterAddress; 60 std::atomic<uint64_t> *mWriteCounterAddress; 61 62 }; 63 64 } // namespace oboe 65 66 #endif //NATIVEOBOE_FIFOCONTROLLERINDIRECT_H 67