diff options
author | Balint Seeber <balint256@gmail.com> | 2018-03-18 17:46:59 -0700 |
---|---|---|
committer | Marcus Müller <marcus@hostalia.de> | 2018-03-22 22:05:33 +0100 |
commit | 7edb8217a58027f1f80ea9404b0164721f812147 (patch) | |
tree | 0a509a31769163c39e0a353f7627036553105e84 /gr-fft | |
parent | c26c19d65938e1777dfbf25a9ae40e73cfc8d703 (diff) |
fft: FFTW wisdom file locking was only taking place from gr::fft::fft_complex.
Generalise lock init and also enable it from 'fft_real_fwd' and 'fft_real_rev'.
Diffstat (limited to 'gr-fft')
-rw-r--r-- | gr-fft/lib/fft.cc | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/gr-fft/lib/fft.cc b/gr-fft/lib/fft.cc index 871ad9bcaa..718cd0990f 100644 --- a/gr-fft/lib/fft.cc +++ b/gr-fft/lib/fft.cc @@ -56,7 +56,8 @@ namespace fs = boost::filesystem; namespace gr { namespace fft { static boost::mutex wisdom_thread_mutex; - boost::interprocess::file_lock wisdom_lock; + boost::interprocess::file_lock wisdom_lock; + static bool wisdom_lock_init_done = false; // Modify while holding 'wisdom_thread_mutex' gr_complex * malloc_complex(int size) @@ -99,15 +100,36 @@ namespace gr { } static void + wisdom_lock_init() + { + if (wisdom_lock_init_done) + return; + + const std::string wisdom_lock_file = wisdom_filename() + ".lock"; + // std::cerr << "Creating FFTW wisdom lockfile: " << wisdom_lock_file << std::endl; + int fd = open(wisdom_lock_file.c_str(), + O_WRONLY | O_CREAT | O_NOCTTY | O_NONBLOCK, + 0666); + if (fd < 0) { + throw std::runtime_error("Failed to create FFTW wisdom lockfile: " + wisdom_lock_file); + } + close(fd); + wisdom_lock = boost::interprocess::file_lock(wisdom_lock_file.c_str()); + wisdom_lock_init_done = true; + } + + static void lock_wisdom() { - wisdom_thread_mutex.lock(); - wisdom_lock.lock(); + wisdom_thread_mutex.lock(); + wisdom_lock_init(); + wisdom_lock.lock(); } static void unlock_wisdom() { + // Assumes 'lock_wisdom' has already been called (i.e. this file_lock is valid) wisdom_lock.unlock(); wisdom_thread_mutex.unlock(); } @@ -163,15 +185,6 @@ namespace gr { { // Hold global mutex during plan construction and destruction. planner::scoped_lock lock(planner::mutex()); - const std::string wisdom_lock_file = wisdom_filename() + ".lock"; - int fd = open(wisdom_lock_file.c_str(), - O_WRONLY | O_CREAT | O_NOCTTY | O_NONBLOCK, - 0666); - if (fd < 0) { - throw std::exception(); - } - close(fd); - wisdom_lock = boost::interprocess::file_lock(wisdom_lock_file.c_str()); assert (sizeof (fftwf_complex) == sizeof (gr_complex)); |