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