Mailing List Archive

r2540 - trunk/varnish-cache/bin/varnishd
Author: phk
Date: 2008-02-26 10:10:35 +0100 (Tue, 26 Feb 2008)
New Revision: 2540

Modified:
trunk/varnish-cache/bin/varnishd/cache.h
Log:
Get the pthread_mutex_trylock() assert right, the error code is the
return value, and not in errno.


Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h 2008-02-25 22:30:23 UTC (rev 2539)
+++ trunk/varnish-cache/bin/varnishd/cache.h 2008-02-26 09:10:35 UTC (rev 2540)
@@ -590,6 +590,7 @@
#define TRYLOCK(foo, r) \
do { \
(r) = pthread_mutex_trylock(foo); \
+ assert(r == 0 || r == EBUSY); \
if (params->diag_bitmap & 0x8) { \
VSL(SLT_Debug, 0, \
"MTX_TRYLOCK(%s,%s,%d," #foo ") = %d", \
@@ -600,15 +601,19 @@
do { \
if (!(params->diag_bitmap & 0x18)) { \
AZ(pthread_mutex_lock(foo)); \
- } else if (pthread_mutex_trylock(foo)) { \
- VSL(SLT_Debug, 0, \
- "MTX_CONTEST(%s,%s,%d," #foo ")", \
- __func__, __FILE__, __LINE__); \
- AZ(pthread_mutex_lock(foo)); \
- } else if (params->diag_bitmap & 0x8) { \
- VSL(SLT_Debug, 0, \
- "MTX_LOCK(%s,%s,%d," #foo ")", \
- __func__, __FILE__, __LINE__); \
+ } else { \
+ int ixjd = pthread_mutex_trylock(foo); \
+ assert(ixjd == 0 || ixjd == EBUSY); \
+ if (ixjd) { \
+ VSL(SLT_Debug, 0, \
+ "MTX_CONTEST(%s,%s,%d," #foo ")", \
+ __func__, __FILE__, __LINE__); \
+ AZ(pthread_mutex_lock(foo)); \
+ } else if (params->diag_bitmap & 0x8) { \
+ VSL(SLT_Debug, 0, \
+ "MTX_LOCK(%s,%s,%d," #foo ")", \
+ __func__, __FILE__, __LINE__); \
+ } \
} \
} while (0)
#define UNLOCK(foo) \