[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH 15 of 15 v5] libxl: fix mutex initialization



# HG changeset patch
# User Roger Pau Monne <roger.pau@xxxxxxxxxxxxx>
# Date 1323939609 -3600
# Node ID 759f27054f543cd57e008db4031fb7353c88fc20
# Parent  97d3104a544c067400c17e252641694790b6cf16
libxl: fix mutex initialization

The macro PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP is not defined on
NetBSD, so define mutex attributes manually.

Signed-off-by: Roger Pau Monne <roger.pau@xxxxxxxxxxxxx>

diff -r 97d3104a544c -r 759f27054f54 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c       Thu Dec 15 10:00:09 2011 +0100
+++ b/tools/libxl/libxl.c       Thu Dec 15 10:00:09 2011 +0100
@@ -41,7 +41,7 @@ int libxl_ctx_alloc(libxl_ctx **pctx, in
 {
     libxl_ctx *ctx;
     struct stat stat_buf;
-    const pthread_mutex_t mutex_value = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
+    pthread_mutexattr_t attr;
 
     if (version != LIBXL_VERSION)
         return ERROR_VERSION;
@@ -55,10 +55,21 @@ int libxl_ctx_alloc(libxl_ctx **pctx, in
     memset(ctx, 0, sizeof(libxl_ctx));
     ctx->lg = lg;
 
-    /* This somewhat convoluted approach is needed because
-     * PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP is defined to be valid
-     * only as an initialiser, not as an expression. */
-    memcpy(&ctx->lock, &mutex_value, sizeof(ctx->lock));
+    if (pthread_mutexattr_init(&attr) != 0) {
+        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, 
+                         "Failed to init mutex attributes\n");
+        return ERROR_FAIL;
+    }
+    if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) != 0) {
+        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, 
+                         "Failed to set mutex attributes\n");
+        return ERROR_FAIL;
+    }
+    if (pthread_mutex_init(&ctx->lock, &attr) != 0) {
+        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, 
+                         "Failed to init mutex\n");
+        return ERROR_FAIL;
+    }
 
     if ( stat(XENSTORE_PID_FILE, &stat_buf) != 0 ) {
         LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "Is xenstore daemon running?\n"

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.