diff options
author | Darren Salt <linux@youmustbejoking.demon.co.uk> | 2006-12-13 18:30:30 +0000 |
---|---|---|
committer | Darren Salt <linux@youmustbejoking.demon.co.uk> | 2006-12-13 18:30:30 +0000 |
commit | 952847b799797174c03ad074f5651210f1c6ebb2 (patch) | |
tree | bf7d654e9cb6289cb225596bf8eb3c3341bcb261 | |
parent | b3dfbb54c0dd53f0da0c6c2672562c646e6cdda6 (diff) | |
download | xine-lib-952847b799797174c03ad074f5651210f1c6ebb2.tar.gz xine-lib-952847b799797174c03ad074f5651210f1c6ebb2.tar.bz2 |
Lock the log buffer while updating it.
CVS patchset: 8411
CVS date: 2006/12/13 18:30:30
-rw-r--r-- | src/xine-engine/scratch.c | 30 | ||||
-rw-r--r-- | src/xine-engine/scratch.h | 4 | ||||
-rw-r--r-- | src/xine-engine/xine.c | 21 | ||||
-rw-r--r-- | src/xine-engine/xine_internal.h | 3 |
4 files changed, 40 insertions, 18 deletions
diff --git a/src/xine-engine/scratch.c b/src/xine-engine/scratch.c index eac5eee63..d750a8a07 100644 --- a/src/xine-engine/scratch.c +++ b/src/xine-engine/scratch.c @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * - * $Id: scratch.c,v 1.22 2006/10/18 18:46:17 hadess Exp $ + * $Id: scratch.c,v 1.23 2006/12/13 18:30:30 dsalt Exp $ * * top-level xine functions * @@ -47,6 +47,8 @@ static void __attribute__((__format__(__printf__, 2, 0))) struct tm tm; size_t l; + pthread_mutex_lock (&this->lock); + time (&t); localtime_r (&t, &tm); @@ -61,37 +63,46 @@ static void __attribute__((__format__(__printf__, 2, 0))) 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 @@ scratch_buffer_t *_x_new_scratch_buffer (int num_lines) { 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; } diff --git a/src/xine-engine/scratch.h b/src/xine-engine/scratch.h index d23d68503..719a9f8d9 100644 --- a/src/xine-engine/scratch.h +++ b/src/xine-engine/scratch.h @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * - * $Id: scratch.h,v 1.11 2006/09/26 05:19:49 dgp85 Exp $ + * $Id: scratch.h,v 1.12 2006/12/13 18:30:30 dsalt Exp $ * * scratch buffer for log output * @@ -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 @@ struct scratch_buffer_s { int num_lines; int cur; + pthread_mutex_t lock; }; scratch_buffer_t *_x_new_scratch_buffer (int num_lines) XINE_PROTECTED; diff --git a/src/xine-engine/xine.c b/src/xine-engine/xine.c index 78476a768..2440e2d95 100644 --- a/src/xine-engine/xine.c +++ b/src/xine-engine/xine.c @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * - * $Id: xine.c,v 1.335 2006/10/16 22:18:24 valtri Exp $ + * $Id: xine.c,v 1.336 2006/12/13 18:30:30 dsalt Exp $ */ /* @@ -1604,9 +1604,10 @@ void xine_init (xine_t *this) { 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 @@ const char *const *xine_get_log_names (xine_t *this) { 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_log (xine_t *this, int buf, const char *format, ...) { 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); } diff --git a/src/xine-engine/xine_internal.h b/src/xine-engine/xine_internal.h index 8ee5d8219..e25339c46 100644 --- a/src/xine-engine/xine_internal.h +++ b/src/xine-engine/xine_internal.h @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * - * $Id: xine_internal.h,v 1.179 2006/10/02 15:56:06 valtri Exp $ + * $Id: xine_internal.h,v 1.180 2006/12/13 18:30:30 dsalt Exp $ * */ @@ -118,6 +118,7 @@ struct xine_s { #ifdef XINE_ENGINE_INTERNAL xine_ticket_t *port_ticket; + pthread_mutex_t log_lock; #endif }; |