diff --git a/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c index f77fce23c..c93fce420 100644 --- a/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c @@ -38,7 +38,6 @@ extern void getIpAddressinString(char *cip, uint32_t ip); int initError = OK; int initCheckDone = 0; char initErrorMessage[MAX_STR_LENGTH]; -sharedMem *thisMem; #ifdef VIRTUAL pthread_t pthread_virtual_tid; @@ -437,9 +436,7 @@ void initStopServer() { #ifdef VIRTUAL virtual_stop = 0; if (!isControlServer) { - lockSharedMemory(thisMem); - thisMem->stop = virtual_stop; - unlockSharedMemory(thisMem); + sharedMemory_setStop(virtual_stop); } #endif } @@ -485,9 +482,7 @@ void setupDetector() { #ifdef VIRTUAL virtual_status = 0; if (isControlServer) { - lockSharedMemory(thisMem); - thisMem->status = virtual_status; - unlockSharedMemory(thisMem); + sharedMemory_setStatus(virtual_status); } memset(virtual_pattern, 0, sizeof(virtual_pattern)); #endif @@ -2227,26 +2222,20 @@ int startStateMachine() { } LOG(logINFOBLUE, ("Starting State Machine\n")); if (isControlServer) { - lockSharedMemory(thisMem); - virtual_stop = thisMem->stop; - unlockSharedMemory(thisMem); + virtual_stop = sharedMemory_getStop(); if (virtual_stop != 0) { LOG(logERROR, ("Cant start acquisition. " "Stop server has not updated stop status to 0\n")); return FAIL; } virtual_status = 1; - lockSharedMemory(thisMem); - thisMem->status = virtual_status; - unlockSharedMemory(thisMem); + sharedMemory_setStatus(virtual_status); } if (pthread_create(&pthread_virtual_tid, NULL, &start_timer, NULL)) { LOG(logERROR, ("Could not start Virtual acquisition thread\n")); virtual_status = 0; if (isControlServer) { - lockSharedMemory(thisMem); - thisMem->status = virtual_status; - unlockSharedMemory(thisMem); + sharedMemory_setStatus(virtual_status); } return FAIL; } @@ -2309,9 +2298,7 @@ void *start_timer(void *arg) { for (int frameNr = 0; frameNr != numFrames; ++frameNr) { // update the virtual stop from stop server - lockSharedMemory(thisMem); - virtual_stop = thisMem->stop; - unlockSharedMemory(thisMem); + virtual_stop = sharedMemory_getStop(); // check if virtual_stop is high if (virtual_stop == 1) { break; @@ -2364,9 +2351,7 @@ void *start_timer(void *arg) { virtual_status = 0; if (isControlServer) { - lockSharedMemory(thisMem); - thisMem->status = virtual_status; - unlockSharedMemory(thisMem); + sharedMemory_setStatus(virtual_status); } LOG(logINFOBLUE, ("Finished Acquiring\n")); return NULL; @@ -2378,20 +2363,15 @@ int stopStateMachine() { #ifdef VIRTUAL if (!isControlServer) { virtual_stop = 1; - lockSharedMemory(thisMem); - virtual_stop = thisMem->stop; - unlockSharedMemory(thisMem); + sharedMemory_setStop(virtual_stop); // read till status is idle int tempStatus = 1; while (tempStatus == 1) { - lockSharedMemory(thisMem); - tempStatus = thisMem->status; - unlockSharedMemory(thisMem); + tempStatus = sharedMemory_getStatus(); } virtual_stop = 0; - lockSharedMemory(thisMem); - virtual_stop = thisMem->stop; - unlockSharedMemory(thisMem); + sharedMemory_setStop(virtual_stop); + virtual_status = tempStatus; LOG(logINFO, ("Stopped State Machine\n")); } return OK; @@ -2409,9 +2389,7 @@ int stopStateMachine() { enum runStatus getRunStatus() { #ifdef VIRTUAL if (!isControlServer) { - lockSharedMemory(thisMem); - virtual_status = thisMem->status; - unlockSharedMemory(thisMem); + virtual_status = sharedMemory_getStatus(); } if (virtual_status == 0) { LOG(logINFOBLUE, ("Status: IDLE\n")); @@ -2694,9 +2672,7 @@ int readFrameFromFifo() { uint32_t runBusy() { #ifdef VIRTUAL if (!isControlServer) { - lockSharedMemory(thisMem); - virtual_status = thisMem->status; - unlockSharedMemory(thisMem); + virtual_status = sharedMemory_getStatus(); } return virtual_status; #endif diff --git a/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c index 5b3c4ab39..4358ec360 100644 --- a/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c @@ -31,7 +31,6 @@ extern void getIpAddressinString(char *cip, uint32_t ip); int initError = OK; int initCheckDone = 0; char initErrorMessage[MAX_STR_LENGTH]; -sharedMem *thisMem; int default_tau_from_file = -1; enum detectorSettings thisSettings; @@ -367,9 +366,7 @@ void initStopServer() { getModuleConfiguration(); virtual_stop = 0; if (!isControlServer) { - lockSharedMemory(thisMem); - thisMem->stop = virtual_stop; - unlockSharedMemory(thisMem); + sharedMemory_setStop(virtual_stop); } // get top/master in virtual readConfigFile(); @@ -674,9 +671,7 @@ void setupDetector() { #ifdef VIRTUAL virtual_status = 0; if (isControlServer) { - lockSharedMemory(thisMem); - thisMem->status = virtual_status; - unlockSharedMemory(thisMem); + sharedMemory_setStatus(virtual_status); } #endif @@ -1993,26 +1988,20 @@ int startStateMachine() { } LOG(logINFOBLUE, ("Starting State Machine\n")); if (isControlServer) { - lockSharedMemory(thisMem); - virtual_stop = thisMem->stop; - unlockSharedMemory(thisMem); + virtual_stop = sharedMemory_getStop(); if (virtual_stop != 0) { LOG(logERROR, ("Cant start acquisition. " "Stop server has not updated stop status to 0\n")); return FAIL; } virtual_status = 1; - lockSharedMemory(thisMem); - thisMem->status = virtual_status; - unlockSharedMemory(thisMem); + sharedMemory_setStatus(virtual_status); } if (pthread_create(&virtual_tid, NULL, &start_timer, NULL)) { LOG(logERROR, ("Could not start Virtual acquisition thread\n")); virtual_status = 0; if (isControlServer) { - lockSharedMemory(thisMem); - thisMem->status = virtual_status; - unlockSharedMemory(thisMem); + sharedMemory_setStatus(virtual_status); } return FAIL; } @@ -2119,9 +2108,7 @@ void *start_timer(void *arg) { usleep(eiger_virtual_transmission_delay_frame); // update the virtual stop from stop server - lockSharedMemory(thisMem); - virtual_stop = thisMem->stop; - unlockSharedMemory(thisMem); + virtual_stop = sharedMemory_getStop(); // check if virtual_stop is high if (virtual_stop == 1) { setStartingFrameNumber(frameNr + iframes + 1); @@ -2224,9 +2211,7 @@ void *start_timer(void *arg) { virtual_status = 0; if (isControlServer) { - lockSharedMemory(thisMem); - thisMem->status = virtual_status; - unlockSharedMemory(thisMem); + sharedMemory_setStatus(virtual_status); } LOG(logINFOBLUE, ("Finished Acquiring\n")); return NULL; @@ -2238,20 +2223,15 @@ int stopStateMachine() { #ifdef VIRTUAL if (!isControlServer) { virtual_stop = 1; - lockSharedMemory(thisMem); - virtual_stop = thisMem->stop; - unlockSharedMemory(thisMem); + sharedMemory_setStop(virtual_stop); // read till status is idle int tempStatus = 1; while (tempStatus == 1) { - lockSharedMemory(thisMem); - tempStatus = thisMem->status; - unlockSharedMemory(thisMem); + tempStatus = sharedMemory_getStatus(); } virtual_stop = 0; - lockSharedMemory(thisMem); - virtual_stop = thisMem->stop; - unlockSharedMemory(thisMem); + sharedMemory_setStop(virtual_stop); + virtual_status = tempStatus; LOG(logINFO, ("Stopped State Machine\n")); } return OK; @@ -2311,9 +2291,7 @@ int startReadOut() { enum runStatus getRunStatus() { #ifdef VIRTUAL if (!isControlServer) { - lockSharedMemory(thisMem); - virtual_status = thisMem->status; - unlockSharedMemory(thisMem); + virtual_status = sharedMemory_getStatus(); } if (virtual_status == 0) { LOG(logINFO, ("Status: IDLE\n")); diff --git a/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c index 80b38c502..698402ab9 100644 --- a/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c @@ -34,7 +34,6 @@ extern void getIpAddressinString(char *cip, uint32_t ip); int initError = OK; int initCheckDone = 0; char initErrorMessage[MAX_STR_LENGTH]; -sharedMem *thisMem; #ifdef VIRTUAL pthread_t pthread_virtual_tid; @@ -346,9 +345,7 @@ void initStopServer() { #ifdef VIRTUAL virtual_stop = 0; if (!isControlServer) { - lockSharedMemory(thisMem); - thisMem->stop = virtual_stop; - unlockSharedMemory(thisMem); + sharedMemory_setStop(virtual_stop); } #endif } @@ -399,9 +396,7 @@ void setupDetector() { #ifdef VIRTUAL virtual_status = 0; if (isControlServer) { - lockSharedMemory(thisMem); - thisMem->status = virtual_status; - unlockSharedMemory(thisMem); + sharedMemory_setStatus(virtual_status); } #endif @@ -2247,26 +2242,20 @@ int startStateMachine() { LOG(logINFOBLUE, ("Starting State Machine\n")); // set status to running if (isControlServer) { - lockSharedMemory(thisMem); - virtual_stop = thisMem->stop; - unlockSharedMemory(thisMem); + virtual_stop = sharedMemory_getStop(); if (virtual_stop != 0) { LOG(logERROR, ("Cant start acquisition. " "Stop server has not updated stop status to 0\n")); return FAIL; } virtual_status = 1; - lockSharedMemory(thisMem); - thisMem->status = virtual_status; - unlockSharedMemory(thisMem); + sharedMemory_setStatus(virtual_status); } if (pthread_create(&pthread_virtual_tid, NULL, &start_timer, NULL)) { LOG(logERROR, ("Could not start Virtual acquisition thread\n")); virtual_status = 0; if (isControlServer) { - lockSharedMemory(thisMem); - thisMem->status = virtual_status; - unlockSharedMemory(thisMem); + sharedMemory_setStatus(virtual_status); } return FAIL; } @@ -2332,9 +2321,7 @@ void *start_timer(void *arg) { for (int frameNr = 0; frameNr != numFrames; ++frameNr) { // update the virtual stop from stop server - lockSharedMemory(thisMem); - virtual_stop = thisMem->stop; - unlockSharedMemory(thisMem); + virtual_stop = sharedMemory_getStop(); // check if virtual_stop is high if (virtual_stop == 1) { break; @@ -2411,9 +2398,7 @@ void *start_timer(void *arg) { virtual_status = 0; if (isControlServer) { - lockSharedMemory(thisMem); - thisMem->status = virtual_status; - unlockSharedMemory(thisMem); + sharedMemory_setStatus(virtual_status); } LOG(logINFOBLUE, ("Finished Acquiring\n")); return NULL; @@ -2425,20 +2410,15 @@ int stopStateMachine() { #ifdef VIRTUAL if (!isControlServer) { virtual_stop = 1; - lockSharedMemory(thisMem); - virtual_stop = thisMem->stop; - unlockSharedMemory(thisMem); + sharedMemory_setStop(virtual_stop); // read till status is idle int tempStatus = 1; while (tempStatus == 1) { - lockSharedMemory(thisMem); - tempStatus = thisMem->status; - unlockSharedMemory(thisMem); + tempStatus = sharedMemory_getStatus(); } virtual_stop = 0; - lockSharedMemory(thisMem); - virtual_stop = thisMem->stop; - unlockSharedMemory(thisMem); + sharedMemory_setStop(virtual_stop); + virtual_status = tempStatus; LOG(logINFO, ("Stopped State Machine\n")); } return OK; @@ -2452,9 +2432,7 @@ int stopStateMachine() { enum runStatus getRunStatus() { #ifdef VIRTUAL if (!isControlServer) { - lockSharedMemory(thisMem); - virtual_status = thisMem->status; - unlockSharedMemory(thisMem); + virtual_status = sharedMemory_getStatus(); } if (virtual_status == 0) { LOG(logINFOBLUE, ("Status: IDLE\n")); @@ -2532,9 +2510,7 @@ void readFrame(int *ret, char *mess) { u_int32_t runBusy() { #ifdef VIRTUAL if (!isControlServer) { - lockSharedMemory(thisMem); - virtual_status = thisMem->status; - unlockSharedMemory(thisMem); + virtual_status = sharedMemory_getStatus(); } return virtual_status; #endif diff --git a/slsDetectorServers/gotthardDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/gotthardDetectorServer/slsDetectorFunctionList.c index 142425524..9c4fd075a 100644 --- a/slsDetectorServers/gotthardDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/gotthardDetectorServer/slsDetectorFunctionList.c @@ -31,7 +31,6 @@ extern void getIpAddressinString(char *cip, uint32_t ip); int initError = OK; int initCheckDone = 0; char initErrorMessage[MAX_STR_LENGTH]; -sharedMem *thisMem; #ifdef VIRTUAL pthread_t pthread_virtual_tid; @@ -360,9 +359,7 @@ void initStopServer() { #ifdef VIRTUAL virtual_stop = 0; if (!isControlServer) { - lockSharedMemory(thisMem); - thisMem->stop = virtual_stop; - unlockSharedMemory(thisMem); + sharedMemory_setStop(virtual_stop); } #endif } @@ -375,9 +372,7 @@ void setupDetector() { #ifdef VIRTUAL virtual_status = 0; if (isControlServer) { - lockSharedMemory(thisMem); - thisMem->status = virtual_status; - unlockSharedMemory(thisMem); + sharedMemory_setStatus(virtual_status); } #endif @@ -1523,26 +1518,20 @@ int startStateMachine() { } LOG(logINFOBLUE, ("Starting State Machine\n")); if (isControlServer) { - lockSharedMemory(thisMem); - virtual_stop = thisMem->stop; - unlockSharedMemory(thisMem); + virtual_stop = sharedMemory_getStop(); if (virtual_stop != 0) { LOG(logERROR, ("Cant start acquisition. " "Stop server has not updated stop status to 0\n")); return FAIL; } virtual_status = 1; - lockSharedMemory(thisMem); - thisMem->status = virtual_status; - unlockSharedMemory(thisMem); + sharedMemory_setStatus(virtual_status); } if (pthread_create(&pthread_virtual_tid, NULL, &start_timer, NULL)) { LOG(logERROR, ("Could not start Virtual acquisition thread\n")); virtual_status = 0; if (isControlServer) { - lockSharedMemory(thisMem); - thisMem->status = virtual_status; - unlockSharedMemory(thisMem); + sharedMemory_setStatus(virtual_status); } return FAIL; } @@ -1592,9 +1581,7 @@ void *start_timer(void *arg) { for (int frameNr = 0; frameNr != numFrames; ++frameNr) { // update the virtual stop from stop server - lockSharedMemory(thisMem); - virtual_stop = thisMem->stop; - unlockSharedMemory(thisMem); + virtual_stop = sharedMemory_getStop(); // check if virtual_stop is high if (virtual_stop == 1) { break; @@ -1639,9 +1626,7 @@ void *start_timer(void *arg) { virtual_status = 0; if (isControlServer) { - lockSharedMemory(thisMem); - thisMem->status = virtual_status; - unlockSharedMemory(thisMem); + sharedMemory_setStatus(virtual_status); } LOG(logINFOBLUE, ("Finished Acquiring\n")); return NULL; @@ -1653,20 +1638,15 @@ int stopStateMachine() { #ifdef VIRTUAL if (!isControlServer) { virtual_stop = 1; - lockSharedMemory(thisMem); - virtual_stop = thisMem->stop; - unlockSharedMemory(thisMem); + sharedMemory_setStop(virtual_stop); // read till status is idle int tempStatus = 1; while (tempStatus == 1) { - lockSharedMemory(thisMem); - tempStatus = thisMem->status; - unlockSharedMemory(thisMem); + tempStatus = sharedMemory_getStatus(); } virtual_stop = 0; - lockSharedMemory(thisMem); - virtual_stop = thisMem->stop; - unlockSharedMemory(thisMem); + sharedMemory_setStop(virtual_stop); + virtual_status = tempStatus; LOG(logINFO, ("Stopped State Machine\n")); } return OK; @@ -1691,9 +1671,7 @@ int stopStateMachine() { enum runStatus getRunStatus() { #ifdef VIRTUAL if (!isControlServer) { - lockSharedMemory(thisMem); - virtual_status = thisMem->status; - unlockSharedMemory(thisMem); + virtual_status = sharedMemory_getStatus(); } if (virtual_status == 0) { LOG(logINFOBLUE, ("Status: IDLE\n")); @@ -1798,9 +1776,7 @@ void readFrame(int *ret, char *mess) { u_int32_t runBusy() { #ifdef VIRTUAL if (!isControlServer) { - lockSharedMemory(thisMem); - virtual_status = thisMem->status; - unlockSharedMemory(thisMem); + virtual_status = sharedMemory_getStatus(); } return virtual_status; #endif diff --git a/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c index 2e5512207..9c38f9d6e 100644 --- a/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c @@ -33,7 +33,6 @@ extern void getIpAddressinString(char *cip, uint32_t ip); int initError = OK; int initCheckDone = 0; char initErrorMessage[MAX_STR_LENGTH]; -sharedMem *thisMem; #ifdef VIRTUAL pthread_t pthread_virtual_tid; @@ -366,9 +365,7 @@ void initStopServer() { #ifdef VIRTUAL virtual_stop = 0; if (!isControlServer) { - lockSharedMemory(thisMem); - thisMem->stop = virtual_stop; - unlockSharedMemory(thisMem); + sharedMemory_setStop(virtual_stop); } // temp threshold and reset event (read by stop server) setThresholdTemperature(DEFAULT_TMP_THRSHLD); @@ -387,9 +384,7 @@ void setupDetector() { #ifdef VIRTUAL virtual_status = 0; if (isControlServer) { - lockSharedMemory(thisMem); - thisMem->status = virtual_status; - unlockSharedMemory(thisMem); + sharedMemory_setStatus(virtual_status); } #endif @@ -1678,26 +1673,20 @@ int startStateMachine() { } LOG(logINFOBLUE, ("starting state machine\n")); if (isControlServer) { - lockSharedMemory(thisMem); - virtual_stop = thisMem->stop; - unlockSharedMemory(thisMem); + virtual_stop = sharedMemory_getStop(); if (virtual_stop != 0) { LOG(logERROR, ("Cant start acquisition. " "Stop server has not updated stop status to 0\n")); return FAIL; } virtual_status = 1; - lockSharedMemory(thisMem); - thisMem->status = virtual_status; - unlockSharedMemory(thisMem); + sharedMemory_setStatus(virtual_status); } if (pthread_create(&pthread_virtual_tid, NULL, &start_timer, NULL)) { LOG(logERROR, ("Could not start Virtual acquisition thread\n")); virtual_status = 0; if (isControlServer) { - lockSharedMemory(thisMem); - thisMem->status = virtual_status; - unlockSharedMemory(thisMem); + sharedMemory_setStatus(virtual_status); } return FAIL; } @@ -1752,9 +1741,7 @@ void *start_timer(void *arg) { usleep(transmissionDelayUs); // update the virtual stop from stop server - lockSharedMemory(thisMem); - virtual_stop = thisMem->stop; - unlockSharedMemory(thisMem); + virtual_stop = sharedMemory_getStop(); // check if virtual_stop is high if (virtual_stop == 1) { setStartingFrameNumber(frameNr + iframes + 1); @@ -1833,9 +1820,7 @@ void *start_timer(void *arg) { virtual_status = 0; if (isControlServer) { - lockSharedMemory(thisMem); - thisMem->status = virtual_status; - unlockSharedMemory(thisMem); + sharedMemory_setStatus(virtual_status); } LOG(logINFOBLUE, ("Finished Acquiring\n")); return NULL; @@ -1847,20 +1832,15 @@ int stopStateMachine() { #ifdef VIRTUAL if (!isControlServer) { virtual_stop = 1; - lockSharedMemory(thisMem); - virtual_stop = thisMem->stop; - unlockSharedMemory(thisMem); + sharedMemory_setStop(virtual_stop); // read till status is idle int tempStatus = 1; while (tempStatus == 1) { - lockSharedMemory(thisMem); - tempStatus = thisMem->status; - unlockSharedMemory(thisMem); + tempStatus = sharedMemory_getStatus(); } virtual_stop = 0; - lockSharedMemory(thisMem); - virtual_stop = thisMem->stop; - unlockSharedMemory(thisMem); + sharedMemory_setStop(virtual_stop); + virtual_status = tempStatus; LOG(logINFO, ("Stopped State Machine\n")); } return OK; @@ -1877,9 +1857,7 @@ int stopStateMachine() { enum runStatus getRunStatus() { #ifdef VIRTUAL if (!isControlServer) { - lockSharedMemory(thisMem); - virtual_status = thisMem->status; - unlockSharedMemory(thisMem); + virtual_status = sharedMemory_getStatus(); } if (virtual_status == 0) { LOG(logINFOBLUE, ("Status: IDLE\n")); @@ -1952,9 +1930,7 @@ void readFrame(int *ret, char *mess) { u_int32_t runBusy() { #ifdef VIRTUAL if (!isControlServer) { - lockSharedMemory(thisMem); - virtual_status = thisMem->status; - unlockSharedMemory(thisMem); + virtual_status = sharedMemory_getStatus(); } return virtual_status; #endif diff --git a/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c index cbd62184c..1cdf449b4 100644 --- a/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c @@ -36,7 +36,6 @@ extern void getIpAddressinString(char *cip, uint32_t ip); int initError = OK; int initCheckDone = 0; char initErrorMessage[MAX_STR_LENGTH]; -sharedMem *thisMem; #ifdef VIRTUAL pthread_t pthread_virtual_tid; @@ -433,9 +432,7 @@ void initStopServer() { #ifdef VIRTUAL virtual_stop = 0; if (!isControlServer) { - lockSharedMemory(thisMem); - thisMem->stop = virtual_stop; - unlockSharedMemory(thisMem); + sharedMemory_setStop(virtual_stop); } #endif } @@ -491,9 +488,7 @@ void setupDetector() { #ifdef VIRTUAL virtual_status = 0; if (isControlServer) { - lockSharedMemory(thisMem); - thisMem->status = virtual_status; - unlockSharedMemory(thisMem); + sharedMemory_setStatus(virtual_status); } memset(virtual_pattern, 0, sizeof(virtual_pattern)); #endif @@ -1860,26 +1855,20 @@ int startStateMachine() { } LOG(logINFOBLUE, ("Starting State Machine\n")); if (isControlServer) { - lockSharedMemory(thisMem); - virtual_stop = thisMem->stop; - unlockSharedMemory(thisMem); + virtual_stop = sharedMemory_getStop(); if (virtual_stop != 0) { LOG(logERROR, ("Cant start acquisition. " "Stop server has not updated stop status to 0\n")); return FAIL; } virtual_status = 1; - lockSharedMemory(thisMem); - thisMem->status = virtual_status; - unlockSharedMemory(thisMem); + sharedMemory_setStatus(virtual_status); } if (pthread_create(&pthread_virtual_tid, NULL, &start_timer, NULL)) { LOG(logERROR, ("Could not start Virtual acquisition thread\n")); virtual_status = 0; if (isControlServer) { - lockSharedMemory(thisMem); - thisMem->status = virtual_status; - unlockSharedMemory(thisMem); + sharedMemory_setStatus(virtual_status); } return FAIL; } @@ -1942,9 +1931,7 @@ void *start_timer(void *arg) { for (int frameNr = 0; frameNr != numFrames; ++frameNr) { // update the virtual stop from stop server - lockSharedMemory(thisMem); - virtual_stop = thisMem->stop; - unlockSharedMemory(thisMem); + virtual_stop = sharedMemory_getStop(); // check if virtual_stop is high if (virtual_stop == 1) { break; @@ -1996,9 +1983,7 @@ void *start_timer(void *arg) { virtual_status = 0; if (isControlServer) { - lockSharedMemory(thisMem); - thisMem->status = virtual_status; - unlockSharedMemory(thisMem); + sharedMemory_setStatus(virtual_status); } LOG(logINFOBLUE, ("Finished Acquiring\n")); return NULL; @@ -2010,20 +1995,15 @@ int stopStateMachine() { #ifdef VIRTUAL if (!isControlServer) { virtual_stop = 1; - lockSharedMemory(thisMem); - virtual_stop = thisMem->stop; - unlockSharedMemory(thisMem); + sharedMemory_setStop(virtual_stop); // read till status is idle int tempStatus = 1; while (tempStatus == 1) { - lockSharedMemory(thisMem); - tempStatus = thisMem->status; - unlockSharedMemory(thisMem); + tempStatus = sharedMemory_getStatus(); } virtual_stop = 0; - lockSharedMemory(thisMem); - virtual_stop = thisMem->stop; - unlockSharedMemory(thisMem); + sharedMemory_setStop(virtual_stop); + virtual_status = tempStatus; LOG(logINFO, ("Stopped State Machine\n")); } return OK; @@ -2041,9 +2021,7 @@ int stopStateMachine() { enum runStatus getRunStatus() { #ifdef VIRTUAL if (!isControlServer) { - lockSharedMemory(thisMem); - virtual_status = thisMem->status; - unlockSharedMemory(thisMem); + virtual_status = sharedMemory_getStatus(); } if (virtual_status == 0) { LOG(logINFOBLUE, ("Status: IDLE\n")); @@ -2283,9 +2261,7 @@ int readFrameFromFifo() { uint32_t runBusy() { #ifdef VIRTUAL if (!isControlServer) { - lockSharedMemory(thisMem); - virtual_status = thisMem->status; - unlockSharedMemory(thisMem); + virtual_status = sharedMemory_getStatus(); } return virtual_status; #endif diff --git a/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c index 188dfd55a..79b9a7679 100644 --- a/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c @@ -32,7 +32,6 @@ extern void getIpAddressinString(char *cip, uint32_t ip); int initError = OK; int initCheckDone = 0; char initErrorMessage[MAX_STR_LENGTH]; -sharedMem *thisMem; #ifdef VIRTUAL pthread_t pthread_virtual_tid; @@ -335,9 +334,7 @@ void initStopServer() { #ifdef VIRTUAL virtual_stop = 0; if (!isControlServer) { - lockSharedMemory(thisMem); - thisMem->stop = virtual_stop; - unlockSharedMemory(thisMem); + sharedMemory_setStop(virtual_stop); } #endif } @@ -394,9 +391,7 @@ void setupDetector() { #ifdef VIRTUAL virtual_status = 0; if (isControlServer) { - lockSharedMemory(thisMem); - thisMem->status = virtual_status; - unlockSharedMemory(thisMem); + sharedMemory_setStatus(virtual_status); } #endif @@ -1987,9 +1982,7 @@ int startStateMachine() { LOG(logINFOBLUE, ("Starting State Machine\n")); // set status to running if (isControlServer) { - lockSharedMemory(thisMem); - virtual_stop = thisMem->stop; - unlockSharedMemory(thisMem); + virtual_stop = sharedMemory_getStop(); if (virtual_stop != 0) { LOG(logERROR, ("Cant start acquisition. " "Stop server has not updated stop status to 0\n")); @@ -1997,17 +1990,13 @@ int startStateMachine() { } virtual_status = 1; - lockSharedMemory(thisMem); - thisMem->status = virtual_status; - unlockSharedMemory(thisMem); + sharedMemory_setStatus(virtual_status); } if (pthread_create(&pthread_virtual_tid, NULL, &start_timer, NULL)) { LOG(logERROR, ("Could not start Virtual acquisition thread\n")); virtual_status = 0; if (isControlServer) { - lockSharedMemory(thisMem); - thisMem->status = virtual_status; - unlockSharedMemory(thisMem); + sharedMemory_setStatus(virtual_status); } return FAIL; } @@ -2051,9 +2040,7 @@ void *start_timer(void *arg) { for (int frameNr = 0; frameNr != numFrames; ++frameNr) { // update the virtual stop from stop server - lockSharedMemory(thisMem); - virtual_stop = thisMem->stop; - unlockSharedMemory(thisMem); + virtual_stop = sharedMemory_getStop(); // check if virtual_stop is high if (virtual_stop == 1) { break; @@ -2106,9 +2093,7 @@ void *start_timer(void *arg) { virtual_status = 0; if (isControlServer) { - lockSharedMemory(thisMem); - thisMem->status = virtual_status; - unlockSharedMemory(thisMem); + sharedMemory_setStatus(virtual_status); } LOG(logINFOBLUE, ("Finished Acquiring\n")); return NULL; @@ -2120,20 +2105,15 @@ int stopStateMachine() { #ifdef VIRTUAL if (!isControlServer) { virtual_stop = 1; - lockSharedMemory(thisMem); - thisMem->stop = virtual_stop; - unlockSharedMemory(thisMem); + sharedMemory_setStop(virtual_stop); // read till status is idle int tempStatus = 1; while (tempStatus == 1) { - lockSharedMemory(thisMem); - tempStatus = thisMem->status; - unlockSharedMemory(thisMem); + tempStatus = sharedMemory_getStatus(); } virtual_stop = 0; - lockSharedMemory(thisMem); - thisMem->stop = virtual_stop; - unlockSharedMemory(thisMem); + sharedMemory_setStop(virtual_stop); + virtual_status = tempStatus; LOG(logINFO, ("Stopped State Machine\n")); } return OK; @@ -2147,9 +2127,7 @@ int stopStateMachine() { enum runStatus getRunStatus() { #ifdef VIRTUAL if (!isControlServer) { - lockSharedMemory(thisMem); - virtual_status = thisMem->status; - unlockSharedMemory(thisMem); + virtual_status = sharedMemory_getStatus(); } if (virtual_status == 0) { LOG(logINFOBLUE, ("Status: IDLE\n")); @@ -2228,9 +2206,7 @@ void readFrame(int *ret, char *mess) { u_int32_t runBusy() { #ifdef VIRTUAL if (!isControlServer) { - lockSharedMemory(thisMem); - virtual_status = thisMem->status; - unlockSharedMemory(thisMem); + virtual_status = sharedMemory_getStatus(); } return virtual_status; #endif diff --git a/slsDetectorServers/slsDetectorServer/include/sharedMemory.h b/slsDetectorServers/slsDetectorServer/include/sharedMemory.h index c74819070..4f2ce14eb 100644 --- a/slsDetectorServers/slsDetectorServer/include/sharedMemory.h +++ b/slsDetectorServers/slsDetectorServer/include/sharedMemory.h @@ -2,22 +2,18 @@ #include -typedef struct Memory { - int version; - sem_t sem; -#ifdef VIRTUAL - int status; - int stop; -#endif -} sharedMem; +char *sharedMemory_getError(); +void sharedMemory_print(); +int sharedMemory_create(int port); +void sharedMemory_initialize(); +int sharedMemory_open(int port); +int sharedMemory_attach(); +int sharedMemory_detach(); +int sharedMemory_remove(); +void sharedMemory_lock(); +void sharedMemory_unlock(); -char *getSharedMemoryError(); -void printSharedMemory(sharedMem *shm); -int createSharedMemory(sharedMem **shm, int port); -void initializeSharedMemory(sharedMem *shm); -int openSharedMemory(sharedMem **shm, int port); -int attachSharedMemory(sharedMem **shm); -int detachSharedMemory(sharedMem **shm); -int removeSharedMemory(); -void lockSharedMemory(); -void unlockSharedMemory(); +void sharedMemory_setStatus(int s); +int sharedMemory_getStatus(); +void sharedMemory_setStop(int s); +int sharedMemory_getStop(); diff --git a/slsDetectorServers/slsDetectorServer/src/sharedMemory.c b/slsDetectorServers/slsDetectorServer/src/sharedMemory.c index 49ce6422c..d226f96ce 100644 --- a/slsDetectorServers/slsDetectorServer/src/sharedMemory.c +++ b/slsDetectorServers/slsDetectorServer/src/sharedMemory.c @@ -16,14 +16,25 @@ #define SHM_NAME "sls_server_shared_memory" #define SHM_VERSION 0x200625 #define SHM_KEY 5678 + +typedef struct Memory { + int version; + sem_t sem; +#ifdef VIRTUAL + int status; + int stop; +#endif +} sharedMem; + +sharedMem *shm = NULL; char shmMess[MAX_STR_LENGTH]; int shmFd = -1; extern int isControlServer; -char *getSharedMemoryError() { return shmMess; } +char *sharedMemory_getError() { return shmMess; } -void printSharedMemory(sharedMem *shm) { +void sharedMemory_print() { LOG(logINFO, ("%s Shared Memory:\n", isControlServer ? "c" : "s")); LOG(logINFO, ("%s version:0x%x\n", isControlServer ? "c" : "s", shm->version)); @@ -33,7 +44,7 @@ void printSharedMemory(sharedMem *shm) { #endif } -int createSharedMemory(sharedMem **shm, int port) { +int sharedMemory_create(int port) { memset(shmMess, 0, MAX_STR_LENGTH); // if sham existed, delete old shm and create again @@ -53,14 +64,14 @@ int createSharedMemory(sharedMem **shm, int port) { return 0; } LOG(logINFO, ("Shared memory created\n")); - if (!attachSharedMemory(shm)) { + if (!sharedMemory_attach()) { return 0; } - initializeSharedMemory(*shm); + sharedMemory_initialize(); return 1; } -void initializeSharedMemory(sharedMem *shm) { +void sharedMemory_initialize() { shm->version = SHM_VERSION; sem_init(&(shm->sem), 1, 1); #ifdef VIRTUAL @@ -70,7 +81,7 @@ void initializeSharedMemory(sharedMem *shm) { LOG(logINFO, ("Shared memory initialized\n")) } -int openSharedMemory(sharedMem **shm, int port) { +int sharedMemory_open(int port) { memset(shmMess, 0, MAX_STR_LENGTH); shmFd = shmget(SHM_KEY + port, sizeof(sharedMem), 0666); if (shmFd == -1) { @@ -78,22 +89,22 @@ int openSharedMemory(sharedMem **shm, int port) { LOG(logERROR, (shmMess)); return 0; } - if (!attachSharedMemory(shm)) { + if (!sharedMemory_attach()) { return 0; } - if ((*shm)->version != SHM_VERSION) { + if (shm->version != SHM_VERSION) { sprintf(shmMess, "Shared memory version 0x%x does not match! (expected: 0x%x)\n", - (*shm)->version, SHM_VERSION); + shm->version, SHM_VERSION); LOG(logERROR, (shmMess)); } LOG(logINFO, ("Shared memory opened\n")); return 1; } -int attachSharedMemory(sharedMem **shm) { - *shm = (sharedMem *)shmat(shmFd, NULL, 0); - if (*shm == (void *)-1) { +int sharedMemory_attach() { + shm = (sharedMem *)shmat(shmFd, NULL, 0); + if (shm == (void *)-1) { sprintf(shmMess, "could not attach: %s\n", strerror(errno)); LOG(logERROR, (shmMess)); return 0; @@ -102,9 +113,9 @@ int attachSharedMemory(sharedMem **shm) { return 1; } -int detachSharedMemory(sharedMem **shm) { +int sharedMemory_detach() { memset(shmMess, 0, MAX_STR_LENGTH); - if (shmdt(*shm) == -1) { + if (shmdt(shm) == -1) { sprintf(shmMess, "could not detach: %s\n", strerror(errno)); LOG(logERROR, (shmMess)); return 0; @@ -113,7 +124,7 @@ int detachSharedMemory(sharedMem **shm) { return 1; } -int removeSharedMemory() { +int sharedMemory_remove() { memset(shmMess, 0, MAX_STR_LENGTH); if (shmctl(shmFd, IPC_RMID, NULL) == -1) { sprintf(shmMess, "could not remove: %s\n", strerror(errno)); @@ -124,6 +135,34 @@ int removeSharedMemory() { return 1; } -void lockSharedMemory(sharedMem *shm) { sem_wait(&(shm->sem)); } +void sharedMemory_lock() { sem_wait(&(shm->sem)); } -void unlockSharedMemory(sharedMem *shm) { sem_post(&(shm->sem)); } \ No newline at end of file +void sharedMemory_unlock() { sem_post(&(shm->sem)); } + +void sharedMemory_setStatus(int s) { + sharedMemory_lock(); + shm->status = s; + sharedMemory_unlock(); +} + +int sharedMemory_getStatus() { + int s = 0; + sharedMemory_lock(); + s = shm->status; + sharedMemory_unlock(); + return s; +} + +void sharedMemory_setStop(int s) { + sharedMemory_lock(); + shm->stop = s; + sharedMemory_unlock(); +} + +int sharedMemory_getStop() { + int s = 0; + sharedMemory_lock(); + s = shm->stop; + sharedMemory_unlock(); + return s; +} diff --git a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer.c b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer.c index b002ff5f9..b3b09f5fe 100644 --- a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer.c +++ b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer.c @@ -26,7 +26,6 @@ extern int checkModuleFlag; #ifdef GOTTHARDD extern int phaseShift; #endif -extern sharedMem *thisMem; void error(char *msg) { perror(msg); } @@ -100,7 +99,7 @@ int main(int argc, char *argv[]) { // control server if (isControlServer) { LOG(logINFOBLUE, ("Control Server [%d]\n", portno)); - if (!createSharedMemory(&thisMem, portno)) { + if (!sharedMemory_create(portno)) { return -1; } #ifdef STOP_SERVER @@ -129,7 +128,7 @@ int main(int argc, char *argv[]) { // stop server else { LOG(logINFOBLUE, ("Stop Server [%d]\n", portno)); - if (!openSharedMemory(&thisMem, portno - 1)) { + if (!sharedMemory_open(portno - 1)) { return -1; } } @@ -161,12 +160,12 @@ int main(int argc, char *argv[]) { exitServer(sockfd); // detach shared memory - if (!detachSharedMemory(&thisMem)) { + if (!sharedMemory_detach()) { return -1; } // remove shared memory (control server) if (isControlServer) { - if (!removeSharedMemory()) { + if (!sharedMemory_remove()) { return -1; } }