Falcon
Loading...
Searching...
No Matches
ringbuffer.hpp
1// ---------------------------------------------------------------------
2// This file is part of falcon-core.
3//
4// Copyright (C) 2015, 2016, 2017 Neuro-Electronics Research Flanders
5//
6// Falcon-server is free software: you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10//
11// Falcon-server is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15//
16// You should have received a copy of the GNU General Public License
17// along with falcon-core. If not, see <http://www.gnu.org/licenses/>.
18// ---------------------------------------------------------------------
19
20#pragma once
21
22#include "disruptor/batch_descriptor.h"
23#include "disruptor/claim_strategy.h"
24#include "disruptor/interface.h"
25#include "disruptor/ring_buffer.h"
26#include "disruptor/wait_strategy.h"
27
38
39template <typename T>
40class RingBuffer : public disruptor::Sequencer {
41 public:
52 RingBuffer(const T& prototype, int buffer_size,
53 disruptor::ClaimStrategyOption claim_strategy_option,
54 disruptor::WaitStrategyOption wait_strategy_option)
55 : disruptor::Sequencer(buffer_size, claim_strategy_option, wait_strategy_option),
56 buffer_size_(buffer_size),
57 mask_(buffer_size - 1),
58 events_(buffer_size, prototype) {}
59
66
67 T* Get(const int64_t& sequence) { return &events_[sequence & mask_]; }
68
69 private:
70 // Members
71 int buffer_size_;
72 int mask_;
73 std::vector<T> events_;
74
75 DISALLOW_COPY_AND_ASSIGN(RingBuffer);
76};
77
78typedef disruptor::ProcessingSequenceBarrier RingBarrier;
79
80typedef disruptor::Sequence RingSequence;
81
82typedef disruptor::ClaimStrategyOption ClaimStrategy;
83typedef disruptor::WaitStrategyOption WaitStrategy;
84typedef disruptor::AlertException RingAlertException;
85
86typedef disruptor::BatchDescriptor RingBatch;
Definition ringbuffer.hpp:40
T * Get(const int64_t &sequence)
Definition ringbuffer.hpp:67
RingBuffer(const T &prototype, int buffer_size, disruptor::ClaimStrategyOption claim_strategy_option, disruptor::WaitStrategyOption wait_strategy_option)
Definition ringbuffer.hpp:52