RTXI
2.4
The Real-Time eXperiment Interface Documentation
src
atomic_fifo.h
Go to the documentation of this file.
1
/*
2
Copyright (C) 2011 Georgia Institute of Technology, University of Utah, Weill Cornell Medical College
3
4
This program is free software: you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation, either version 3 of the License, or
7
(at your option) any later version.
8
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
13
14
You should have received a copy of the GNU General Public License
15
along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17
*/
18
19
#ifndef ATOMIC_FIFO_H
20
#define ATOMIC_FIFO_H
21
22
#include <cstdlib>
23
#include <atomic>
24
26
/*
27
* Uses C++11 standard atomic library to implement a lockfree FIFO.
28
* It is an absolute requirement only one thread produces ( calls write() )
29
* and only one thread consumes ( calls read() ).
30
*
31
*/
32
33
class
AtomicFifo
34
{
35
36
public
:
37
AtomicFifo
(
size_t
);
38
~AtomicFifo
(
void
);
39
48
bool
write
(
const
void
*buffer,
size_t
itemSize);
49
58
bool
read
(
void
*buffer,
size_t
itemSize);
59
66
bool
isLockFree
()
const
;
67
private
:
68
size_t
increment(
size_t
current_ptr,
size_t
itemSize)
const
;
69
70
char
*data;
71
std::atomic<size_t> head;
72
std::atomic<size_t> tail;
73
size_t
fifoSize;
74
75
};
76
77
#endif
/* ATOMIC_FIFO_H */
AtomicFifo::write
bool write(const void *buffer, size_t itemSize)
Definition:
atomic_fifo.cpp:35
AtomicFifo::AtomicFifo
AtomicFifo(size_t)
Definition:
atomic_fifo.cpp:24
AtomicFifo
Lockfree SINGLE producer / SINGLE consumer FIFO.
Definition:
atomic_fifo.h:33
AtomicFifo::isLockFree
bool isLockFree() const
Definition:
atomic_fifo.cpp:94
AtomicFifo::~AtomicFifo
~AtomicFifo(void)
Definition:
atomic_fifo.cpp:30
AtomicFifo::read
bool read(void *buffer, size_t itemSize)
Definition:
atomic_fifo.cpp:61
Generated on Thu Apr 21 2022 16:58:34 for RTXI by
1.8.17