# HG changeset patch # User Chris Cannam # Date 1444658775 -3600 # Node ID 0cb263a2f52cdb6b15cb141fc067d3e502a2a2cc # Parent 2c43f99040689b482b52971b1edef6b697427f21 Fix lock contention in FFTapi diff -r 2c43f9904068 -r 0cb263a2f52c data/fft/FFTapi.cpp --- a/data/fft/FFTapi.cpp Thu Aug 20 13:33:46 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 2c43f9904068 -r 0cb263a2f52c data/fft/FFTapi.h --- a/data/fft/FFTapi.h Thu Aug 20 13:33:46 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);