aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorIan Jackson <ian.jackson@eu.citrix.com>2012-01-13 16:54:27 +0000
committerIan Jackson <ian.jackson@eu.citrix.com>2012-01-13 16:54:27 +0000
commit2fe29aed9d328641cdc50ffdb013193883bf2f0a (patch)
tree7daa6fbab37f7e11ffa49558fff6bf42b95fc287 /tools
parent8fc051a10f0df8e0030b2d6cbddb720f4322c7d3 (diff)
downloadxen-2fe29aed9d328641cdc50ffdb013193883bf2f0a.tar.gz
xen-2fe29aed9d328641cdc50ffdb013193883bf2f0a.tar.bz2
xen-2fe29aed9d328641cdc50ffdb013193883bf2f0a.zip
libxl: Provide more formal libxl__ctx_lock and _unlock
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 <ian.jackson@eu.citrix.com> Acked-by: Ian Campbell <ian.campbell@citrix.com> Committed-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/libxl/libxl_internal.h23
1 files changed, 13 insertions, 10 deletions
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index 1b03929b2a..39e9e052fe 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
@@ -753,16 +754,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))
/*