blob: 7434634e4d8117dfd357b6ca4f25c7f10227c09f [file] [log] [blame]
Phil Burkfd911c12017-01-03 17:15:39 -08001/*
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 FIFO_FIFO_CONTROLLER_H
18#define FIFO_FIFO_CONTROLLER_H
19
20#include <stdint.h>
21#include <atomic>
22
23#include "FifoControllerBase.h"
24
25/**
26 * A FIFO with counters contained in the class.
27 */
28class FifoController : public FifoControllerBase
29{
30public:
31 FifoController(fifo_counter_t bufferSize, fifo_counter_t threshold)
32 : FifoControllerBase(bufferSize, threshold)
33 , mReadCounter(0)
34 , mWriteCounter(0)
35 {}
36
37 virtual ~FifoController() {}
38
39 // TODO review use of memory barriers, probably incorrect
40 virtual fifo_counter_t getReadCounter() override {
41 return mReadCounter.load(std::memory_order_acquire);
42 }
43 virtual void setReadCounter(fifo_counter_t n) override {
44 mReadCounter.store(n, std::memory_order_release);
45 }
46 virtual fifo_counter_t getWriteCounter() override {
47 return mWriteCounter.load(std::memory_order_acquire);
48 }
49 virtual void setWriteCounter(fifo_counter_t n) override {
50 mWriteCounter.store(n, std::memory_order_release);
51 }
52
53private:
54 std::atomic<fifo_counter_t> mReadCounter;
55 std::atomic<fifo_counter_t> mWriteCounter;
56};
57
58
59#endif //FIFO_FIFO_CONTROLLER_H