commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r9205 - gnuradio/branches/features/mp-sched/gnuradio-c


From: eb
Subject: [Commit-gnuradio] r9205 - gnuradio/branches/features/mp-sched/gnuradio-core/src/lib/general
Date: Thu, 7 Aug 2008 14:57:16 -0600 (MDT)

Author: eb
Date: 2008-08-07 14:57:15 -0600 (Thu, 07 Aug 2008)
New Revision: 9205

Modified:
   gnuradio/branches/features/mp-sched/gnuradio-core/src/lib/general/gri_fft.cc
Log:
Thread safety fix for FFTW plan construction and destruction.



Modified: 
gnuradio/branches/features/mp-sched/gnuradio-core/src/lib/general/gri_fft.cc
===================================================================
--- 
gnuradio/branches/features/mp-sched/gnuradio-core/src/lib/general/gri_fft.cc    
    2008-08-07 20:51:49 UTC (rev 9204)
+++ 
gnuradio/branches/features/mp-sched/gnuradio-core/src/lib/general/gri_fft.cc    
    2008-08-07 20:57:15 UTC (rev 9205)
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2003 Free Software Foundation, Inc.
+ * Copyright 2003,2008 Free Software Foundation, Inc.
  * 
  * This file is part of GNU Radio
  * 
@@ -28,7 +28,12 @@
 #include <stdio.h>
 #include <cassert>
 #include <stdexcept>
+#include <boost/thread.hpp>
 
+typedef boost::mutex::scoped_lock scoped_lock;
+static boost::mutex  s_planning_mutex;
+
+
 static char *
 wisdom_filename ()
 {
@@ -80,6 +85,9 @@
 
 gri_fft_complex::gri_fft_complex (int fft_size, bool forward)
 {
+  // Hold global mutex during plan construction and destruction.
+  scoped_lock  lock(s_planning_mutex);
+
   assert (sizeof (fftwf_complex) == sizeof (gr_complex));
   
   if (fft_size <= 0)
@@ -96,10 +104,6 @@
     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), 
@@ -116,6 +120,9 @@
 
 gri_fft_complex::~gri_fft_complex ()
 {
+  // Hold global mutex during plan construction and destruction.
+  scoped_lock  lock(s_planning_mutex);
+
   fftwf_destroy_plan ((fftwf_plan) d_plan);
   fftwf_free (d_inbuf);
   fftwf_free (d_outbuf);
@@ -131,6 +138,9 @@
 
 gri_fft_real_fwd::gri_fft_real_fwd (int fft_size)
 {
+  // Hold global mutex during plan construction and destruction.
+  scoped_lock  lock(s_planning_mutex);
+
   assert (sizeof (fftwf_complex) == sizeof (gr_complex));
   
   if (fft_size <= 0)
@@ -147,10 +157,6 @@
     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,
@@ -166,6 +172,9 @@
 
 gri_fft_real_fwd::~gri_fft_real_fwd ()
 {
+  // Hold global mutex during plan construction and destruction.
+  scoped_lock  lock(s_planning_mutex);
+
   fftwf_destroy_plan ((fftwf_plan) d_plan);
   fftwf_free (d_inbuf);
   fftwf_free (d_outbuf);





reply via email to

[Prev in Thread] Current Thread [Next in Thread]