blob: 32f788190446e1d81ce75d22d7646b2ff14d275f [file] [log] [blame]
Don Turnerca6f91a2017-09-05 14:52:39 +01001/*
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 Turnerca6f91a2017-09-05 14:52:39 +010020#include <atomic>
Phil Burk9446ed62020-07-13 11:26:55 -070021#include <stdint.h>
22
23#include "FifoControllerBase.h"
Don Turnerca6f91a2017-09-05 14:52:39 +010024
Don Turner3bf32ae2017-11-27 13:25:05 +000025namespace oboe {
26
Don Turnerca6f91a2017-09-05 14:52:39 +010027/**
28 * A FifoControllerBase with counters external to the class.
29 */
30class FifoControllerIndirect : public FifoControllerBase {
31
32public:
33 FifoControllerIndirect(uint32_t bufferSize,
Phil Burk08a5e0f2019-08-23 16:28:21 -070034 std::atomic<uint64_t> *readCounterAddress,
35 std::atomic<uint64_t> *writeCounterAddress);
Thomas Guilbertf2636012019-07-10 12:16:08 -070036 virtual ~FifoControllerIndirect() = default;
Don Turnerca6f91a2017-09-05 14:52:39 +010037
Thomas Guilbertf2636012019-07-10 12:16:08 -070038 virtual uint64_t getReadCounter() const override {
Don Turnerca6f91a2017-09-05 14:52:39 +010039 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 Guilbert5a73fb92019-07-12 11:54:45 -070044 virtual void incrementReadCounter(uint64_t n) override {
45 mReadCounterAddress->fetch_add(n, std::memory_order_acq_rel);
46 }
Thomas Guilbertf2636012019-07-10 12:16:08 -070047 virtual uint64_t getWriteCounter() const override {
Don Turnerca6f91a2017-09-05 14:52:39 +010048 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 Guilbert5a73fb92019-07-12 11:54:45 -070053 virtual void incrementWriteCounter(uint64_t n) override {
54 mWriteCounterAddress->fetch_add(n, std::memory_order_acq_rel);
55 }
Don Turnerca6f91a2017-09-05 14:52:39 +010056
57private:
Thomas Guilbert103bc752019-07-15 12:30:16 -070058
Phil Burk08a5e0f2019-08-23 16:28:21 -070059 std::atomic<uint64_t> *mReadCounterAddress;
60 std::atomic<uint64_t> *mWriteCounterAddress;
Don Turnerca6f91a2017-09-05 14:52:39 +010061
62};
63
Don Turner3bf32ae2017-11-27 13:25:05 +000064} // namespace oboe
65
Don Turnerca6f91a2017-09-05 14:52:39 +010066#endif //NATIVEOBOE_FIFOCONTROLLERINDIRECT_H