summaryrefslogtreecommitdiff
path: root/gr-fft
diff options
context:
space:
mode:
authorJohnathan Corgan <johnathan@corganlabs.com>2017-06-07 11:55:44 -0700
committerJohnathan Corgan <johnathan@corganlabs.com>2017-06-07 11:55:44 -0700
commit37d373acee2112b0bb350e5abe09aca0115e5cc6 (patch)
treebc6388920d54aef04d9894698a6273274abdb738 /gr-fft
parent0e32fcaf928e8f3f9161a619201d3cf253a46ded (diff)
parentb57a37f7c676542f08a27d3f141f4d9ed2ab1132 (diff)
Merge branch 'maint'
Diffstat (limited to 'gr-fft')
-rw-r--r--gr-fft/lib/fft.cc32
1 files changed, 32 insertions, 0 deletions
diff --git a/gr-fft/lib/fft.cc b/gr-fft/lib/fft.cc
index 5af77d97eb..ef81583187 100644
--- a/gr-fft/lib/fft.cc
+++ b/gr-fft/lib/fft.cc
@@ -46,10 +46,12 @@ static int my_fftw_read_char(void *f) { return fgetc((FILE *) f); }
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/path.hpp>
+#include <boost/interprocess/sync/file_lock.hpp>
namespace fs = boost::filesystem;
namespace gr {
namespace fft {
+ static boost::mutex wisdom_thread_mutex;
gr_complex *
malloc_complex(int size)
@@ -92,6 +94,30 @@ namespace gr {
}
static void
+ lock_wisdom()
+ {
+ 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();
+ }
+ boost::interprocess::file_lock wisdom_lock(wisdom_lock_file.c_str());
+ wisdom_lock.lock();
+ wisdom_thread_mutex.lock();
+ }
+
+ static void
+ unlock_wisdom()
+ {
+ const std::string wisdom_lock_file = wisdom_filename() + ".lock";
+ boost::interprocess::file_lock wisdom_lock(wisdom_lock_file.c_str());
+ wisdom_lock.unlock();
+ wisdom_thread_mutex.unlock();
+ }
+
+ static void
import_wisdom()
{
const std::string filename = wisdom_filename ();
@@ -162,6 +188,7 @@ namespace gr {
d_nthreads = nthreads;
config_threading(nthreads);
+ lock_wisdom();
import_wisdom(); // load prior wisdom from disk
d_plan = fftwf_plan_dft_1d (fft_size,
@@ -175,6 +202,7 @@ namespace gr {
throw std::runtime_error ("fftwf_plan_dft_1d failed");
}
export_wisdom(); // store new wisdom to disk
+ unlock_wisdom();
}
fft_complex::~fft_complex()
@@ -233,6 +261,7 @@ namespace gr {
d_nthreads = nthreads;
config_threading(nthreads);
+ lock_wisdom();
import_wisdom(); // load prior wisdom from disk
d_plan = fftwf_plan_dft_r2c_1d (fft_size,
@@ -245,6 +274,7 @@ namespace gr {
throw std::runtime_error ("fftwf_plan_dft_r2c_1d failed");
}
export_wisdom(); // store new wisdom to disk
+ unlock_wisdom();
}
fft_real_fwd::~fft_real_fwd()
@@ -303,6 +333,7 @@ namespace gr {
d_nthreads = nthreads;
config_threading(nthreads);
+ lock_wisdom();
import_wisdom(); // load prior wisdom from disk
// FIXME If there's ever a chance that the planning functions
@@ -318,6 +349,7 @@ namespace gr {
throw std::runtime_error ("fftwf_plan_dft_c2r_1d failed");
}
export_wisdom (); // store new wisdom to disk
+ unlock_wisdom();
}
fft_real_rev::~fft_real_rev ()