From 84e7e866809f041f37d70d2aaca925af4f0011bf Mon Sep 17 00:00:00 2001 From: hadaq Date: Mon, 3 Jun 2002 17:47:08 +0000 Subject: [PATCH] *** empty log message *** --- allParam/ca/client/caParam.c | 552 ++++++++++++++--------------------- 1 file changed, 223 insertions(+), 329 deletions(-) diff --git a/allParam/ca/client/caParam.c b/allParam/ca/client/caParam.c index 4fed8d4..959e570 100644 --- a/allParam/ca/client/caParam.c +++ b/allParam/ca/client/caParam.c @@ -1,4 +1,4 @@ -static const char rcsId[] = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/allParam/ca/client/caParam.c,v 1.19 2002-06-03 10:47:35 hadaq Exp $"; +static const char rcsId[] = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/allParam/ca/client/caParam.c,v 1.20 2002-06-03 17:47:08 hadaq Exp $"; #define _POSIX_C_SOURCE 199509L #include @@ -16,8 +16,7 @@ static const char rcsId[] = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuild #include -#define TIMEOUTEVT 0.0002 -#define TIMEOUTSG 10.0 +#define TIMEOUTEVT 1.0E-09 #define TIMEOUTIO 10.0 static void Param_copyStringsToAllocMem(struct event_handler_args args); @@ -34,6 +33,7 @@ static int Param_storeStringCache(const Param *, const char *, const char *, con typedef struct CaParamS { Tcl_Interp *cache; pthread_mutex_t *cacheLock; + pthread_mutex_t *socketLock; } CaParam; typedef struct ParamStringResultS { @@ -83,19 +83,30 @@ int conSetupParam(Param *my, const char *setup) pthread_mutexattr_create(attr); pthread_mutex_init(((CaParam *) (my->specParam))->cacheLock, *attr); pthread_mutexattr_delete(attr); + + ((CaParam *) (my->specParam))->socketLock = malloc(sizeof(pthread_mutex_t)); + pthread_mutexattr_create(attr); + pthread_mutex_init(((CaParam *) (my->specParam))->socketLock, *attr); + pthread_mutexattr_delete(attr); #else ((CaParam *) (my->specParam))->cacheLock = malloc(sizeof(pthread_mutex_t)); pthread_mutex_init(((CaParam *) (my->specParam))->cacheLock, NULL); + + ((CaParam *) (my->specParam))->socketLock = malloc(sizeof(pthread_mutex_t)); + pthread_mutex_init(((CaParam *) (my->specParam))->socketLock, NULL); #endif ((CaParam *) (my->specParam))->cache = Tcl_CreateInterp(); - if((status = ca_task_initialize()) != ECA_NORMAL) { + if ((status = ca_task_initialize()) != ECA_NORMAL) { Param_strerror((Param *) my, ca_message(status)); + pthread_mutex_destroy(((CaParam *) (my->specParam))->cacheLock); free(((CaParam *) (my->specParam))->cacheLock); + pthread_mutex_destroy(((CaParam *) (my->specParam))->socketLock); + free(((CaParam *) (my->specParam))->socketLock); retVal = -1; } else { - if(setup != NULL) { + if (setup != NULL) { my->setup = malloc(strlen(setup) + 1); strcpy(my->setup, setup); } else { @@ -103,7 +114,7 @@ int conSetupParam(Param *my, const char *setup) } my->basedir = malloc(PARAM_MAX_VALUE_LEN); uname(buffer); - if(Param_getString(my, buffer->nodename, "basedir", &row, my->basedir) || (row != 1)) { + if (Param_getString(my, buffer->nodename, "basedir", &row, my->basedir) || (row != 1)) { strcpy(my->basedir, ""); } else if (strlen(my->basedir)) { strcat(my->basedir, "/"); @@ -125,8 +136,10 @@ void desParam(Param *my) Tcl_DeleteInterp(((CaParam *) (my->specParam))->cache); pthread_mutex_destroy(((CaParam *) (my->specParam))->cacheLock); free(((CaParam *) (my->specParam))->cacheLock); + pthread_mutex_destroy(((CaParam *) (my->specParam))->socketLock); + free(((CaParam *) (my->specParam))->socketLock); free(my->basedir); - if(my->setup != NULL) { + if (my->setup != NULL) { free(my->setup); } } @@ -158,73 +171,51 @@ int Param_getIntArray(const Param *my, const char *name, const char *idx, int ma char buf[PARAM_MAX_NAME_LEN]; *rows = 0; - if(Param_getIntArrayCache(my, name, idx, maxrows, rows, val) || (*rows != maxrows)) { -#ifdef SYNCHRONOUS_GROUP - CA_SYNC_GID pgid; -#endif + if (Param_getIntArrayCache(my, name, idx, maxrows, rows, val) || (*rows != maxrows)) { pPVName = malloc((strlen("HAD:PI:") + (my->setup == NULL ? 0 : strlen(my->setup) + 1) + strlen(name) + 1 + strlen(idx) + 1) * sizeof(char)); Param_returnPVName(my, "PI", name, idx, pPVName); - if((status = ca_search(pPVName, &chan)) == ECA_GETFAIL) { - Param_strerror((Param *) my, ca_message(status)); - found = 0; - } else if (status != ECA_NORMAL) { - Param_strerror((Param *) my, ca_message(status)); - retVal = -1; - } else { -#ifdef SYNCHRONOUS_GROUP - ca_sg_create(&pgid); -#endif - do { - status = ca_pend_io(TIMEOUTIO); - } while ((ca_state(chan) != cs_conn) && (status != ECA_TIMEOUT)); - if(status != ECA_NORMAL) { + if (0 == pthread_mutex_lock(((CaParam *) (my->specParam))->socketLock)) { + if ((status = ca_search(pPVName, &chan)) == ECA_GETFAIL) { Param_strerror((Param *) my, ca_message(status)); found = 0; - retVal = 0; - } - if(found == 1) { -#ifndef SYNCHRONOUS_GROUP - ParamIntResult resultS, *result = &resultS; - result->val = val; - result->rows = rows; - result->maxrows = maxrows; - result->my = my; - result->retVal = &retVal; - result->isReady = &isReady; - isReady = 1; - - status = ca_array_get_callback(ca_field_type(chan), ca_element_count(chan), chan, Param_copyIntsToAllocMem, result); -#else - status = ca_sg_array_get(pgid, ca_field_type(chan), ca_element_count(chan), chan, val); -#endif + } else if (status != ECA_NORMAL) { Param_strerror((Param *) my, ca_message(status)); -#ifndef SYNCHRONOUS_GROUP + retVal = -1; + } else { do { - ca_pend_event(TIMEOUTEVT); - } while(isReady == 1); -#else - if((status = ca_sg_block(pgid, TIMEOUTSG)) == ECA_TIMEOUT) { - retVal = 0; - *rows = 0; - } else if (status == ECA_NORMAL) { + status = ca_pend_io(TIMEOUTIO); + } while ((ca_state(chan) != cs_conn) && (status != ECA_TIMEOUT)); + if (status != ECA_NORMAL) { + Param_strerror((Param *) my, ca_message(status)); + found = 0; retVal = 0; - *rows = maxrows > ca_element_count(chan) ? ca_element_count(chan) : maxrows; - } else { - retVal = -1; - *rows = 0; } - ca_sg_delete(pgid); -#endif - } - if((status = ca_clear_channel(chan)) != ECA_NORMAL) { - Param_strerror((Param *) my, ca_message(status)); + if (found == 1) { + ParamIntResult resultS, *result = &resultS; + result->val = val; + result->rows = rows; + result->maxrows = maxrows; + result->my = my; + result->retVal = &retVal; + result->isReady = &isReady; + isReady = 1; + + status = ca_array_get_callback(ca_field_type(chan), ca_element_count(chan), chan, Param_copyIntsToAllocMem, result); + Param_strerror((Param *) my, ca_message(status)); + do { + ca_pend_event(TIMEOUTEVT); + } while(isReady == 1); + } + if ((status = ca_clear_channel(chan)) != ECA_NORMAL) { + Param_strerror((Param *) my, ca_message(status)); + } } + pthread_mutex_unlock(((CaParam *) (my->specParam))->socketLock); } - free(pPVName); - if(maxrows == 1) { + if (maxrows == 1) { Param_storeIntCache(my, name, idx, *val); } else { for (i = 0 ; i < *rows ; i++) { @@ -249,74 +240,53 @@ int Param_getStringArray(const Param *my, const char *name, const char *idx, int char buf[PARAM_MAX_NAME_LEN]; *rows = 0; - if(Param_getStringArrayCache(my, name, idx, maxrows, rows, val) || (*rows != maxrows)) { -#ifdef SYNCHRONOUS_GROUP - CA_SYNC_GID pgid; -#endif + if (Param_getStringArrayCache(my, name, idx, maxrows, rows, val) || (*rows != maxrows)) { pPVName = malloc((strlen("HAD:PS:") + (my->setup == NULL ? 0 : strlen(my->setup) + 1) + strlen(name) + 1 + strlen(idx) + 1) * sizeof(char)); Param_returnPVName(my, "PS", name, idx, pPVName); - if((status = ca_search(pPVName, &chan)) == ECA_GETFAIL) { - Param_strerror((Param *) my, ca_message(status)); - found = 0; - } else if (status != ECA_NORMAL) { - Param_strerror((Param *) my, ca_message(status)); - retVal = -1; - } else { -#ifdef SYNCHRONOUS_GROUP - ca_sg_create(&pgid); -#endif - do { - status = ca_pend_io(TIMEOUTIO); - } while ((ca_state(chan) != cs_conn) && (status != ECA_TIMEOUT)); - if(status != ECA_NORMAL) { + if (0 == pthread_mutex_lock(((CaParam *) (my->specParam))->socketLock)) { + if ((status = ca_search(pPVName, &chan)) == ECA_GETFAIL) { Param_strerror((Param *) my, ca_message(status)); found = 0; - retVal = 0; - } - if(found == 1) { -#ifndef SYNCHRONOUS_GROUP - ParamStringResult resultS, *result = &resultS; - result->val = val; - result->rows = rows; - result->maxrows = maxrows; - result->my = my; - result->retVal = &retVal; - result->isReady = &isReady; - isReady = 1; - - status = ca_array_get_callback(ca_field_type(chan), ca_element_count(chan), chan, Param_copyStringsToAllocMem, result); -#else - status = ca_sg_array_get(pgid, ca_field_type(chan), ca_element_count(chan), chan, val); -#endif + } else if (status != ECA_NORMAL) { Param_strerror((Param *) my, ca_message(status)); -#ifndef SYNCHRONOUS_GROUP + retVal = -1; + } else { do { - ca_pend_event(TIMEOUTEVT); - } while(isReady == 1); -#else - if((status = ca_sg_block(pgid, TIMEOUTSG)) == ECA_TIMEOUT) { + status = ca_pend_io(TIMEOUTIO); + } while ((ca_state(chan) != cs_conn) && (status != ECA_TIMEOUT)); + if (status != ECA_NORMAL) { + Param_strerror((Param *) my, ca_message(status)); + found = 0; retVal = 0; - *rows = 0; - } else if (status == ECA_NORMAL) { - retVal = 0; - *rows = maxrows > ca_element_count(chan) ? ca_element_count(chan) : maxrows; - } else { - retVal = -1; - *rows = 0; } - ca_sg_delete(pgid); -#endif - } + if (found == 1) { + ParamStringResult resultS, *result = &resultS; + result->val = val; + result->rows = rows; + result->maxrows = maxrows; + result->my = my; + result->retVal = &retVal; + result->isReady = &isReady; + isReady = 1; + + status = ca_array_get_callback(ca_field_type(chan), ca_element_count(chan), chan, Param_copyStringsToAllocMem, result); + Param_strerror((Param *) my, ca_message(status)); + do { + ca_pend_event(TIMEOUTEVT); + } while(isReady == 1); + } - if((status = ca_clear_channel(chan)) != ECA_NORMAL) { - Param_strerror((Param *) my, ca_message(status)); + if ((status = ca_clear_channel(chan)) != ECA_NORMAL) { + Param_strerror((Param *) my, ca_message(status)); + } } + pthread_mutex_unlock(((CaParam *) (my->specParam))->socketLock); } free(pPVName); - if(maxrows == 1) { + if (maxrows == 1) { Param_storeStringCache(my, name, idx, *val); } else { for (i = 0 ; i < *rows ; i++) { @@ -333,7 +303,6 @@ int Param_getFilenameArray(const Param *my, const char *name, const char *idx, i { int isReady; int retVal = 0; - int hasPrefix = 0; int status; int found = 1; chid chan; @@ -341,91 +310,69 @@ int Param_getFilenameArray(const Param *my, const char *name, const char *idx, i int i; char *prefixVal[PARAM_MAX_ARRAY_LEN]; char buf[PARAM_MAX_NAME_LEN]; - char prefix[PARAM_MAX_VALUE_LEN]; *rows = 0; - if(Param_getStringArrayCache(my, name, idx, maxrows, rows, val) || (*rows != maxrows)) { -#ifdef SYNCHRONOUS_GROUP - CA_SYNC_GID pgid; -#endif + if (Param_getStringArrayCache(my, name, idx, maxrows, rows, val) || (*rows != maxrows)) { pPVName = malloc((strlen("HAD:PS:") + (my->setup == NULL ? 0 : strlen(my->setup) + 1) + strlen(name) + 1 + strlen(idx) + 1) * sizeof(char)); Param_returnPVName(my, "PS", name, idx, pPVName); - if((status = ca_search(pPVName, &chan)) == ECA_GETFAIL) { - Param_strerror((Param *) my, ca_message(status)); - found = 0; - } else if (status != ECA_NORMAL) { - Param_strerror((Param *) my, ca_message(status)); - retVal = -1; - } else { -#ifdef SYNCHRONOUS_GROUP - ca_sg_create(&pgid); -#endif - do { - status = ca_pend_io(TIMEOUTIO); - } while ((ca_state(chan) != cs_conn) && (status != ECA_TIMEOUT)); - if(status != ECA_NORMAL) { + if (0 == pthread_mutex_lock(((CaParam *) (my->specParam))->socketLock)) { + if ((status = ca_search(pPVName, &chan)) == ECA_GETFAIL) { Param_strerror((Param *) my, ca_message(status)); found = 0; - retVal = 0; - } - if(found == 1) { -#ifndef SYNCHRONOUS_GROUP - ParamStringResult resultS, *result = &resultS; - result->val = prefixVal; - result->rows = rows; - result->maxrows = maxrows; - result->my = my; - result->retVal = &retVal; - result->isReady = &isReady; - isReady = 1; - - for (i = 0 ; i < maxrows ; i++) { - prefixVal[i] = malloc(PARAM_MAX_VALUE_LEN); - } - status = ca_array_get_callback(ca_field_type(chan), ca_element_count(chan), chan, Param_copyStringsToAllocMem, result); -#else - status = ca_sg_array_get(pgid, ca_field_type(chan), ca_element_count(chan), chan, prefixVal); -#endif + } else if (status != ECA_NORMAL) { Param_strerror((Param *) my, ca_message(status)); -#ifndef SYNCHRONOUS_GROUP + retVal = -1; + } else { do { - ca_pend_event(TIMEOUTEVT); - } while(isReady == 1); -#else - if((status = ca_sg_block(pgid, TIMEOUTSG)) == ECA_TIMEOUT) { + status = ca_pend_io(TIMEOUTIO); + } while ((ca_state(chan) != cs_conn) && (status != ECA_TIMEOUT)); + if (status != ECA_NORMAL) { + Param_strerror((Param *) my, ca_message(status)); + found = 0; retVal = 0; - *rows = 0; - } else if (status == ECA_NORMAL) { - retVal = 0; - *rows = maxrows > ca_element_count(chan) ? ca_element_count(chan) : maxrows; - } else { - retVal = -1; - *rows = 0; } - ca_sg_delete(pgid); -#endif - - for (i = 0 ; i < *rows ; i++) { - if (*prefixVal[i] == '/') { - strcpy(val[i], prefixVal[i]); - } else { - strcpy(val[i], my->basedir); - strcat(val[i], prefixVal[i]); + if (found == 1) { + ParamStringResult resultS, *result = &resultS; + result->val = prefixVal; + result->rows = rows; + result->maxrows = maxrows; + result->my = my; + result->retVal = &retVal; + result->isReady = &isReady; + isReady = 1; + + for (i = 0 ; i < maxrows ; i++) { + prefixVal[i] = malloc(PARAM_MAX_VALUE_LEN); + } + status = ca_array_get_callback(ca_field_type(chan), ca_element_count(chan), chan, Param_copyStringsToAllocMem, result); + Param_strerror((Param *) my, ca_message(status)); + do { + ca_pend_event(TIMEOUTEVT); + } while(isReady == 1); + + for (i = 0 ; i < *rows ; i++) { + if (*prefixVal[i] == '/') { + strcpy(val[i], prefixVal[i]); + } else { + strcpy(val[i], my->basedir); + strcat(val[i], prefixVal[i]); + } + } + for (i = 0 ; i < maxrows ; i++) { + free(prefixVal[i]); } } - for (i = 0 ; i < maxrows ; i++) { - free(prefixVal[i]); + if ((status = ca_clear_channel(chan)) != ECA_NORMAL) { + Param_strerror((Param *) my, ca_message(status)); } } - if((status = ca_clear_channel(chan)) != ECA_NORMAL) { - Param_strerror((Param *) my, ca_message(status)); - } + pthread_mutex_unlock(((CaParam *) (my->specParam))->socketLock); } free(pPVName); - if(maxrows == 1) { + if (maxrows == 1) { Param_storeStringCache(my, name, idx, *val); } else { for (i = 0 ; i < *rows ; i++) { @@ -440,9 +387,6 @@ int Param_getFilenameArray(const Param *my, const char *name, const char *idx, i int Param_getBlob(const Param *my, const char *name, const char *idx, size_t *size, FILE **val) { -#ifdef SYNCHRONOUS_GROUP - CA_SYNC_GID pgid; -#endif int isReady; int retVal = 0; int status; @@ -453,66 +397,48 @@ int Param_getBlob(const Param *my, const char *name, const char *idx, size_t *si pPVName = malloc((strlen("HAD:PB:") + (my->setup == NULL ? 0 : strlen(my->setup) + 1) + strlen(name) + 1 + strlen(idx) + 1) * sizeof(char)); Param_returnPVName(my, "PB", name, idx, pPVName); - if((status = ca_search(pPVName, &chan)) == ECA_GETFAIL) { - Param_strerror((Param *) my, ca_message(status)); - found = 0; - } else if (status != ECA_NORMAL) { - Param_strerror((Param *) my, ca_message(status)); - retVal = -1; - } else { -#ifdef SYNCHRONOUS_GROUP - ca_sg_create(&pgid); -#endif - do { - status = ca_pend_io(TIMEOUTIO); - } while ((ca_state(chan) != cs_conn) && (status != ECA_TIMEOUT)); - if(status != ECA_NORMAL) { + if (0 == pthread_mutex_lock(((CaParam *) (my->specParam))->socketLock)) { + if ((status = ca_search(pPVName, &chan)) == ECA_GETFAIL) { Param_strerror((Param *) my, ca_message(status)); found = 0; - retVal = 0; - } - if((*val = tmpfile()) == NULL) { - Param_strerror((Param *) my, strerror(errno)); - found = 0; + } else if (status != ECA_NORMAL) { + Param_strerror((Param *) my, ca_message(status)); retVal = -1; - } + } else { + do { + status = ca_pend_io(TIMEOUTIO); + } while ((ca_state(chan) != cs_conn) && (status != ECA_TIMEOUT)); + if (status != ECA_NORMAL) { + Param_strerror((Param *) my, ca_message(status)); + found = 0; + retVal = 0; + } + if ((*val = tmpfile()) == NULL) { + Param_strerror((Param *) my, strerror(errno)); + found = 0; + retVal = -1; + } - if(found == 1) { -#ifndef SYNCHRONOUS_GROUP - ParamBlobResult resultS, *result = &resultS; - result->val = val; - result->size = size; - result->my = my; - result->retVal = &retVal; - result->isReady = &isReady; - isReady = 1; - - status = ca_array_get_callback(ca_field_type(chan), ca_element_count(chan), chan, Param_copyBlobToAllocMem, result); -#else - status = ca_sg_array_get(pgid, ca_field_type(chan), ca_element_count(chan), chan, val); -#endif - Param_strerror((Param *) my, ca_message(status)); -#ifndef SYNCHRONOUS_GROUP - do { - ca_pend_event(TIMEOUTEVT); - } while(isReady == 1); -#else - if((status = ca_sg_block(pgid, TIMEOUTSG)) == ECA_TIMEOUT) { - retVal = 0; - *size = 0; - } else if (status == ECA_NORMAL) { - retVal = 0; - *size = ca_element_count(chan) * sizeof(DBR_LONG); - } else { - retVal = -1; - *size = 0; - } - ca_sg_delete(pgid); -#endif - } - if((status = ca_clear_channel(chan)) != ECA_NORMAL) { - Param_strerror((Param *) my, ca_message(status)); + if (found == 1) { + ParamBlobResult resultS, *result = &resultS; + result->val = val; + result->size = size; + result->my = my; + result->retVal = &retVal; + result->isReady = &isReady; + isReady = 1; + + status = ca_array_get_callback(ca_field_type(chan), ca_element_count(chan), chan, Param_copyBlobToAllocMem, result); + Param_strerror((Param *) my, ca_message(status)); + do { + ca_pend_event(TIMEOUTEVT); + } while(isReady == 1); + } + if ((status = ca_clear_channel(chan)) != ECA_NORMAL) { + Param_strerror((Param *) my, ca_message(status)); + } } + pthread_mutex_unlock(((CaParam *) (my->specParam))->socketLock); } free(pPVName); @@ -522,9 +448,6 @@ int Param_getBlob(const Param *my, const char *name, const char *idx, size_t *si int Param_storeInt(const Param *my, const char *name, const char *idx, unsigned long int value) { -#ifdef SYNCHRONOUS_GROUP - CA_SYNC_GID pgid; -#endif int retVal = 0; int status; int found = 1; @@ -534,52 +457,39 @@ int Param_storeInt(const Param *my, const char *name, const char *idx, unsigned pPVName = malloc((strlen("HAD:PI:") + (my->setup == NULL ? 0 : strlen(my->setup) + 1) + strlen(name) + 1 + strlen(idx) + 1) * sizeof(char)); Param_returnPVName(my, "PI", name, idx, pPVName); - if((status = ca_search(pPVName, &chan)) == ECA_GETFAIL) { - Param_strerror((Param *) my, ca_message(status)); - found = 0; - } else if (status != ECA_NORMAL) { - Param_strerror((Param *) my, ca_message(status)); - retVal = -1; - } else { -#ifdef SYNCHRONOUS_GROUP - ca_sg_create(&pgid); -#endif - do { - status = ca_pend_io(TIMEOUTIO); - } while ((ca_state(chan) != cs_conn) && (status != ECA_TIMEOUT)); - if(status != ECA_NORMAL) { + if (0 == pthread_mutex_lock(((CaParam *) (my->specParam))->socketLock)) { + if ((status = ca_search(pPVName, &chan)) == ECA_GETFAIL) { Param_strerror((Param *) my, ca_message(status)); found = 0; - retVal = 0; - } - if(found == 1) { -#ifndef SYNCHRONOUS_GROUP - ParamConfirmStoreStruct confirmS, *confirm = &confirmS; - int isReady = 1; - confirm->isReady = &isReady; - - status = ca_array_put_callback(DBR_LONG, 1, chan, &value, Param_confirmStore, confirm); -#else - status = ca_sg_array_put(pgid, DBR_LONG, 1, chan, &value); -#endif + } else if (status != ECA_NORMAL) { Param_strerror((Param *) my, ca_message(status)); -#ifndef SYNCHRONOUS_GROUP + retVal = -1; + } else { do { - ca_pend_event(TIMEOUTEVT); - } while(isReady == 1); -#else - if((status = ca_sg_block(pgid, TIMEOUTSG)) == ECA_NORMAL) { + status = ca_pend_io(TIMEOUTIO); + } while ((ca_state(chan) != cs_conn) && (status != ECA_TIMEOUT)); + if (status != ECA_NORMAL) { + Param_strerror((Param *) my, ca_message(status)); + found = 0; retVal = 0; - } else { - retVal = -1; } - ca_sg_delete(pgid); -#endif - } + if (found == 1) { + ParamConfirmStoreStruct confirmS, *confirm = &confirmS; + int isReady = 1; + confirm->isReady = &isReady; + + status = ca_array_put_callback(DBR_LONG, 1, chan, &value, Param_confirmStore, confirm); + Param_strerror((Param *) my, ca_message(status)); + do { + ca_pend_event(TIMEOUTEVT); + } while(isReady == 1); + } - if((status = ca_clear_channel(chan)) != ECA_NORMAL) { - Param_strerror((Param *) my, ca_message(status)); + if ((status = ca_clear_channel(chan)) != ECA_NORMAL) { + Param_strerror((Param *) my, ca_message(status)); + } } + pthread_mutex_unlock(((CaParam *) (my->specParam))->socketLock); } free(pPVName); @@ -589,9 +499,6 @@ int Param_storeInt(const Param *my, const char *name, const char *idx, unsigned int Param_storeString(const Param *my, const char *name, const char *idx, const char *value) { -#ifdef SYNCHRONOUS_GROUP - CA_SYNC_GID pgid; -#endif int retVal = 0; int status; int found = 1; @@ -601,52 +508,39 @@ int Param_storeString(const Param *my, const char *name, const char *idx, const pPVName = malloc((strlen("HAD:PS:") + (my->setup == NULL ? 0 : strlen(my->setup) + 1) + strlen(name) + 1 + strlen(idx) + 1) * sizeof(char)); Param_returnPVName(my, "PS", name, idx, pPVName); - if((status = ca_search(pPVName, &chan)) == ECA_GETFAIL) { - Param_strerror((Param *) my, ca_message(status)); - found = 0; - } else if (status != ECA_NORMAL) { - Param_strerror((Param *) my, ca_message(status)); - retVal = -1; - } else { -#ifdef SYNCHRONOUS_GROUP - ca_sg_create(&pgid); -#endif - do { - status = ca_pend_io(TIMEOUTIO); - } while ((ca_state(chan) != cs_conn) && (status != ECA_TIMEOUT)); - if(status != ECA_NORMAL) { + if (0 == pthread_mutex_lock(((CaParam *) (my->specParam))->socketLock)) { + if ((status = ca_search(pPVName, &chan)) == ECA_GETFAIL) { Param_strerror((Param *) my, ca_message(status)); found = 0; - retVal = 0; - } - if(found == 1) { -#ifndef SYNCHRONOUS_GROUP - ParamConfirmStoreStruct confirmS, *confirm = &confirmS; - int isReady = 1; - confirm->isReady = &isReady; - - status = ca_array_put_callback(DBR_STRING, 1, chan, value, Param_confirmStore, confirm); -#else - status = ca_sg_array_put(pgid, DBR_STRING, 1, chan, &value); -#endif + } else if (status != ECA_NORMAL) { Param_strerror((Param *) my, ca_message(status)); -#ifndef SYNCHRONOUS_GROUP + retVal = -1; + } else { do { - ca_pend_event(TIMEOUTEVT); - } while(isReady == 1); -#else - if((status = ca_sg_block(pgid, TIMEOUTSG)) == ECA_NORMAL) { + status = ca_pend_io(TIMEOUTIO); + } while ((ca_state(chan) != cs_conn) && (status != ECA_TIMEOUT)); + if (status != ECA_NORMAL) { + Param_strerror((Param *) my, ca_message(status)); + found = 0; retVal = 0; - } else { - retVal = -1; } - ca_sg_delete(pgid); -#endif - } + if (found == 1) { + ParamConfirmStoreStruct confirmS, *confirm = &confirmS; + int isReady = 1; + confirm->isReady = &isReady; - if((status = ca_clear_channel(chan)) != ECA_NORMAL) { - Param_strerror((Param *) my, ca_message(status)); + status = ca_array_put_callback(DBR_STRING, 1, chan, value, Param_confirmStore, confirm); + Param_strerror((Param *) my, ca_message(status)); + do { + ca_pend_event(TIMEOUTEVT); + } while(isReady == 1); + } + + if ((status = ca_clear_channel(chan)) != ECA_NORMAL) { + Param_strerror((Param *) my, ca_message(status)); + } } + pthread_mutex_unlock(((CaParam *) (my->specParam))->socketLock); } free(pPVName); @@ -677,7 +571,7 @@ static void Param_copyStringsToAllocMem(struct event_handler_args args) *(result->rows) = (args.count > result->maxrows) ? result->maxrows : args.count; - if(args.type == DBR_STRING && args.status == ECA_NORMAL) { + if (args.type == DBR_STRING && args.status == ECA_NORMAL) { for(i = 0 ; i < *(result->rows) ; i++) { strcpy((result->val)[i], buffer[i]); } @@ -695,7 +589,7 @@ static void Param_copyIntsToAllocMem(struct event_handler_args args) if (args.count == 1) { *(result->rows) = 1; - if(args.type == DBR_LONG && args.status == ECA_NORMAL) { + if (args.type == DBR_LONG && args.status == ECA_NORMAL) { memcpy(result->val, buffer, sizeof(dbr_long_t)); } else { Param_strerror((Param *) result->my, ca_message(args.status)); @@ -707,7 +601,7 @@ static void Param_copyIntsToAllocMem(struct event_handler_args args) } else { *(result->rows) = result->maxrows; } - if(args.type == DBR_LONG && args.status == ECA_NORMAL) { + if (args.type == DBR_LONG && args.status == ECA_NORMAL) { memcpy(result->val, buffer + 2, (sizeof(dbr_long_t) * *(result->rows))); } else { Param_strerror((Param *) result->my, ca_message(args.status)); @@ -721,7 +615,7 @@ static void Param_copyBlobToAllocMem(struct event_handler_args args) { ParamBlobResult *result = args.usr; dbr_long_t *buffer = (dbr_long_t *) args.dbr; - if(args.type == DBR_LONG && args.status == ECA_NORMAL) { + if (args.type == DBR_LONG && args.status == ECA_NORMAL) { *(result->size) = *buffer; fwrite(buffer + 1, 1, *(result->size), *(result->val)); fflush(*(result->val)); @@ -756,7 +650,7 @@ static void Param_returnPVName(const Param *my, const char *type, const char *na static void Param_strerror(Param *my, const char *strerror) { my->strerror = realloc(my->strerror, strlen(strerror) + 1); - if(my->strerror != NULL) { + if (my->strerror != NULL) { strcpy(my->strerror, strerror); } } @@ -772,7 +666,7 @@ static int Param_getIntArrayCache(const Param *my, const char *name, const char strval[i] = malloc(PARAM_MAX_VALUE_LEN * sizeof(char)); } *rows = 0; - if((retVal |= Param_getStringArrayCache(my, name, idx, maxrows, rows, strval)) == 0) { + if ((retVal |= Param_getStringArrayCache(my, name, idx, maxrows, rows, strval)) == 0) { for (i = 0 ; i < *rows ; i++) { val[i] = strtoul(strval[i], &endptr, 0); if (*endptr != '\0') { @@ -804,14 +698,14 @@ static int Param_getStringArrayCache(const Param *my, const char *name, const ch } *rows = 0; - if(Tcl_GetVar2(((CaParam *) (my->specParam))->cache, lname, lidx, 0) != 0) { + if (Tcl_GetVar2(((CaParam *) (my->specParam))->cache, lname, lidx, 0) != 0) { strcpy(val[0], Tcl_GetVar2(((CaParam *) (my->specParam))->cache, lname, lidx, 0)); *rows = 1; } else { char index[PARAM_MAX_NAME_LEN]; for (i = 0 ; i < maxrows ; i++) { sprintf(index,"%s%d", lidx, i); - if(Tcl_GetVar2(((CaParam *) (my->specParam))->cache, lname, index, 0) != 0) { + if (Tcl_GetVar2(((CaParam *) (my->specParam))->cache, lname, index, 0) != 0) { strcpy(val[i], Tcl_GetVar2(((CaParam *) (my->specParam))->cache, lname, index, 0)); (*rows)++; } else { -- 2.43.0