Mercurial > hg > svcore
comparison data/fft/FFTapi.h @ 1131:db946591a391 tony-2.0-integration
Fix lock contention in FFTapi
author | Chris Cannam |
---|---|
date | Mon, 12 Oct 2015 15:06:15 +0100 |
parents | b66734b5f806 |
children | e94719f941ba |
comparison
equal
deleted
inserted
replaced
1130:98898331dc2a | 1131:db946591a391 |
---|---|
50 | 50 |
51 #endif | 51 #endif |
52 | 52 |
53 #include <vector> | 53 #include <vector> |
54 #include <complex> | 54 #include <complex> |
55 #include <mutex> | |
55 | 56 |
56 class FFTForward // with fft shift but not window | 57 class FFTForward // with fft shift but not window |
57 { | 58 { |
59 static std::mutex m_mutex; | |
60 | |
58 public: | 61 public: |
59 FFTForward(int size) : | 62 FFTForward(int size) : |
60 m_size(size), | 63 m_size(size) |
61 m_input((float *)fftf_malloc(size * sizeof(float))), | 64 { |
62 m_output((fftf_complex *)fftf_malloc((size/2 + 1) * sizeof(fftf_complex))), | 65 std::lock_guard<std::mutex> lock(m_mutex); |
63 m_plan(fftf_plan_dft_r2c_1d(size, m_input, m_output, FFTW_MEASURE)) | 66 m_input = (float *)fftf_malloc(size * sizeof(float)); |
64 { } | 67 m_output = (fftf_complex *)fftf_malloc((size/2 + 1) * sizeof(fftf_complex)); |
68 m_plan = fftf_plan_dft_r2c_1d(size, m_input, m_output, FFTW_ESTIMATE); | |
69 } | |
65 | 70 |
66 ~FFTForward() { | 71 ~FFTForward() { |
72 std::lock_guard<std::mutex> lock(m_mutex); | |
67 fftf_destroy_plan(m_plan); | 73 fftf_destroy_plan(m_plan); |
68 fftf_free(m_input); | 74 fftf_free(m_input); |
69 fftf_free(m_output); | 75 fftf_free(m_output); |
70 } | 76 } |
71 | 77 |