From 816d87e1d38dc0fecbe1fa47794b2d7a18d2e321 Mon Sep 17 00:00:00 2001 From: waker Date: Thu, 17 May 2012 20:50:47 +0200 Subject: fixed many calls to pl_find_meta[_raw] being called without pl_lock; added debug pl_ensure_lock function which asserts when pl_lock is not set when it is required; added new API functions for thread-safe metadata access --- playlist.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'playlist.c') diff --git a/playlist.c b/playlist.c index 11a280c1..d50bff77 100644 --- a/playlist.c +++ b/playlist.c @@ -55,7 +55,7 @@ #define DISABLE_LOCKING 0 #define DEBUG_LOCKING 0 -//#define DETECT_PL_LOCK_RC 1 +#define DETECT_PL_LOCK_RC 1 // file format revision history // 1.1->1.2 changelog: @@ -186,7 +186,7 @@ pl_lock (void) { #if !DISABLE_LOCKING mutex_lock (mutex); #if DETECT_PL_LOCK_RC - pl_lock_tid = pthread_self(); + pl_lock_tid = pthread_self (); tids[ntids++] = pl_lock_tid; #endif @@ -1170,10 +1170,12 @@ error: playItem_t * plt_insert_cue (playlist_t *plt, playItem_t *after, playItem_t *origin, int numsamples, int samplerate) { trace ("pl_insert_cue numsamples=%d, samplerate=%d\n", numsamples, samplerate); + pl_lock (); const char *fname = pl_find_meta_raw (origin, ":URI"); int len = strlen (fname); char cuename[len+5]; strcpy (cuename, fname); + pl_unlock (); strcpy (cuename+len, ".cue"); DB_FILE *fp = vfs_fopen (cuename); if (!fp) { @@ -3812,3 +3814,17 @@ int plt_is_fast_mode (playlist_t *plt) { return plt->fast_mode; } + +void +pl_ensure_lock (void) { +#if DETECT_PL_LOCK_RC + pthread_t tid = pthread_self (); + for (int i = 0; i < ntids; i++) { + if (tids[i] == tid) { + return; + } + } + fprintf (stderr, "\033[0;31mnon-thread-safe playlist access function was called outside of pl_lock. please make a backtrace and post a bug. thank you.\033[37;0m\n"); + assert(0); +#endif +} -- cgit v1.2.3