FFTFactory: add mutex for thread safety. Implements issue #514

pull/530/head
f4exb 2020-05-01 04:56:04 +02:00
rodzic 578ac1db00
commit 42d6732147
2 zmienionych plików z 7 dodań i 1 usunięć

Wyświetl plik

@ -15,10 +15,12 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#include <QMutexLocker>
#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<unsigned int, std::vector<AllocatedEngine>>& 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<unsigned int, std::vector<AllocatedEngine>>& enginesBySize = inverse ?
m_invFFTEngineBySize : m_fftEngineBySize;

Wyświetl plik

@ -21,6 +21,7 @@
#include <map>
#include <vector>
#include <QMutex>
#include <QString>
#include "export.h"
@ -51,6 +52,7 @@ private:
QString m_fftwWisdomFileName;
std::map<unsigned int, std::vector<AllocatedEngine>> m_fftEngineBySize;
std::map<unsigned int, std::vector<AllocatedEngine>> m_invFFTEngineBySize;
QMutex m_mutex;
};
#endif // _SDRBASE_FFTWFACTORY_H