1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

DSP: Ensured that FFTW is initialised and destroyed in a thread-safe way

This commit is contained in:
hogliux 2018-08-20 09:39:25 +01:00 committed by Tom Poole
parent 30b044c167
commit 1b0cdc74f2

View file

@ -641,6 +641,8 @@ struct FFTWImpl : public FFT::Instance
FFTWImpl (size_t orderToUse, DynamicLibrary&& libraryToUse, const Symbols& symbols)
: fftwLibrary (std::move (libraryToUse)), fftw (symbols), order (static_cast<size_t> (orderToUse))
{
ScopedLock lock (getFFTWPlanLock());
auto n = (1u << order);
HeapBlock<Complex<float>> in (n), out (n);
@ -653,6 +655,8 @@ struct FFTWImpl : public FFT::Instance
~FFTWImpl() override
{
ScopedLock lock (getFFTWPlanLock());
fftw.destroy_fftw (c2cForward);
fftw.destroy_fftw (c2cInverse);
fftw.destroy_fftw (r2c);
@ -697,6 +701,15 @@ struct FFTWImpl : public FFT::Instance
FloatVectorOperations::multiply ((float*) inputOutputData, 1.0f / static_cast<float> (n), (int) n);
}
//==============================================================================
// fftw's plan_* and destroy_* methods are NOT thread safe. So we need to share
// a lock between all instances of FFTWImpl
static CriticalSection& getFFTWPlanLock() noexcept
{
static CriticalSection cs;
return cs;
}
//==============================================================================
DynamicLibrary fftwLibrary;
Symbols fftw;