From: Christoph Egger <Christoph.Egger@amd.com>
To: Roger Pau Monne <roger.pau@entel.upc.edu>
Cc: xen-devel@lists.xensource.com
Subject: Re: [PATCH] libxl: fix mutex initialization
Date: Fri, 13 Jan 2012 15:01:16 +0100 [thread overview]
Message-ID: <4F10392C.2070007@amd.com> (raw)
In-Reply-To: <bb6b01995d64f7c2887b.1326460363@loki.upc.es>
On 01/13/12 14:12, Roger Pau Monne wrote:
> # HG changeset patch
> # User Roger Pau Monne<roger.pau@entel.upc.edu>
> # Date 1326460029 -3600
> # Node ID bb6b01995d64f7c2887b7174536861b83ef04364
> # Parent 117ad4634ba11c10e45f3d86e6baff35d7d2691c
> 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@entel.upc.edu>
Acked-by: Christoph Egger <Christoph.Egger@amd.com>
>
> diff -r 117ad4634ba1 -r bb6b01995d64 tools/libxl/libxl.c
> --- a/tools/libxl/libxl.c Fri Jan 13 13:55:01 2012 +0100
> +++ b/tools/libxl/libxl.c Fri Jan 13 14:07:09 2012 +0100
> @@ -41,7 +41,6 @@ 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;
>
> if (version != LIBXL_VERSION)
> return ERROR_VERSION;
> @@ -55,10 +54,10 @@ 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 (libxl__init_recursive_mutex(ctx,&ctx->lock)< 0) {
> + LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Failed to initialize mutex");
> + return ERROR_FAIL;
> + }
>
> if ( stat(XENSTORE_PID_FILE,&stat_buf) != 0 ) {
> LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "Is xenstore daemon running?\n"
> diff -r 117ad4634ba1 -r bb6b01995d64 tools/libxl/libxl_internal.c
> --- a/tools/libxl/libxl_internal.c Fri Jan 13 13:55:01 2012 +0100
> +++ b/tools/libxl/libxl_internal.c Fri Jan 13 14:07:09 2012 +0100
> @@ -304,6 +304,28 @@ _hidden int libxl__compare_macs(libxl_ma
> return 0;
> }
>
> +_hidden int libxl__init_recursive_mutex(libxl_ctx *ctx, pthread_mutex_t *lock)
> +{
> + pthread_mutexattr_t attr;
> +
> + 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(lock,&attr) != 0) {
> + LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR,
> + "Failed to init mutex\n");
> + return ERROR_FAIL;
> + }
> + return 0;
> +}
> +
> libxl_device_model_version libxl__device_model_version_running(libxl__gc *gc,
> uint32_t domid)
> {
> diff -r 117ad4634ba1 -r bb6b01995d64 tools/libxl/libxl_internal.h
> --- a/tools/libxl/libxl_internal.h Fri Jan 13 13:55:01 2012 +0100
> +++ b/tools/libxl/libxl_internal.h Fri Jan 13 14:07:09 2012 +0100
> @@ -606,6 +606,8 @@ _hidden int libxl__e820_alloc(libxl__gc
> _hidden int libxl__parse_mac(const char *s, libxl_mac mac);
> /* compare mac address @a and @b. 0 if the same, -ve if a<b and +ve if a>b */
> _hidden int libxl__compare_macs(libxl_mac *a, libxl_mac *b);
> +/* init a recursive mutex */
> +_hidden int libxl__init_recursive_mutex(libxl_ctx *ctx, pthread_mutex_t *lock);
>
> #define STRINGIFY(x) #x
> #define TOSTRING(x) STRINGIFY(x)
>
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xensource.com
> http://lists.xensource.com/xen-devel
>
--
---to satisfy European Law for business letters:
Advanced Micro Devices GmbH
Einsteinring 24, 85689 Dornach b. Muenchen
Geschaeftsfuehrer: Alberto Bozzo, Andrew Bowd
Sitz: Dornach, Gemeinde Aschheim, Landkreis Muenchen
Registergericht Muenchen, HRB Nr. 43632
next prev parent reply other threads:[~2012-01-13 14:01 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-13 13:12 [PATCH] libxl: fix mutex initialization Roger Pau Monne
2012-01-13 14:01 ` Christoph Egger [this message]
2012-01-26 17:41 ` Ian Jackson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4F10392C.2070007@amd.com \
--to=christoph.egger@amd.com \
--cc=roger.pau@entel.upc.edu \
--cc=xen-devel@lists.xensource.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.