MuseScore
3.4
Music composition and notation
libmscore
fifo.h
Go to the documentation of this file.
1
//=============================================================================
2
// MuseScore
3
// Music Composition & Notation
4
//
5
// Copyright (C) 2002-2011 Werner Schweer
6
//
7
// This program is free software; you can redistribute it and/or modify
8
// it under the terms of the GNU General Public License version 2
9
// as published by the Free Software Foundation and appearing in
10
// the file LICENCE.GPL
11
//=============================================================================
12
13
#ifndef __FIFO_H__
14
#define __FIFO_H__
15
16
#include <atomic>
17
18
namespace
Ms
{
19
20
//---------------------------------------------------------
21
// FifoBase
22
// - works only for one reader/writer
23
// - reader writes ridx
24
// - writer writes widx
25
// - reader decrements counter
26
// - writer increments counter
27
// - counter increment/decrement must be atomic
28
//---------------------------------------------------------
29
30
class
FifoBase
{
31
32
protected
:
33
int
ridx
;
// read index
34
int
widx
;
// write index
35
std::atomic<int>
counter
;
// objects in fifo
36
int
maxCount
;
37
38
void
push
();
39
void
pop
();
40
41
public
:
42
FifoBase
() {
clear
(); }
43
virtual
~FifoBase
() {}
44
void
clear
();
45
int
count
()
const
{
return
counter
; }
46
bool
empty
()
const
{
return
counter == 0; }
47
bool
isFull
()
const
{
return
maxCount ==
counter
; }
48
};
49
50
51
}
// namespace Ms
52
#endif
53
Ms::FifoBase
Definition:
fifo.h:30
Ms::FifoBase::maxCount
int maxCount
Definition:
fifo.h:36
Ms::FifoBase::FifoBase
FifoBase()
Definition:
fifo.h:42
Ms::FifoBase::clear
void clear()
Definition:
fifo.cpp:21
Ms::FifoBase::count
int count() const
Definition:
fifo.h:45
Ms::FifoBase::isFull
bool isFull() const
Definition:
fifo.h:47
Ms::FifoBase::empty
bool empty() const
Definition:
fifo.h:46
Ms::FifoBase::pop
void pop()
Definition:
fifo.cpp:43
Ms::FifoBase::~FifoBase
virtual ~FifoBase()
Definition:
fifo.h:43
Ms::FifoBase::push
void push()
Definition:
fifo.cpp:32
Ms
Definition:
aeolus.cpp:26
Ms::FifoBase::ridx
int ridx
Definition:
fifo.h:33
Ms::FifoBase::counter
std::atomic< int > counter
Definition:
fifo.h:35
Ms::FifoBase::widx
int widx
Definition:
fifo.h:34
Generated by
1.8.13