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:
parent
30b044c167
commit
1b0cdc74f2
1 changed files with 13 additions and 0 deletions
|
|
@ -641,6 +641,8 @@ struct FFTWImpl : public FFT::Instance
|
||||||
FFTWImpl (size_t orderToUse, DynamicLibrary&& libraryToUse, const Symbols& symbols)
|
FFTWImpl (size_t orderToUse, DynamicLibrary&& libraryToUse, const Symbols& symbols)
|
||||||
: fftwLibrary (std::move (libraryToUse)), fftw (symbols), order (static_cast<size_t> (orderToUse))
|
: fftwLibrary (std::move (libraryToUse)), fftw (symbols), order (static_cast<size_t> (orderToUse))
|
||||||
{
|
{
|
||||||
|
ScopedLock lock (getFFTWPlanLock());
|
||||||
|
|
||||||
auto n = (1u << order);
|
auto n = (1u << order);
|
||||||
HeapBlock<Complex<float>> in (n), out (n);
|
HeapBlock<Complex<float>> in (n), out (n);
|
||||||
|
|
||||||
|
|
@ -653,6 +655,8 @@ struct FFTWImpl : public FFT::Instance
|
||||||
|
|
||||||
~FFTWImpl() override
|
~FFTWImpl() override
|
||||||
{
|
{
|
||||||
|
ScopedLock lock (getFFTWPlanLock());
|
||||||
|
|
||||||
fftw.destroy_fftw (c2cForward);
|
fftw.destroy_fftw (c2cForward);
|
||||||
fftw.destroy_fftw (c2cInverse);
|
fftw.destroy_fftw (c2cInverse);
|
||||||
fftw.destroy_fftw (r2c);
|
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);
|
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;
|
DynamicLibrary fftwLibrary;
|
||||||
Symbols fftw;
|
Symbols fftw;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue