[xiph-cvs] cvs commit: vorbis-tools/ogg123 buffer.c status.c

Stan Seibert volsung at xiph.org
Tue Dec 18 18:07:53 PST 2001



volsung     01/12/18 18:07:52

  Modified:    ogg123   Tag: volsung_kc_20011011 buffer.c status.c
  Log:
  Need to make sure I don't leave mutexes locked when we cancel threads.
  Fixed some style bugs.

Revision  Changes    Path
No                   revision

No                   revision

1.7.2.23.2.12 +20 -19    vorbis-tools/ogg123/buffer.c

Index: buffer.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/buffer.c,v
retrieving revision 1.7.2.23.2.11
retrieving revision 1.7.2.23.2.12
diff -u -r1.7.2.23.2.11 -r1.7.2.23.2.12
--- buffer.c	2001/12/19 01:34:26	1.7.2.23.2.11
+++ buffer.c	2001/12/19 02:07:51	1.7.2.23.2.12
@@ -11,7 +11,7 @@
  *                                                                  *
  ********************************************************************
 
- last mod: $Id: buffer.c,v 1.7.2.23.2.11 2001/12/19 01:34:26 volsung Exp $
+ last mod: $Id: buffer.c,v 1.7.2.23.2.12 2001/12/19 02:07:51 volsung Exp $
 
  ********************************************************************/
 
@@ -71,11 +71,11 @@
   DEBUG("Enter buffer_thread_init");
 
   /* Block signals to this thread */
-  sigfillset (&set);
-  sigaddset (&set, SIGINT);
-  sigaddset (&set, SIGTSTP);
-  sigaddset (&set, SIGCONT);
-  if (pthread_sigmask (SIG_BLOCK, &set, NULL) != 0)
+  sigfillset(&set);
+  sigaddset(&set, SIGINT);
+  sigaddset(&set, SIGTSTP);
+  sigaddset(&set, SIGCONT);
+  if (pthread_sigmask(SIG_BLOCK, &set, NULL) != 0)
     DEBUG("pthread_sigmask failed");
 }
 
@@ -87,9 +87,10 @@
   DEBUG("Enter buffer_thread_cleanup");
 
   /* Cleanup thread data structures */
-  pthread_mutex_destroy (&buf->mutex);
-  pthread_cond_destroy (&buf->playback_cond);
-  pthread_cond_destroy (&buf->write_cond);
+  pthread_mutex_unlock(&buf->mutex);
+  pthread_mutex_destroy(&buf->mutex);
+  pthread_cond_destroy(&buf->playback_cond);
+  pthread_cond_destroy(&buf->write_cond);
 }
 
 
@@ -365,9 +366,9 @@
   buf->write_arg = arg;
 
   /* Setup pthread variables */
-  pthread_mutex_init (&buf->mutex, NULL);
-  pthread_cond_init (&buf->write_cond, NULL);
-  pthread_cond_init (&buf->playback_cond, NULL);
+  pthread_mutex_init(&buf->mutex, NULL);
+  pthread_cond_init(&buf->write_cond, NULL);
+  pthread_cond_init(&buf->playback_cond, NULL);
   
   /* Correct for impossible chunk sizes */
   if (audio_chunk_size > size || audio_chunk_size == 0)
@@ -392,14 +393,14 @@
   action_t *action;
 
   /* Cleanup pthread variables */
-  pthread_mutex_destroy (&buf->mutex);
-  pthread_cond_destroy (&buf->write_cond);
-  pthread_cond_destroy (&buf->playback_cond);
+  pthread_mutex_destroy(&buf->mutex);
+  pthread_cond_destroy(&buf->write_cond);
+  pthread_cond_destroy(&buf->playback_cond);
   
   /* Reinit pthread variables */
