/* -*- c++ -*- */
/*
- * Copyright 2003 Free Software Foundation, Inc.
+ * Copyright 2003,2008 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
#include <cassert>
#include <stdexcept>
+
+boost::mutex &
+gri_fft_planner::mutex()
+{
+ static boost::mutex s_planning_mutex;
+
+ return s_planning_mutex;
+}
+
static char *
wisdom_filename ()
{
- static char *filename = ".gr_fftw_wisdom";
+ static const char *filename = ".gr_fftw_wisdom";
char *home = getenv ("HOME");
if (home){
gri_fft_complex::gri_fft_complex (int fft_size, bool forward)
{
+ // Hold global mutex during plan construction and destruction.
+ gri_fft_planner::scoped_lock lock(gri_fft_planner::mutex());
+
assert (sizeof (fftwf_complex) == sizeof (gr_complex));
if (fft_size <= 0)
throw std::runtime_error ("fftwf_malloc");
}
- // FIXME If there's ever a chance that the planning functions
- // will be called in multiple threads, we've got to ensure single
- // threaded access. They are not thread-safe.
-
gri_fftw_import_wisdom (); // load prior wisdom from disk
d_plan = fftwf_plan_dft_1d (fft_size,
reinterpret_cast<fftwf_complex *>(d_inbuf),
gri_fft_complex::~gri_fft_complex ()
{
+ // Hold global mutex during plan construction and destruction.
+ gri_fft_planner::scoped_lock lock(gri_fft_planner::mutex());
+
fftwf_destroy_plan ((fftwf_plan) d_plan);
fftwf_free (d_inbuf);
fftwf_free (d_outbuf);
gri_fft_real_fwd::gri_fft_real_fwd (int fft_size)
{
+ // Hold global mutex during plan construction and destruction.
+ gri_fft_planner::scoped_lock lock(gri_fft_planner::mutex());
+
assert (sizeof (fftwf_complex) == sizeof (gr_complex));
if (fft_size <= 0)
throw std::runtime_error ("fftwf_malloc");
}
- // FIXME If there's ever a chance that the planning functions
- // will be called in multiple threads, we've got to ensure single
- // threaded access. They are not thread-safe.
-
gri_fftw_import_wisdom (); // load prior wisdom from disk
d_plan = fftwf_plan_dft_r2c_1d (fft_size,
d_inbuf,
gri_fft_real_fwd::~gri_fft_real_fwd ()
{
+ // Hold global mutex during plan construction and destruction.
+ gri_fft_planner::scoped_lock lock(gri_fft_planner::mutex());
+
fftwf_destroy_plan ((fftwf_plan) d_plan);
fftwf_free (d_inbuf);
fftwf_free (d_outbuf);
gri_fft_real_rev::gri_fft_real_rev (int fft_size)
{
+ // Hold global mutex during plan construction and destruction.
+ gri_fft_planner::scoped_lock lock(gri_fft_planner::mutex());
+
assert (sizeof (fftwf_complex) == sizeof (gr_complex));
if (fft_size <= 0)