From 0b10942df8fcf8972d5389d9c0bc93b400e1d25b Mon Sep 17 00:00:00 2001 From: phk Date: Tue, 26 Feb 2008 09:10:35 +0000 Subject: [PATCH] Get the pthread_mutex_trylock() assert right, the error code is the 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 | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/varnish-cache/bin/varnishd/cache.h b/varnish-cache/bin/varnishd/cache.h index 44bf5469..400e8fa5 100644 --- a/varnish-cache/bin/varnishd/cache.h +++ b/varnish-cache/bin/varnishd/cache.h @@ -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) \ -- 2.39.5