Update of /cvsroot/xine/xine-lib/src/xine-engine
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv5900/src/xine-engine

Modified Files:
        scratch.c scratch.h xine.c xine_internal.h 
Log Message:
Lock the log buffer while updating it.

Index: scratch.c
===================================================================
RCS file: /cvsroot/xine/xine-lib/src/xine-engine/scratch.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- scratch.c   18 Oct 2006 18:46:17 -0000      1.22
+++ scratch.c   13 Dec 2006 18:30:30 -0000      1.23
@@ -47,6 +47,8 @@
   struct tm tm;
   size_t l;
 
+  pthread_mutex_lock (&this->lock);
+
   time (&t);
   localtime_r (&t, &tm);
 
@@ -61,37 +63,46 @@
 
   lprintf ("printing format %s to line %d\n", format, this->cur);
   this->cur = (this->cur + 1) % this->num_lines;
+
+  pthread_mutex_unlock (&this->lock);
 }
 
 static const char **scratch_get_content (scratch_buffer_t *this) {
   int i, j;
 
+  pthread_mutex_lock (&this->lock);
+
   for(i = 0, j = (this->cur - 1); i < this->num_lines; i++, j--) {
 
     if(j < 0)
       j = (this->num_lines - 1);
 
-    this->ordered[i] = this->lines[j];
+    free (this->ordered[i]);
+    this->ordered[i] = this->lines[j] ? strdup (this->lines[j]) : NULL;
     lprintf ("line %d contains >%s<\n", i , this->lines[j]);
   }
 
+  pthread_mutex_unlock (&this->lock);
   return this->ordered;
 
 }
 
 static void scratch_dispose (scratch_buffer_t *this) {
-  char *mem;
   int   i;
   
-  mem = (char *) this->lines[0];
-  
+  pthread_mutex_lock (&this->lock);
+
   for(i = 0; i < this->num_lines; i++ ) {
+    free(this->ordered[i]);
     free(this->lines[i]);
-    this->lines[i] = NULL;
   }
   
   free (this->lines);
   free (this->ordered);
+
+  pthread_mutex_unlock (&this->lock);
+  pthread_mutex_destroy (&this->lock);
+
   free (this);
 }
 
@@ -104,16 +115,15 @@
   this->lines   = xine_xmalloc (sizeof (char *) * (num_lines + 1));
   this->ordered = xine_xmalloc (sizeof (char *) * (num_lines + 1));
 
-  for (i = 0; i < num_lines; i++)
-    this->lines[i] = NULL;
+  for (i = 0; i <= num_lines; i++)
+    this->lines[i] = this->ordered[i] = NULL;
 
-  this->ordered[i]     = NULL;
-  this->lines[i]       = NULL;
   this->scratch_printf = scratch_printf;
   this->get_content    = scratch_get_content;
   this->dispose        = scratch_dispose;
   this->num_lines      = num_lines;
   this->cur            = 0;
+  pthread_mutex_init (&this->lock, NULL);
 
   return this;
 }

Index: scratch.h
===================================================================
RCS file: /cvsroot/xine/xine-lib/src/xine-engine/scratch.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- scratch.h   26 Sep 2006 05:19:49 -0000      1.11
+++ scratch.h   13 Dec 2006 18:30:30 -0000      1.12
@@ -27,6 +27,7 @@
 #define HAVE_SCRATCH_H
 
 #include <stdarg.h>
+#include <pthread.h>
 
 typedef struct scratch_buffer_s scratch_buffer_t;
 
@@ -50,6 +51,7 @@
   int            num_lines;
   int            cur;
 
+  pthread_mutex_t lock;
 };
 
 scratch_buffer_t *_x_new_scratch_buffer (int num_lines) XINE_PROTECTED;

Index: xine.c
===================================================================
RCS file: /cvsroot/xine/xine-lib/src/xine-engine/xine.c,v
retrieving revision 1.335
retrieving revision 1.336
diff -u -r1.335 -r1.336
--- xine.c      16 Oct 2006 22:18:24 -0000      1.335
+++ xine.c      13 Dec 2006 18:30:30 -0000      1.336
@@ -1604,9 +1604,10 @@
   this->streams = xine_list_new();
 
   /*
-   * streams lock
+   * locks
    */
   pthread_mutex_init (&this->streams_lock, NULL);
+  pthread_mutex_init (&this->log_lock, NULL);
   
   /*
    * start metronom clock
@@ -1951,12 +1952,21 @@
   return log_sections;
 }
 
+static inline void check_log_alloc (xine_t *this, int buf)
+{
+  pthread_mutex_lock (&this->log_lock);
+
+  if ( ! this->log_buffers[buf] )
+    this->log_buffers[buf] = _x_new_scratch_buffer(150);
+
+  pthread_mutex_unlock (&this->log_lock);
+}
+
 void xine_log (xine_t *this, int buf, const char *format, ...) {
   va_list argp;
   char    buffer[SCRATCH_LINE_LEN_MAX];
   
-  if ( ! this->log_buffers[buf] )
-    this->log_buffers[buf] = _x_new_scratch_buffer(150);
+  check_log_alloc (this, buf);
 
   va_start (argp, format);
   this->log_buffers[buf]->scratch_printf (this->log_buffers[buf], format, 
argp);
@@ -1973,8 +1983,7 @@
 void xine_vlog(xine_t *this, int buf, const char *format, 
                 va_list args)
 {
-  if ( ! this->log_buffers[buf] )
-    this->log_buffers[buf] = _x_new_scratch_buffer(150);
+  check_log_alloc (this, buf);
 
   this->log_buffers[buf]->scratch_printf(this->log_buffers[buf], format, args);
 }

Index: xine_internal.h
===================================================================
RCS file: /cvsroot/xine/xine-lib/src/xine-engine/xine_internal.h,v
retrieving revision 1.179
retrieving revision 1.180
diff -u -r1.179 -r1.180
--- xine_internal.h     2 Oct 2006 15:56:06 -0000       1.179
+++ xine_internal.h     13 Dec 2006 18:30:30 -0000      1.180
@@ -118,6 +118,7 @@
 
 #ifdef XINE_ENGINE_INTERNAL
   xine_ticket_t             *port_ticket;
+  pthread_mutex_t            log_lock;
 #endif
 };
 


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Xine-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/xine-cvslog

Reply via email to