On Mon, Dec 12, 2011 at 10:37:35AM -0700, Matt Mills wrote:
> On Mon, Dec 12, 2011 at 3:41 AM, Martin Braun <martin.br...@kit.edu> wrote:
> 
>     * Do you randomly get either segfault or i/o error? I always get the i/o
>      with this code..
>
> I get both.
>  
> 
>     * Your code stresses the WAV-code a lot :) What are you trying to
>      accomplish? Are you finding a bug in wavfile_sink or do you need this
>      behaviour for something? Because you don't need close() if you just
>      want to switch files.
>     * In any case, you're right. It's possible to call close() during work()
>      after do_update() is finished and thus yank the fp out from under our
>      feet. Actually, I can't think of any case where we need to call
>      close() manually--perhaps it should even be private?
>  
> I don't think making close() private is really the right solution. I'm
> recording distinct conversations so having an open() unmute() mute() close()
> sequence per call makes the most sense (if a channel is idle for 20 minutes
> between transmissions then I'm going to have the last wav file open for 20
> minutes; unless I open a temporary file to write nothing to, which just seems
> silly).
Yes, that makes sense. Try this (is the same as what I sent to
patch-gnuradio). It works with your script.

MB


-- 
Karlsruhe Institute of Technology (KIT)
Communications Engineering Lab (CEL)

Dipl.-Ing. Martin Braun
Research Associate

Kaiserstraße 12
Building 05.01
76131 Karlsruhe

Phone: +49 721 608-43790
Fax: +49 721 608-46071
www.cel.kit.edu

KIT -- University of the State of Baden-Württemberg and
National Laboratory of the Helmholtz Association

From dee7e8664410b4337e740b97a2c1b9437fba51d3 Mon Sep 17 00:00:00 2001
From: Martin Braun <martin.br...@kit.edu>
Date: Mon, 12 Dec 2011 18:11:29 +0100
Subject: [PATCH] WAV sink: is now threadsafe; do_update() therefore must be
 private

---
 gnuradio-core/src/lib/io/gr_wavfile_sink.cc |    2 +-
 gnuradio-core/src/lib/io/gr_wavfile_sink.h  |   14 +++++++-------
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/gnuradio-core/src/lib/io/gr_wavfile_sink.cc b/gnuradio-core/src/lib/io/gr_wavfile_sink.cc
index a96aadc..88b2323 100644
--- a/gnuradio-core/src/lib/io/gr_wavfile_sink.cc
+++ b/gnuradio-core/src/lib/io/gr_wavfile_sink.cc
@@ -184,6 +184,7 @@ gr_wavfile_sink::work (int noutput_items,
   
   int nwritten;
   
+  gruel::scoped_lock guard(d_mutex);     // hold mutex for duration of this block
   do_update();	// update: d_fp is reqd
   if (!d_fp)	// drop output on the floor
     return noutput_items;
@@ -254,7 +255,6 @@ gr_wavfile_sink::do_update()
     return;
   }
   
-  gruel::scoped_lock guard(d_mutex);     // hold mutex for duration of this block
   if (d_fp) {
     close_wav();
   }
diff --git a/gnuradio-core/src/lib/io/gr_wavfile_sink.h b/gnuradio-core/src/lib/io/gr_wavfile_sink.h
index 5fd3eaa..6a6b7eb 100644
--- a/gnuradio-core/src/lib/io/gr_wavfile_sink.h
+++ b/gnuradio-core/src/lib/io/gr_wavfile_sink.h
@@ -86,6 +86,13 @@ private:
   short convert_to_short(float sample);
 
   /*!
+   * \brief If any file changes have occurred, update now. This is called
+   * internally by work() and thus doesn't usually need to be called by
+   * hand.
+   */
+  void do_update();
+  
+  /*!
    * \brief Writes information to the WAV header which is not available
    * a-priori (chunk size etc.) and closes the file. Not thread-safe and
    * assumes d_fp is a valid file pointer, should thus only be called by
@@ -108,13 +115,6 @@ public:
   void close();
 
   /*!
-   * \brief If any file changes have occurred, update now. This is called
-   * internally by work() and thus doesn't usually need to be called by
-   * hand.
-   */
-  void do_update();
-  
-  /*!
    * \brief Set the sample rate. This will not affect the WAV file
    * currently opened. Any following open() calls will use this new
    * sample rate.
-- 
1.7.5.4

Attachment: pgpp8l05wT6Kf.pgp
Description: PGP signature

_______________________________________________
Discuss-gnuradio mailing list
Discuss-gnuradio@gnu.org
https://lists.gnu.org/mailman/listinfo/discuss-gnuradio

Reply via email to