# HG changeset patch # User Chris Cannam # Date 1444658775 -3600 # Node ID db946591a39117218320a9fe2201647c61c5fa5f # Parent 98898331dc2a174a883a883f93aa70c0517c7cd4 Fix lock contention in FFTapi diff -r 98898331dc2a -r db946591a391 data/fft/FFTapi.cpp --- a/data/fft/FFTapi.cpp Mon Oct 12 13:38:24 2015 +0100 +++ b/data/fft/FFTapi.cpp Mon Oct 12 15:06:15 2015 +0100 @@ -16,6 +16,8 @@ #include "FFTapi.h" +std::mutex FFTForward::m_mutex; + #ifndef HAVE_FFTW3F #include diff -r 98898331dc2a -r db946591a391 data/fft/FFTapi.h --- a/data/fft/FFTapi.h Mon Oct 12 13:38:24 2015 +0100 +++ b/data/fft/FFTapi.h Mon Oct 12 15:06:15 2015 +0100 @@ -52,18 +52,24 @@ #include #include +#include class FFTForward // with fft shift but not window { + static std::mutex m_mutex; + public: FFTForward(int size) : - m_size(size), - m_input((float *)fftf_malloc(size * sizeof(float))), - m_output((fftf_complex *)fftf_malloc((size/2 + 1) * sizeof(fftf_complex))), - m_plan(fftf_plan_dft_r2c_1d(size, m_input, m_output, FFTW_MEASURE)) - { } + m_size(size) + { + std::lock_guard lock(m_mutex); + m_input = (float *)fftf_malloc(size * sizeof(float)); + m_output = (fftf_complex *)fftf_malloc((size/2 + 1) * sizeof(fftf_complex)); + m_plan = fftf_plan_dft_r2c_1d(size, m_input, m_output, FFTW_ESTIMATE); + } ~FFTForward() { + std::lock_guard lock(m_mutex); fftf_destroy_plan(m_plan); fftf_free(m_input); fftf_free(m_output);