zynaddsubfx

ZynAddSubFX open source synthesizer
Log | Files | Refs | Submodules | LICENSE

commit c816179faa83bcb3e3161eef7198476d4826a31b
parent 3efbafdd53546cdbc21c9939fe3190ff7102bb26
Author: fundamental <[email protected]>
Date:   Fri, 17 Oct 2014 11:25:13 -0400

Add mutex around FFTW Planner

This prevents undefined behavior during PADsynth generation

Diffstat:
Msrc/DSP/FFTwrapper.cpp | 16++++++++++++++++
1 file changed, 16 insertions(+), 0 deletions(-)

diff --git a/src/DSP/FFTwrapper.cpp b/src/DSP/FFTwrapper.cpp @@ -23,13 +23,24 @@ #include <cmath> #include <cassert> #include <cstring> +#include <pthread.h> #include "FFTwrapper.h" +static pthread_mutex_t *mutex = NULL; + FFTwrapper::FFTwrapper(int fftsize_) { + //first one will spawn the mutex (yeah this may be a race itself) + if(!mutex) { + mutex = new pthread_mutex_t; + pthread_mutex_init(mutex, NULL); + } + + fftsize = fftsize_; time = new fftw_real[fftsize]; fft = new fftw_complex[fftsize + 1]; + pthread_mutex_lock(mutex); planfftw = fftw_plan_dft_r2c_1d(fftsize, time, fft, @@ -38,12 +49,15 @@ FFTwrapper::FFTwrapper(int fftsize_) fft, time, FFTW_ESTIMATE); + pthread_mutex_unlock(mutex); } FFTwrapper::~FFTwrapper() { + pthread_mutex_lock(mutex); fftw_destroy_plan(planfftw); fftw_destroy_plan(planfftw_inv); + pthread_mutex_unlock(mutex); delete [] time; delete [] fft; @@ -82,4 +96,6 @@ void FFTwrapper::freqs2smps(const fft_t *freqs, float *smps) void FFT_cleanup() { fftw_cleanup(); + pthread_mutex_destroy(mutex); + delete mutex; }