diff options
author | waker <wakeroid@gmail.com> | 2012-05-17 20:50:47 +0200 |
---|---|---|
committer | waker <wakeroid@gmail.com> | 2012-05-17 20:50:47 +0200 |
commit | 816d87e1d38dc0fecbe1fa47794b2d7a18d2e321 (patch) | |
tree | 6753620029a94976bf27d474156723dd2f403813 /playlist.c | |
parent | af55e42f2422f8734bc80fb8a58eba80b29937ef (diff) |
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
Diffstat (limited to 'playlist.c')
-rw-r--r-- | playlist.c | 20 |
1 files changed, 18 insertions, 2 deletions
@@ -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 +} |