Skip to content

feature req: DataOutputQueue with maxSize=0 --> received data only sent to callbacks #366

Closed
@diablodale

Description

@diablodale

I request the DataOutputQueue support maxSize=0 so that no data is retained in the internal std::queue yet the callbacks continue to be called with the data.

I think the change is trivial and isolated to LockingQueue.hpp. I can take on this work as it already has use potential in my app.

Setup

  • all

Repro

By code review. LockingQueue::push() and tryWaitAndPush() don't behave appropriately when maxSize=0.
If maxSize=0, they would actually behave as if it was =1.

bool push(T const& data) {
{
std::unique_lock<std::mutex> lock(guard);
if(!blocking) {
// if non blocking, remove as many oldest elements as necessary, so next one will fit
// necessary if maxSize was changed
while(queue.size() >= maxSize) {
queue.pop();
}
} else {
signalPop.wait(lock, [this]() { return queue.size() < maxSize || destructed; });
if(destructed) return false;
}
queue.push(data);
}
signalPush.notify_all();
return true;
}

A one-line change to check for if (maxSize == 0) return true would correct the behavior and support this feature request. I think true is the appropriate return since this is not an error condition and the function would have placed the data into the queue. It just so happens that a maxSize=0 queue is a singularity with size 0... or like /dev/null.

And removing the one line check here

if(sz == 0) throw std::invalid_argument("Queue size can't be 0!");

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions