Don Turner | ca6f91a | 2017-09-05 14:52:39 +0100 | [diff] [blame] | 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 | |
Don Turner | ca6f91a | 2017-09-05 14:52:39 +0100 | [diff] [blame] | 20 | #include <atomic> |
Phil Burk | 9446ed6 | 2020-07-13 11:26:55 -0700 | [diff] [blame] | 21 | #include <stdint.h> |
| 22 | |
| 23 | #include "FifoControllerBase.h" |
Don Turner | ca6f91a | 2017-09-05 14:52:39 +0100 | [diff] [blame] | 24 | |
Don Turner | 3bf32ae | 2017-11-27 13:25:05 +0000 | [diff] [blame] | 25 | namespace oboe { |
| 26 | |
Don Turner | ca6f91a | 2017-09-05 14:52:39 +0100 | [diff] [blame] | 27 | /** |
| 28 | * A FifoControllerBase with counters external to the class. |
| 29 | */ |
| 30 | class FifoControllerIndirect : public FifoControllerBase { |
| 31 | |
| 32 | public: |
| 33 | FifoControllerIndirect(uint32_t bufferSize, |
Phil Burk | 08a5e0f | 2019-08-23 16:28:21 -0700 | [diff] [blame] | 34 | std::atomic<uint64_t> *readCounterAddress, |
| 35 | std::atomic<uint64_t> *writeCounterAddress); |
Thomas Guilbert | f263601 | 2019-07-10 12:16:08 -0700 | [diff] [blame] | 36 | virtual ~FifoControllerIndirect() = default; |
Don Turner | ca6f91a | 2017-09-05 14:52:39 +0100 | [diff] [blame] | 37 | |
Thomas Guilbert | f263601 | 2019-07-10 12:16:08 -0700 | [diff] [blame] | 38 | virtual uint64_t getReadCounter() const override { |
Don Turner | ca6f91a | 2017-09-05 14:52:39 +0100 | [diff] [blame] | 39 | return mReadCounterAddress->load(std::memory_order_acquire); |
| 40 | } |
| 41 | virtual void setReadCounter(uint64_t n) override { |
| 42 | mReadCounterAddress->store(n, std::memory_order_release); |
| 43 | } |
Thomas Guilbert | 5a73fb9 | 2019-07-12 11:54:45 -0700 | [diff] [blame] | 44 | virtual void incrementReadCounter(uint64_t n) override { |
| 45 | mReadCounterAddress->fetch_add(n, std::memory_order_acq_rel); |
| 46 | } |
Thomas Guilbert | f263601 | 2019-07-10 12:16:08 -0700 | [diff] [blame] | 47 | virtual uint64_t getWriteCounter() const override { |
Don Turner | ca6f91a | 2017-09-05 14:52:39 +0100 | [diff] [blame] | 48 | return mWriteCounterAddress->load(std::memory_order_acquire); |
| 49 | } |
| 50 | virtual void setWriteCounter(uint64_t n) override { |
| 51 | mWriteCounterAddress->store(n, std::memory_order_release); |
| 52 | } |
Thomas Guilbert | 5a73fb9 | 2019-07-12 11:54:45 -0700 | [diff] [blame] | 53 | virtual void incrementWriteCounter(uint64_t n) override { |
| 54 | mWriteCounterAddress->fetch_add(n, std::memory_order_acq_rel); |
| 55 | } |
Don Turner | ca6f91a | 2017-09-05 14:52:39 +0100 | [diff] [blame] | 56 | |
| 57 | private: |
Thomas Guilbert | 103bc75 | 2019-07-15 12:30:16 -0700 | [diff] [blame] | 58 | |
Phil Burk | 08a5e0f | 2019-08-23 16:28:21 -0700 | [diff] [blame] | 59 | std::atomic<uint64_t> *mReadCounterAddress; |
| 60 | std::atomic<uint64_t> *mWriteCounterAddress; |
Don Turner | ca6f91a | 2017-09-05 14:52:39 +0100 | [diff] [blame] | 61 | |
| 62 | }; |
| 63 | |
Don Turner | 3bf32ae | 2017-11-27 13:25:05 +0000 | [diff] [blame] | 64 | } // namespace oboe |
| 65 | |
Don Turner | ca6f91a | 2017-09-05 14:52:39 +0100 | [diff] [blame] | 66 | #endif //NATIVEOBOE_FIFOCONTROLLERINDIRECT_H |