MuseScore  3.4
Music composition and notation
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 
Definition: fifo.h:30
int maxCount
Definition: fifo.h:36
FifoBase()
Definition: fifo.h:42
void clear()
Definition: fifo.cpp:21
int count() const
Definition: fifo.h:45
bool isFull() const
Definition: fifo.h:47
bool empty() const
Definition: fifo.h:46
void pop()
Definition: fifo.cpp:43
virtual ~FifoBase()
Definition: fifo.h:43
void push()
Definition: fifo.cpp:32
Definition: aeolus.cpp:26
int ridx
Definition: fifo.h:33
std::atomic< int > counter
Definition: fifo.h:35
int widx
Definition: fifo.h:34