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

Ralph Giles giles at xiph.org
Tue Jun 24 04:39:37 PDT 2003



giles       03/06/24 07:39:37

  Modified:    ogg123   buffer.c
  Log:
  Switch to fixed number of arguments on separate debug macros. Ugly, but actually portable.

Revision  Changes    Path
1.21      +19 -16    vorbis-tools/ogg123/buffer.c

Index: buffer.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/buffer.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- buffer.c	3 May 2003 14:24:33 -0000	1.20
+++ buffer.c	24 Jun 2003 11:39:37 -0000	1.21
@@ -11,7 +11,7 @@
  *                                                                  *
  ********************************************************************
 
- last mod: $Id: buffer.c,v 1.20 2003/05/03 14:24:33 volsung Exp $
+ last mod: $Id: buffer.c,v 1.21 2003/06/24 11:39:37 giles Exp $
 
  ********************************************************************/
 
@@ -34,20 +34,23 @@
 #define MIN3(x,y,z)    MIN(x,MIN(y,z))
 #define MIN4(w,x,y,z)  MIN( MIN(w,x), MIN(y,z) )
 
-/* Special debugging code.  THIS IS NOT PORTABLE! */
 #ifdef DEBUG_BUFFER
 FILE *debugfile;
-#define DEBUG(x, y...) { fprintf (debugfile, "%d: " x "\n", getpid(),  ## y); }
+#define DEBUG(x) { fprintf (debugfile, "%d: " x "\n", getpid()); }
+#define DEBUG1(x, y) { fprintf (debugfile, "%d: " x "\n", getpid(), y); }
+#define DEBUG2(x, y, z) { fprintf (debugfile, "%d: " x "\n", getpid(), y, z); }
 #else
-#define DEBUG(x, y...)
+#define DEBUG(x)
+#define DEBUG1(x, y)
+#define DEBUG2(x, y, z)
 #endif
 
 /* Macros that support debugging of threading structures */
 
-#define LOCK_MUTEX(mutex) { DEBUG("Locking mutex %s.", #mutex); pthread_mutex_lock (&(mutex)); }
-#define UNLOCK_MUTEX(mutex) { DEBUG("Unlocking mutex %s", #mutex); pthread_mutex_unlock(&(mutex)); }
-#define COND_WAIT(cond, mutex) { DEBUG("Unlocking %s and waiting on %s", #mutex, #cond); pthread_cond_wait(&(cond), &(mutex)); }
-#define COND_SIGNAL(cond) { DEBUG("Signalling %s", #cond); pthread_cond_signal(&(cond)); }
+#define LOCK_MUTEX(mutex) { DEBUG1("Locking mutex %s.", #mutex); pthread_mutex_lock (&(mutex)); }
+#define UNLOCK_MUTEX(mutex) { DEBUG1("Unlocking mutex %s", #mutex); pthread_mutex_unlock(&(mutex)); }
+#define COND_WAIT(cond, mutex) { DEBUG2("Unlocking %s and waiting on %s", #mutex, #cond); pthread_cond_wait(&(cond), &(mutex)); }
+#define COND_SIGNAL(cond) { DEBUG1("Signalling %s", #cond); pthread_cond_signal(&(cond)); }
 
 extern signal_request_t sig_request;  /* Need access to global cancel flag */
 
@@ -238,7 +241,7 @@
  
     /* No need to lock mutex here because the other thread will
        NEVER reduce the number of bytes stored in the buffer */
-    DEBUG("Sending %d bytes to the audio device", write_amount);
+    DEBUG1("Sending %d bytes to the audio device", write_amount);
     write_amount = buf->write_func(buf->buffer + buf->start, write_amount,
                     /* Only set EOS if this is the last chunk */
                     write_amount == buf->curfill ? buf->eos : 0,
@@ -249,7 +252,7 @@
     buf->curfill -= write_amount;
     buf->position += write_amount;
     buf->start = (buf->start + write_amount) % buf->size;
-    DEBUG("Updated buffer fill, curfill = %ld", buf->curfill);
+    DEBUG1("Updated buffer fill, curfill = %ld", buf->curfill);
 
     /* If we've essentially emptied the buffer and prebuffering is enabled,
        we need to do another prebuffering session */
@@ -276,7 +279,7 @@
   long   buf_write_pos; /* offset of first available write location */
   size_t write_size;
 
-  DEBUG("Enter submit_data_chunk, size %d", size);
+  DEBUG1("Enter submit_data_chunk, size %d", size);
 
   pthread_cleanup_push(buffer_mutex_unlock, buf);
 
@@ -301,7 +304,7 @@
       data += write_size;
       size -= write_size;
       buf->position_end += write_size;
-      DEBUG("writing chunk into buffer, curfill = %ld", buf->curfill);
+      DEBUG1("writing chunk into buffer, curfill = %ld", buf->curfill);
     }
     else {
 
@@ -370,7 +373,7 @@
 #endif
 
   /* Initialize the buffer structure. */
-  DEBUG("buffer_create, size = %ld", size);
+  DEBUG1("buffer_create, size = %ld", size);
 
   memset (buf, 0, sizeof(*buf));
 
@@ -555,7 +558,7 @@
 
     /* No need to lock mutex here because the other thread will
        NEVER reduce the number of bytes stored in the buffer */
-    DEBUG("Copying %d bytes from the buffer", write_amount);
+    DEBUG1("Copying %d bytes from the buffer", write_amount);
     memcpy(data, buf->buffer + buf->start, write_amount);
     LOCK_MUTEX(buf->mutex);
 
@@ -563,7 +566,7 @@
     data += write_amount;
     nbytes -= write_amount;
     buf->start = (buf->start + write_amount) % buf->size;
-    DEBUG("Updated buffer fill, curfill = %ld", buf->curfill);
+    DEBUG1("Updated buffer fill, curfill = %ld", buf->curfill);
     
     /* Signal a waiting decoder thread that they can put more
        audio into the buffer */
@@ -738,7 +741,7 @@
   while (!empty) {
 
     if (buf->curfill > 0) {
-      DEBUG("Buffer curfill = %ld, going back to sleep.", buf->curfill);
+      DEBUG1("Buffer curfill = %ld, going back to sleep.", buf->curfill);
       COND_WAIT(buf->write_cond, buf->mutex);
     } else 
       empty = 1;

<p><p>--- >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