diff -r 8348f40ba2b7 tools/libxen/Makefile --- a/tools/libxen/Makefile Thu Dec 21 14:49:19 2006 +0000 +++ b/tools/libxen/Makefile Fri Dec 22 17:32:26 2006 -0500 @@ -27,7 +27,8 @@ CFLAGS = -Iinclude \ -W -Wall -Wmissing-prototypes -Werror -std=c99 -O2 -fPIC LDFLAGS = $(shell xml2-config --libs) \ - $(shell curl-config --libs) + $(shell curl-config --libs) \ + -lpthread LIBXENAPI_HDRS = $(wildcard include/*.h) LIBXENAPI_OBJS = $(patsubst %.c, %.o, $(wildcard src/*.c)) diff -r 8348f40ba2b7 tools/libxen/include/xen_common.h --- a/tools/libxen/include/xen_common.h Thu Dec 21 14:49:19 2006 +0000 +++ b/tools/libxen/include/xen_common.h Fri Dec 22 17:32:26 2006 -0500 @@ -24,13 +24,13 @@ #include #include #include - +// The init and the fini really need to happen only once. +// The mutex will take care of that +#include #include "xen_host_decl.h" - typedef bool (*xen_result_func)(const void *data, size_t len, void *result_handle); - /** * len does not include a terminating \0. diff -r 8348f40ba2b7 tools/libxen/src/xen_common.c --- a/tools/libxen/src/xen_common.c Thu Dec 21 14:49:19 2006 +0000 +++ b/tools/libxen/src/xen_common.c Fri Dec 22 17:32:26 2006 -0500 @@ -43,6 +43,8 @@ #define PERMISSIVE 1 +static pthread_mutex_t mutexUserCount=PTHREAD_MUTEX_INITIALIZER; +static unsigned UserCount=0; static xmlXPathCompExprPtr responsePath = NULL; static xmlXPathCompExprPtr faultPath = NULL; @@ -111,23 +113,35 @@ void void xen_init(void) { - responsePath = - xmlXPathCompile( - BAD_CAST( - "/methodResponse/params/param/value/struct/member/value")); - faultPath = - xmlXPathCompile( - BAD_CAST("/methodResponse/fault/value/struct/member/value")); + pthread_mutex_lock(&mutexUserCount); + if (UserCount==0) + { + responsePath = + xmlXPathCompile( + BAD_CAST( + "/methodResponse/params/param/value/struct/member/value")); + faultPath = + xmlXPathCompile( + BAD_CAST("/methodResponse/fault/value/struct/member/value")); + } + UserCount++; + pthread_mutex_unlock(&mutexUserCount); } void xen_fini(void) { - xmlXPathFreeCompExpr(responsePath); - xmlXPathFreeCompExpr(faultPath); - responsePath = NULL; - faultPath = NULL; + pthread_mutex_lock(&mutexUserCount); + UserCount--; + if (UserCount==0) + { + xmlXPathFreeCompExpr(responsePath); + xmlXPathFreeCompExpr(faultPath); + responsePath = NULL; + faultPath = NULL; + } + pthread_mutex_unlock(&mutexUserCount); }