From 6d7c042b2025f6ecd7e3c3013eeeff331a471d82 Mon Sep 17 00:00:00 2001 From: muench Date: Wed, 26 May 2004 11:34:38 +0000 Subject: [PATCH] mutex around rpc calls, tested with test suite --- allParam/rpc/rpcParam.c | 68 +++++++++++++++++++++++++++++++++++++++-- allParam/test/Makefile | 4 +-- 2 files changed, 68 insertions(+), 4 deletions(-) diff --git a/allParam/rpc/rpcParam.c b/allParam/rpc/rpcParam.c index 4cd7037..e224295 100644 --- a/allParam/rpc/rpcParam.c +++ b/allParam/rpc/rpcParam.c @@ -1,4 +1,4 @@ -static const char rcsId[] = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/allParam/rpc/rpcParam.c,v 1.10 2004-05-24 12:07:33 muench Exp $"; +static const char rcsId[] = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/allParam/rpc/rpcParam.c,v 1.11 2004-05-26 11:34:38 muench Exp $"; #define _POSIX_C_SOURCE 199509L #if HAVE_CONFIG_H @@ -9,6 +9,9 @@ static const char rcsId[] = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuild #include #include +#ifdef PTHREADS +#include +#endif /* PTHREADS */ #include #include #include @@ -27,6 +30,9 @@ typedef struct RpcParamS { CLIENT *cl; unsigned long remParam; PCache *cache; +#ifdef PTHREADS + pthread_mutex_t *rpcLock; +#endif /* PTHREADS */ } RpcParam; int conSetupParam(Param * my, const char *setup) @@ -47,12 +53,18 @@ int conSetupParam(Param * my, const char *setup) my->setup = NULL; } + rpcParam = malloc(sizeof(RpcParam)); + +#ifdef PTHREADS + rpcParam->rpcLock = malloc(sizeof(pthread_mutex_t)); + pthread_mutex_init(rpcParam->rpcLock, NULL); +#endif /* PTHREADS */ + server = getenv("PARAM_RPCPAS_ADDR"); if (server == NULL) { Param_strerror(my, "Environment variable PARAM_RPCPAS_ADDR not set"); retVal = -1; } else { - rpcParam = malloc(sizeof(RpcParam)); rpcParam->cl = clnt_create(server, RPCPARAMPROG, RPCPARAMVERS, "tcp"); if (rpcParam->cl == NULL) { Param_strerror(my, clnt_spcreateerror(server)); @@ -61,7 +73,13 @@ int conSetupParam(Param * my, const char *setup) char *arg; arg = my->setup == NULL ? "" : my->setup; +#ifdef PTHREADS + pthread_mutex_lock(rpcParam->rpcLock); +#endif /* PTHREADS */ rpcParam->remParam = *con_1(&arg, rpcParam->cl); +#ifdef PTHREADS + pthread_mutex_unlock(rpcParam->rpcLock); +#endif /* PTHREADS */ } } @@ -103,9 +121,19 @@ void desParam(Param * my) RpcParam *rpcParam = my->specParam; if (rpcParam->cl != NULL) { +#ifdef PTHREADS + pthread_mutex_lock(rpcParam->rpcLock); +#endif /* PTHREADS */ des_1(&rpcParam->remParam, rpcParam->cl); +#ifdef PTHREADS + pthread_mutex_unlock(rpcParam->rpcLock); +#endif /* PTHREADS */ clnt_destroy(rpcParam->cl); } +#ifdef PTHREADS + pthread_mutex_destroy(rpcParam->rpcLock); + free(rpcParam->rpcLock); +#endif /* PTHREADS */ free(rpcParam); free(my->setup); } @@ -124,7 +152,13 @@ int Param_getInt(const Param * my, const char *name, const char *idx, int *row, args.name = name; args.idx = idx; +#ifdef PTHREADS + pthread_mutex_lock(rpcParam->rpcLock); +#endif /* PTHREADS */ res = *getint_1(&args, rpcParam->cl); +#ifdef PTHREADS + pthread_mutex_unlock(rpcParam->rpcLock); +#endif /* PTHREADS */ *row = res.rows; *val = res.value; @@ -148,7 +182,13 @@ int Param_getString(const Param * my, const char *name, const char *idx, int *ro args.name = name; args.idx = idx; +#ifdef PTHREADS + pthread_mutex_lock(rpcParam->rpcLock); +#endif /* PTHREADS */ res = *getstring_1(&args, rpcParam->cl); +#ifdef PTHREADS + pthread_mutex_unlock(rpcParam->rpcLock); +#endif /* PTHREADS */ *row = res.rows; strcpy(val, res.value); @@ -194,7 +234,13 @@ int Param_getIntArray(const Param * my, const char *name, const char *idx, int m args.idx = idx; args.maxrows = maxrows; +#ifdef PTHREADS + pthread_mutex_lock(rpcParam->rpcLock); +#endif /* PTHREADS */ res = *getintarray_1(&args, rpcParam->cl); +#ifdef PTHREADS + pthread_mutex_unlock(rpcParam->rpcLock); +#endif /* PTHREADS */ *rows = res.value.value_len; for (i = 0; i < res.value.value_len; i++) { @@ -220,7 +266,13 @@ int Param_getStringArray(const Param * my, const char *name, const char *idx, in args.idx = idx; args.maxrows = maxrows; +#ifdef PTHREADS + pthread_mutex_lock(rpcParam->rpcLock); +#endif /* PTHREADS */ res = *getstringarray_1(&args, rpcParam->cl); +#ifdef PTHREADS + pthread_mutex_unlock(rpcParam->rpcLock); +#endif /* PTHREADS */ *rows = res.value.value_len; for (i = 0; i < res.value.value_len; i++) { @@ -288,7 +340,13 @@ int Param_storeInt(const Param * my, const char *name, const char *idx, unsigned args.idx = idx; args.value = value; +#ifdef PTHREADS + pthread_mutex_lock(rpcParam->rpcLock); +#endif /* PTHREADS */ res = *storeint_1(&args, rpcParam->cl); +#ifdef PTHREADS + pthread_mutex_unlock(rpcParam->rpcLock); +#endif /* PTHREADS */ return res; } @@ -305,7 +363,13 @@ int Param_storeString(const Param * my, const char *name, const char *idx, const args.idx = idx; args.value = value; +#ifdef PTHREADS + pthread_mutex_lock(rpcParam->rpcLock); +#endif /* PTHREADS */ res = *storestring_1(&args, rpcParam->cl); +#ifdef PTHREADS + pthread_mutex_unlock(rpcParam->rpcLock); +#endif /* PTHREADS */ return res; } diff --git a/allParam/test/Makefile b/allParam/test/Makefile index 1387b78..99efad9 100644 --- a/allParam/test/Makefile +++ b/allParam/test/Makefile @@ -13,13 +13,13 @@ LOADPSQLLIBES = -L../psql -lpsqlParam -lpq -lcrypt # Tcl test LOADTCLLIBES = -L../tcl -ltclParam -ltcl -lm -ldl # Rpc test -LOADRPCLIBES = -L.. -lrpcParam +LOADRPCLIBES = -L.. -lrpcParam_p HEADERS = blob/*.h filename/*.h int/*.h string/*.h VPATH=.:blob:filename:int:string -CFLAGS = -Wall -I../include +CFLAGS = -Wall -I../include -DPTHREADS OBJS = suite.o blobobjs filenameobjs intobjs stringobjs LIBS = ca file ora psql tcl rpc -- 2.43.0