From 5ab6042c04f65ebab363450acc6503ce4290d5c3 Mon Sep 17 00:00:00 2001 From: reuk Date: Fri, 10 Jul 2020 20:02:50 +0100 Subject: [PATCH] Convolution: Fix issue where old convolution engines were sometimes used after calling prepare The startThread/stopThread calls were moved to prevent a thread sanitizer warning about a race on the vtable of Impl. --- .../juce_dsp/frequency/juce_Convolution.cpp | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/modules/juce_dsp/frequency/juce_Convolution.cpp b/modules/juce_dsp/frequency/juce_Convolution.cpp index 8983676570..050aa91bc3 100644 --- a/modules/juce_dsp/frequency/juce_Convolution.cpp +++ b/modules/juce_dsp/frequency/juce_Convolution.cpp @@ -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()>; @@ -93,6 +86,9 @@ public: // 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 { @@ -119,9 +115,14 @@ ConvolutionMessageQueue::ConvolutionMessageQueue() ConvolutionMessageQueue::ConvolutionMessageQueue (int entries) : pimpl (std::make_unique (entries)) -{} +{ + pimpl->startThread(); +} -ConvolutionMessageQueue::~ConvolutionMessageQueue() noexcept = default; +ConvolutionMessageQueue::~ConvolutionMessageQueue() noexcept +{ + pimpl->stopThread (-1); +} ConvolutionMessageQueue::ConvolutionMessageQueue (ConvolutionMessageQueue&&) noexcept = default; ConvolutionMessageQueue& ConvolutionMessageQueue::operator= (ConvolutionMessageQueue&&) noexcept = default; @@ -1016,7 +1017,8 @@ public: { mixer.prepare (spec); engineQueue->prepare (spec); - installPendingEngine(); + currentEngine = engineQueue->getEngine(); + previousEngine = nullptr; jassert (currentEngine != nullptr); }