Skip to content

Commit

Permalink
iioutil/commandqueue: Made the enqueue thread-safe.
Browse files Browse the repository at this point in the history
Signed-off-by: andrei.danila <[email protected]>
  • Loading branch information
andreidanila1 committed Apr 29, 2024
1 parent 90e8e61 commit cdbc0d3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions iioutil/include/iioutil/commandqueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ private Q_SLOTS:
private:
std::deque<Command *> m_commandQueue;
std::mutex m_commandMutex;
std::mutex m_enqueueMutex;
std::atomic<bool> m_running;
QThreadPool m_commandExecThreadPool;
};
Expand Down
2 changes: 2 additions & 0 deletions iioutil/src/commandqueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ CommandQueue::~CommandQueue()

void CommandQueue::enqueue(Command *command)
{
m_enqueueMutex.lock();
m_commandQueue.push_back(command);
qDebug(CAT_COMMANDQUEUE) << "enqueued " << command << " " << m_commandQueue.size();
m_enqueueMutex.unlock();

if(!m_running) {
start();
Expand Down

0 comments on commit cdbc0d3

Please sign in to comment.