Skip to content

Commit

Permalink
Merge pull request #13 from fventuri/let_callback_threads_terminate_a…
Browse files Browse the repository at this point in the history
…fter_stop

Fix dead lock condition with stop() method
  • Loading branch information
fventuri authored Oct 21, 2021
2 parents c6abc24 + da33df3 commit a6a2bf3
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/rsp_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,13 @@ bool rsp_impl::stop()
}
}
run_status = RunStatus::idle;

// notify the callback threads so they can terminate
ring_buffers[0].tail = ring_buffers[0].head;
ring_buffers[1].tail = ring_buffers[1].head;
ring_buffers[0].overflow.notify_one();
ring_buffers[1].overflow.notify_one();

return true;
}

Expand Down Expand Up @@ -711,6 +718,10 @@ void rsp_impl::stream_callback(short *xi, short *xq,
return ring_buffer.tail + ring_buffer_overflow >= ring_buffer.head;
});

if (run_status != RunStatus::streaming) {
return;
}

unsigned long new_head = ring_buffer.head + numSamples;
size_t start = static_cast<size_t>(ring_buffer.head & RingBufferMask);
size_t end = static_cast<size_t>(new_head & RingBufferMask);
Expand Down

0 comments on commit a6a2bf3

Please sign in to comment.