-  pthread_mutex_init (&buf->mutex, NULL);
-  pthread_cond_init (&buf->write_cond, NULL);
-  pthread_cond_init (&buf->playback_cond, NULL);
+  pthread_mutex_init(&buf->mutex, NULL);
+  pthread_cond_init(&buf->write_cond, NULL);
+  pthread_cond_init(&buf->playback_cond, NULL);
 
   /* Clear old actions */
   while (buf->actions != NULL) {
@@ -463,7 +464,7 @@
   /* Signal all the playback condition to wake stuff up */
   COND_SIGNAL(buf->playback_cond);
 
-  pthread_join (buf->thread, NULL);
+  pthread_join(buf->thread, NULL);
 
   buffer_thread_cleanup(buf);
 

1.1.2.7.2.9 +31 -8     vorbis-tools/ogg123/Attic/status.c

Index: status.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/Attic/status.c,v
retrieving revision 1.1.2.7.2.8
retrieving revision 1.1.2.7.2.9
diff -u -r1.1.2.7.2.8 -r1.1.2.7.2.9
--- status.c	2001/12/14 05:45:14	1.1.2.7.2.8
+++ status.c	2001/12/19 02:07:52	1.1.2.7.2.9
@@ -11,7 +11,7 @@
  *                                                                  *
  ********************************************************************
 
- last mod: $Id: status.c,v 1.1.2.7.2.8 2001/12/14 05:45:14 volsung Exp $
+ last mod: $Id: status.c,v 1.1.2.7.2.9 2001/12/19 02:07:52 volsung Exp $
 
  ********************************************************************/
 
@@ -30,6 +30,12 @@
 
 /* ------------------- Private functions ------------------ */
 
+void unlock_output_lock (void *arg)
+{
+  pthread_mutex_unlock(&output_lock);
+}
+
+
 void write_buffer_state_string (char *dest, buffer_stats_t *buf_stats)
 {
   char *cur = dest;
@@ -311,11 +317,13 @@
 
 void status_clear_line ()
 {
-  pthread_mutex_lock(&output_lock);
+  pthread_cleanup_push(unlock_output_lock, NULL);
 
+  pthread_mutex_lock(&output_lock);
   clear_line(last_line_len);
-
   pthread_mutex_unlock(&output_lock);
+
+  pthread_cleanup_pop(0);
 }
 
 void status_print_statistics (stat_format_t *stats,
@@ -323,11 +331,12 @@
                               data_source_stats_t *transport_statistics,
                               decoder_stats_t *decoder_statistics)
 {
+  pthread_cleanup_push(unlock_output_lock, NULL);
 
   /* Updating statistics is not critical.  If another thread is
      already doing output, we skip it. */
   if (pthread_mutex_trylock(&output_lock) == 0) {
-
+    
     if (decoder_statistics != NULL) {
       /* Current playback time */
       write_time_string(stats[1].arg.stringarg,
@@ -375,6 +384,8 @@
 
     pthread_mutex_unlock(&output_lock);
   }
+
+  pthread_cleanup_pop(0);
 }
 
 
@@ -385,6 +396,8 @@
   if (verbosity > max_verbosity)
     return;
 
+  pthread_cleanup_push(unlock_output_lock, NULL);
+
   pthread_mutex_lock(&output_lock);
 
   va_start (ap, fmt);
@@ -392,6 +405,8 @@
   va_end (ap);
 
   pthread_mutex_unlock(&output_lock);
+
+  pthread_cleanup_pop(0);
 }
 
 
@@ -400,11 +415,15 @@
   if (verbosity > max_verbosity)
     return;
 
+  pthread_cleanup_push(unlock_output_lock, NULL);
+
   pthread_mutex_lock(&output_lock);
 
   vstatus_print_nolock(fmt, ap);
 
   pthread_mutex_unlock(&output_lock);
+
+  pthread_cleanup_pop(0);
 }
 
 
@@ -412,21 +431,25 @@
 {
   va_list ap;
 
-  pthread_mutex_lock(&output_lock);
+  pthread_cleanup_push(unlock_output_lock, NULL);
 
+  pthread_mutex_lock(&output_lock);
   va_start (ap, fmt);
   vstatus_print_nolock (fmt, ap);
   va_end (ap);
-
   pthread_mutex_unlock(&output_lock);
+
+  pthread_cleanup_pop(0);
 }
 
 
 void vstatus_error (const char *fmt, va_list ap)
 {
-  pthread_mutex_lock(&output_lock);
+  pthread_cleanup_push(unlock_output_lock, NULL);
 
+  pthread_mutex_lock(&output_lock);
   vstatus_print_nolock (fmt, ap);
-
   pthread_mutex_unlock(&output_lock);
+
+  pthread_cleanup_pop(0);
 }

--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list