Skip to content

Commit

Permalink
Convolution: Fix issue where old convolution engines were sometimes u…
Browse files Browse the repository at this point in the history
…sed after calling prepare

The startThread/stopThread calls were moved to prevent a thread
sanitizer warning about a race on the vtable of Impl.
  • Loading branch information
reuk committed Jul 10, 2020
1 parent 3de4fab commit 5ab6042
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions modules/juce_dsp/frequency/juce_Convolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,7 @@ class BackgroundMessageQueue : private Thread
public:
explicit BackgroundMessageQueue (int entries)
: Thread ("Convolution background loader"), queue (entries)
{
startThread();
}

~BackgroundMessageQueue() override
{
stopThread (-1);
}
{}

using IncomingCommand = FixedSizeFunction<400, void()>;

Expand All @@ -93,6 +86,9 @@ class BackgroundMessageQueue : private Thread
// This function is only safe to call from a single thread at a time.
bool push (IncomingCommand& command) { return queue.push (command); }

using Thread::startThread;
using Thread::stopThread;

private:
void run() override
{
Expand All @@ -119,9 +115,14 @@ ConvolutionMessageQueue::ConvolutionMessageQueue()

ConvolutionMessageQueue::ConvolutionMessageQueue (int entries)
: pimpl (std::make_unique<Impl> (entries))
{}
{
pimpl->startThread();
}

ConvolutionMessageQueue::~ConvolutionMessageQueue() noexcept = default;
ConvolutionMessageQueue::~ConvolutionMessageQueue() noexcept
{
pimpl->stopThread (-1);
}

ConvolutionMessageQueue::ConvolutionMessageQueue (ConvolutionMessageQueue&&) noexcept = default;
ConvolutionMessageQueue& ConvolutionMessageQueue::operator= (ConvolutionMessageQueue&&) noexcept = default;
Expand Down Expand Up @@ -1016,7 +1017,8 @@ class Convolution::Impl
{
mixer.prepare (spec);
engineQueue->prepare (spec);
installPendingEngine();
currentEngine = engineQueue->getEngine();
previousEngine = nullptr;
jassert (currentEngine != nullptr);
}

Expand Down

0 comments on commit 5ab6042

Please sign in to comment.