]> err.no Git - varnish/commitdiff
Get the pthread_mutex_trylock() assert right, the error code is the
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 26 Feb 2008 09:10:35 +0000 (09:10 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 26 Feb 2008 09:10:35 +0000 (09:10 +0000)
return value, and not in errno.

git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2540 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/cache.h

index 44bf54693d9c139736f5b356e9bfbd4d3c431f6b..400e8fa56b8dc8f40fda9c0e53e9febbb40b6a77 100644 (file)
@@ -590,6 +590,7 @@ int RFC2616_cache_policy(const struct sess *sp, const struct http *hp);
 #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 {                                                              \
 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)                                            \