From 42d6732147c20053e7477c2e2de7c809c0dd9a4b Mon Sep 17 00:00:00 2001 From: f4exb Date: Fri, 1 May 2020 04:56:04 +0200 Subject: [PATCH] FFTFactory: add mutex for thread safety. Implements issue #514 --- sdrbase/dsp/fftfactory.cpp | 6 +++++- sdrbase/dsp/fftfactory.h | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/sdrbase/dsp/fftfactory.cpp b/sdrbase/dsp/fftfactory.cpp index 5367d4eae..46cb7efc6 100644 --- a/sdrbase/dsp/fftfactory.cpp +++ b/sdrbase/dsp/fftfactory.cpp @@ -15,10 +15,12 @@ // along with this program. If not, see . // /////////////////////////////////////////////////////////////////////////////////// +#include #include "fftfactory.h" FFTFactory::FFTFactory(const QString& fftwWisdomFileName) : - m_fftwWisdomFileName(fftwWisdomFileName) + m_fftwWisdomFileName(fftwWisdomFileName), + m_mutex(QMutex::Recursive) {} FFTFactory::~FFTFactory() @@ -70,6 +72,7 @@ void FFTFactory::preallocate( unsigned int FFTFactory::getEngine(unsigned int fftSize, bool inverse, FFTEngine **engine) { + QMutexLocker mutexLocker(&m_mutex); std::map>& enginesBySize = inverse ? m_invFFTEngineBySize : m_fftEngineBySize; @@ -121,6 +124,7 @@ unsigned int FFTFactory::getEngine(unsigned int fftSize, bool inverse, FFTEngine void FFTFactory::releaseEngine(unsigned int fftSize, bool inverse, unsigned int engineSequence) { + QMutexLocker mutexLocker(&m_mutex); std::map>& enginesBySize = inverse ? m_invFFTEngineBySize : m_fftEngineBySize; diff --git a/sdrbase/dsp/fftfactory.h b/sdrbase/dsp/fftfactory.h index 80aefed89..65859757e 100644 --- a/sdrbase/dsp/fftfactory.h +++ b/sdrbase/dsp/fftfactory.h @@ -21,6 +21,7 @@ #include #include +#include #include #include "export.h" @@ -51,6 +52,7 @@ private: QString m_fftwWisdomFileName; std::map> m_fftEngineBySize; std::map> m_invFFTEngineBySize; + QMutex m_mutex; }; #endif // _SDRBASE_FFTWFACTORY_H