/* * debug_mutex.h: debugging wrappers for pthread_mutex_ functions * * See the main source file 'xineliboutput.c' for copyright information and * how to reach the author. * * $Id: debug_mutex.h,v 1.3 2007-03-14 11:50:08 phintuka Exp $ * */ #ifndef DEBUG_MUTEX_H #define DEBUG_MUTEX_H #ifndef _PTHREAD_H # error pthread.h must be included before debug_mutex.h #endif /* * Override pthread_mutex_ calls: * * Change type of each mutex to PTHREAD_MUTEX_ERRORCHECK_NP * * Store line number of last succeed pthread_mutex_lock call * for each initialized mutex * * Check every pthread_mutex_ call for errors and log all errors * * To help detecting deadlocks and minimize logging: * - Try locking first in pthread_mutex_lock * - If pthread_mutex_trylock fails, log a message and retry. * - When trylock failed, log another message when lock is acquired. * * * NOTE: debugging itself is not thread-safe and may indicate wrong line numbers ! * */ #define MAX_DBG_MUTEX 64 static struct { pthread_mutex_t *lock; int line; int tid; } dbgdata[MAX_DBG_MUTEX+1] = {{NULL,0}}; static void dbg_setdata(pthread_mutex_t *mutex, int line) { int i; for(i=0; i