From 83cf2897f3069dee94549da7ace743b7303df2e7 Mon Sep 17 00:00:00 2001 From: waker Date: Sat, 14 May 2011 20:01:33 +0200 Subject: fixed several pl_lock race conditions in streamer; added assertion to catch this kind of race conditions, which can be turned on by defining DETECT_PL_LOCK_RC 1 in streamer.c and playlist.c --- playlist.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'playlist.c') diff --git a/playlist.c b/playlist.c index 4fe6ed2d..3ec33ad9 100644 --- a/playlist.c +++ b/playlist.c @@ -52,6 +52,7 @@ #define DISABLE_LOCKING 0 #define DEBUG_LOCKING 0 +//#define DETECT_PL_LOCK_RC 1 // file format revision history // 1.1->1.2 changelog: @@ -164,14 +165,21 @@ pl_free (void) { } #if DEBUG_LOCKING -int pl_lock_cnt = 0; +volatile int pl_lock_cnt = 0; +#endif +#if DETECT_PL_LOCK_RC +static pthread_t tids[1000]; +static int ntids = 0; +pthread_t pl_lock_tid = 0; #endif -//pthread_t pl_lock_tid = 0; void pl_lock (void) { #if !DISABLE_LOCKING mutex_lock (mutex); - //pl_lock_tid = pthread_self(); +#if DETECT_PL_LOCK_RC + pl_lock_tid = pthread_self(); + tids[ntids++] = pl_lock_tid; +#endif #if DEBUG_LOCKING pl_lock_cnt++; @@ -183,6 +191,17 @@ pl_lock (void) { void pl_unlock (void) { #if !DISABLE_LOCKING +#if DETECT_PL_LOCK_RC + if (ntids > 0) { + ntids--; + } + if (ntids > 0) { + pl_lock_tid = tids[ntids-1]; + } + else { + pl_lock_tid = 0; + } +#endif mutex_unlock (mutex); #if DEBUG_LOCKING pl_lock_cnt--; -- cgit v1.2.3