From: Mike Brady Date: Mon, 19 Nov 2018 20:12:57 +0000 (+0000) Subject: Add the sort-of mutex name to the debug_mutex_lock and _unlock. Also, setting the... X-Git-Tag: 3.3RC0~166 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f7342a70dff4af9a0759fb464b1e21138b2c45fa;p=thirdparty%2Fshairport-sync.git Add the sort-of mutex name to the debug_mutex_lock and _unlock. Also, setting the debug level to 0 turns off the debug logging of them. Handy. --- diff --git a/common.c b/common.c index e0a35b8d..df460bc8 100644 --- a/common.c +++ b/common.c @@ -1143,9 +1143,9 @@ int sps_pthread_mutex_timedlock(pthread_mutex_t *mutex, useconds_t dally_time, } #endif -int _debug_mutex_lock(pthread_mutex_t *mutex, useconds_t dally_time, const char *filename, +int _debug_mutex_lock(pthread_mutex_t *mutex, useconds_t dally_time, const char *mutexname, const char *filename, const int line, int debuglevel) { - if (debuglevel > debuglev) + if ((debuglevel > debuglev) || (debuglevel == 0)) return pthread_mutex_lock(mutex); int oldState; pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldState); @@ -1153,7 +1153,7 @@ int _debug_mutex_lock(pthread_mutex_t *mutex, useconds_t dally_time, const char char dstring[1000]; memset(dstring, 0, sizeof(dstring)); snprintf(dstring, sizeof(dstring), "%s:%d", filename, line); - debug(3, "debug_mutex_lock at \"%s\".", dstring); + debug(3, "mutex_lock \"%s\" at \"%s\".", mutexname, dstring); int result = sps_pthread_mutex_timedlock(mutex, dally_time, dstring, debuglevel); if (result == ETIMEDOUT) { result = pthread_mutex_lock(mutex); @@ -1161,16 +1161,16 @@ int _debug_mutex_lock(pthread_mutex_t *mutex, useconds_t dally_time, const char uint64_t divisor = (uint64_t)1 << 32; double delay = 1.0 * time_delay / divisor; debug(debuglevel, - "debug_mutex_lock at \"%s\" expected max wait: %0.9f, actual wait: %0.9f sec.", dstring, + "mutex_lock \"%s\" at \"%s\" expected max wait: %0.9f, actual wait: %0.9f sec.", mutexname, dstring, (1.0 * dally_time) / 1000000, delay); } pthread_setcancelstate(oldState,NULL); return result; } -int _debug_mutex_unlock(pthread_mutex_t *mutex, const char *filename, const int line, +int _debug_mutex_unlock(pthread_mutex_t *mutex, const char *mutexname, const char *filename, const int line, int debuglevel) { - if (debuglevel > debuglev) + if ((debuglevel > debuglev) || (debuglevel == 0)) return pthread_mutex_unlock(mutex); int oldState; pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldState); @@ -1178,11 +1178,11 @@ int _debug_mutex_unlock(pthread_mutex_t *mutex, const char *filename, const int char errstr[512]; memset(dstring, 0, sizeof(dstring)); snprintf(dstring, sizeof(dstring), "%s:%d", filename, line); - debug(debuglevel, "debug_mutex_unlock at \"%s\".", dstring); + debug(debuglevel, "mutex_unlock \"%s\" at \"%s\".", mutexname, dstring); int r = pthread_mutex_unlock(mutex); if (r != 0) - debug(1, "error %d: \"%s\" unlocking a mutex: \"%s\".", r, - strerror_r(r, errstr, sizeof(errstr)), dstring); + debug(1, "error %d: \"%s\" unlocking mutex \"%s\" at \"%s\".", r, + strerror_r(r, errstr, sizeof(errstr)), mutexname, dstring); pthread_setcancelstate(oldState,NULL); return r; } diff --git a/common.h b/common.h index 81aab4cb..2fec4c26 100644 --- a/common.h +++ b/common.h @@ -299,20 +299,20 @@ int sps_pthread_mutex_timedlock(pthread_mutex_t *mutex, useconds_t dally_time, const char *debugmessage, int debuglevel); // wait for the specified time, checking every 20 milliseconds, and block if it can't acquire the // lock -int _debug_mutex_lock(pthread_mutex_t *mutex, useconds_t dally_time, const char *filename, +int _debug_mutex_lock(pthread_mutex_t *mutex, useconds_t dally_time, const char *mutexName, const char *filename, const int line, int debuglevel); -#define debug_mutex_lock(mu, t, d) _debug_mutex_lock(mu, t, __FILE__, __LINE__, d) +#define debug_mutex_lock(mu, t, d) _debug_mutex_lock(mu, t, #mu , __FILE__, __LINE__, d) -int _debug_mutex_unlock(pthread_mutex_t *mutex, const char *filename, const int line, +int _debug_mutex_unlock(pthread_mutex_t *mutex, const char *mutexName, const char *filename, const int line, int debuglevel); -#define debug_mutex_unlock(mu, d) _debug_mutex_unlock(mu, __FILE__, __LINE__, d) +#define debug_mutex_unlock(mu, d) _debug_mutex_unlock(mu, #mu, __FILE__, __LINE__, d) void pthread_cleanup_debug_mutex_unlock(void *arg); #define pthread_cleanup_debug_mutex_lock(mu, t, d) \ - if (_debug_mutex_lock(mu, t, __FILE__, __LINE__, d) == 0) \ + if (_debug_mutex_lock(mu, t, #mu, __FILE__, __LINE__, d) == 0) \ pthread_cleanup_push(pthread_cleanup_debug_mutex_unlock, (void *)mu) char *get_version_string(); // mallocs a string space -- remember to free it afterwards