arduino-audio-tools
SynchronizedQueue.h
1 #pragma once
2 #include "AudioTools/CoreAudio/AudioBasic/Collections/List.h"
3 
4 namespace audio_tools {
5 
15 template <class T, class TMutex>
17  public:
18  SynchronizedQueue() = default;
19 
20  bool enqueue(T& data) {
21  LockGuard(mutex);
22  return l.push_front(data);
23  }
24 
25  bool peek(T& data) {
26  LockGuard(mutex);
27  if (l.end()->prior == nullptr) return false;
28  data = *(l.end()->prior);
29  return true;
30  }
31 
32  bool dequeue(T& data) {
33  LockGuard(mutex);
34  return l.pop_back(data);
35  }
36 
37  size_t size() {
38  LockGuard(mutex);
39  return l.size();
40  }
41 
42  bool clear() {
43  LockGuard(mutex);
44  return l.clear();
45  }
46 
47  bool empty() {
48  LockGuard(mutex);
49  return l.empty();
50  }
51 
52  void setAllocator(Allocator& allocator) { l.setAllocator(allocator); }
53 
54  protected:
55  List<T> l;
56  TMutex mutex;
57 };
58 
59 } // namespace audio_tools
Memory allocateator which uses malloc.
Definition: Allocator.h:22
Double linked list.
Definition: List.h:18
RAII implementaion using a Mutex: Only a few microcontrollers provide lock guards,...
Definition: LockGuard.h:17
FIFO Queue which is based on a List that is thread save.
Definition: SynchronizedQueue.h:16
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition: AudioConfig.h:872