Skip to content

Commit

Permalink
Queue tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pschatzmann committed Sep 29, 2024
1 parent 13bb1ca commit ee4a592
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
5 changes: 4 additions & 1 deletion examples/tests/basic/test-queue/test-queue.ino
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#include "AudioTools.h"
#include "Concurrency/QueueLockFree.h"

// select the queue implementation:
//Queue<int> q;
QueueFromVector<int> q{0,10};
//QueueFromVector<int> q{10, 0};
QueueLockFree<int> q(10);

void setup(){
Serial.begin(115200);
Expand Down
4 changes: 3 additions & 1 deletion src/AudioBasic/Collections/QueueFromVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace audio_tools {
template <class T>
class QueueFromVector {
public:
QueueFromVector(T empty, size_t size) {
QueueFromVector(size_t size, T empty) {
null_value = empty;
resize(size);
};
Expand Down Expand Up @@ -72,6 +72,8 @@ class QueueFromVector {
bool is_full() {
return _size >= vector.size();
}

size_t capacity() { return vector.capacity(); }

void setAllocator(Allocator &allocator){
vector.setAllocator(allocator);
Expand Down
4 changes: 2 additions & 2 deletions src/AudioTools/Buffers.h
Original file line number Diff line number Diff line change
Expand Up @@ -722,8 +722,8 @@ class NBuffer : public BaseBuffer<T> {
uint16_t buffer_count = 0;
BaseBuffer<T> *actual_read_buffer = nullptr;
BaseBuffer<T> *actual_write_buffer = nullptr;
QueueFromVector<BaseBuffer<T> *> available_buffers{nullptr,0};
QueueFromVector<BaseBuffer<T> *> filled_buffers{nullptr,0};
QueueFromVector<BaseBuffer<T> *> available_buffers{0, nullptr};
QueueFromVector<BaseBuffer<T> *> filled_buffers{0, nullptr};
unsigned long start_time = 0;
unsigned long sample_count = 0;

Expand Down
2 changes: 2 additions & 0 deletions src/Concurrency/QueueLockFree.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class QueueLockFree {

size_t capacity() const { return capacity_value; }

bool empty() { return size() == 0;}

size_t size() const {
size_t head = head_pos.load(std::memory_order_acquire);
return tail_pos.load(std::memory_order_relaxed) - head;
Expand Down

0 comments on commit ee4a592

Please sign in to comment.