[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-devel] [PATCH 15/15] libxl: New event generation API
On Mon, 2011-12-12 at 19:24 +0000, Stefano Stabellini wrote: > diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c > index cd613f7..94bdbba 100644 > --- a/tools/libxl/libxl.c > +++ b/tools/libxl/libxl.c > @@ -63,6 +63,12 @@ int libxl_ctx_alloc(libxl_ctx **pctx, int version, > * only as an initialiser, not as an expression. */ > memcpy(&ctx->lock, &mutex_value, sizeof(ctx->lock)); > > + if(pthread_key_create(&ctx->tls_key, NULL) < 0) { > + LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, errno, > + "cannot create tls key"); > + return ERROR_FAIL; You need a corresponding pthread_key_delete in the free function. > [...] > @@ -65,17 +66,41 @@ int libxl__ptr_add(libxl__gc *gc, void *ptr) > return 0; > } > > +libxl__gc *libxl__init_gc(libxl_ctx *ctx) > +{ > + libxl__gc *gc = (libxl__gc *) pthread_getspecific(ctx->tls_key); > + if (gc == NULL) { > + gc = (libxl__gc *) malloc(sizeof(libxl__gc)); > + if (gc == NULL) > + return NULL; > + gc->alloc_maxsize = 0; > + gc->alloc_ptrs = 0; > + gc->owner = ctx; > + gc->nested = 1; > + pthread_setspecific(ctx->tls_key, gc); pthread_setspecific can fail. > [...] > void libxl__free_all(libxl__gc *gc) > { > void *ptr; > int i; > > + gc->nested--; > + if (gc->nested > 0) > + return; > + > for (i = 0; i < gc->alloc_maxsize; i++) { > ptr = gc->alloc_ptrs[i]; > gc->alloc_ptrs[i] = NULL; > free(ptr); > } > free(gc->alloc_ptrs); > + pthread_setspecific(CTX->tls_key, NULL); As above this can also fail. I think this one might be a bit harder to deal with in general. > + free(gc); > } > Ian. _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |