From: Ian Campbell Subject: Re: [PATCH 04/10] libxl: Provide more formal libxl__ctx_lock and _unlock Date: Fri, 13 Jan 2012 10:42:10 +0000 Message-ID: <1326451331.17210.311.camel@zakaz.uk.xensource.com> References: <1325882107-5794-1-git-send-email-ian.jackson@eu.citrix.com> <1325882107-5794-5-git-send-email-ian.jackson@eu.citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1325882107-5794-5-git-send-email-ian.jackson@eu.citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Ian Jackson Cc: "xen-devel@lists.xensource.com" List-Id: xen-devel@lists.xenproject.org On Fri, 2012-01-06 at 20:35 +0000, Ian Jackson wrote: > Previously the only official interface for the ctx lock was the > CTX_LOCK and CTX_UNLOCK convenience macros, which assume and use "ctx" > from the surrounding scope. > > Instead, provide libxl__ctx_lock and _unlock functions which can be > used by these convenience macros, and other callers who have > nonstandard requirements. > > Signed-off-by: Ian Jackson Acked-by: Ian Campbell > --- > tools/libxl/libxl_internal.h | 23 +++++++++++++---------- > 1 files changed, 13 insertions(+), 10 deletions(-) > > diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h > index d681d73..1dadf15 100644 > --- a/tools/libxl/libxl_internal.h > +++ b/tools/libxl/libxl_internal.h > @@ -115,7 +115,8 @@ struct libxl__ctx { > struct xs_handle *xsh; > > pthread_mutex_t lock; /* protects data structures hanging off the ctx */ > - /* Always use CTX_LOCK and CTX_UNLOCK to manipulate this. > + /* Always use libxl__ctx_lock and _unlock (or the convenience > + * macors CTX_LOCK and CTX_UNLOCK) to manipulate this. > * > * You may acquire this mutex recursively if it is convenient to > * do so. You may not acquire this lock at the same time as any > @@ -749,16 +750,18 @@ libxl__device_model_version_running(libxl__gc *gc, uint32_t domid); > > /* Locking functions. See comment for "lock" member of libxl__ctx. */ > > -#define CTX_LOCK do { \ > - int mutex_r = pthread_mutex_lock(&CTX->lock); \ > - assert(!mutex_r); \ > - } while(0) > +static inline void libxl__ctx_lock(libxl_ctx *ctx) { > + int r = pthread_mutex_lock(&ctx->lock); > + assert(!r); > +} > > -#define CTX_UNLOCK do { \ > - int mutex_r = pthread_mutex_unlock(&CTX->lock); \ > - assert(!mutex_r); \ > - } while(0) > - > +static inline void libxl__ctx_unlock(libxl_ctx *ctx) { > + int r = pthread_mutex_unlock(&ctx->lock); > + assert(!r); > +} > + > +#define CTX_LOCK (libxl__ctx_lock(CTX)) > +#define CTX_UNLOCK (libxl__ctx_unlock(CTX)) > > > /*