blob: d3e413e3c9ec6af88bc8bf71c12542595a28e884 [file] [log] [blame]
Don Turnerca6f91a2017-09-05 14:52:39 +01001/*
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
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 contained in the class.
29 */
30class FifoController : public FifoControllerBase
31{
32public:
Phil Burk919cd422019-08-12 17:26:50 -070033 FifoController(uint32_t bufferSize);
Thomas Guilbertf2636012019-07-10 12:16:08 -070034 virtual ~FifoController() = default;
Don Turnerca6f91a2017-09-05 14:52:39 +010035
Thomas Guilbertf2636012019-07-10 12:16:08 -070036 virtual uint64_t getReadCounter() const override {
Don Turnerca6f91a2017-09-05 14:52:39 +010037 return mReadCounter.load(std::memory_order_acquire);
38 }
39 virtual void setReadCounter(uint64_t n) override {
40 mReadCounter.store(n, std::memory_order_release);
41 }
Thomas Guilbert5a73fb92019-07-12 11:54:45 -070042 virtual void incrementReadCounter(uint64_t n) override {
43 mReadCounter.fetch_add(n, std::memory_order_acq_rel);
44 }
Thomas Guilbertf2636012019-07-10 12:16:08 -070045 virtual uint64_t getWriteCounter() const override {
Don Turnerca6f91a2017-09-05 14:52:39 +010046 return mWriteCounter.load(std::memory_order_acquire);
47 }
48 virtual void setWriteCounter(uint64_t n) override {
49 mWriteCounter.store(n, std::memory_order_release);
50 }
Thomas Guilbert5a73fb92019-07-12 11:54:45 -070051 virtual void incrementWriteCounter(uint64_t n) override {
52 mWriteCounter.fetch_add(n, std::memory_order_acq_rel);
53 }
Don Turnerca6f91a2017-09-05 14:52:39 +010054
55private:
Phil Burk919cd422019-08-12 17:26:50 -070056 std::atomic<uint64_t> mReadCounter{};
57 std::atomic<uint64_t> mWriteCounter{};
Don Turnerca6f91a2017-09-05 14:52:39 +010058};
59
Don Turner3bf32ae2017-11-27 13:25:05 +000060} // namespace oboe
Don Turnerca6f91a2017-09-05 14:52:39 +010061
62#endif //NATIVEOBOE_FIFOCONTROLLER_H