mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2026-01-16 15:15:56 +01:00
eiger: locking for local link access in shared memory
This commit is contained in:
@@ -8,8 +8,8 @@ int sharedMemory_open(int port);
|
||||
int sharedMemory_attach();
|
||||
int sharedMemory_detach();
|
||||
int sharedMemory_remove();
|
||||
void sharedMemory_lock();
|
||||
void sharedMemory_unlock();
|
||||
void sharedMemory_lockStatus();
|
||||
void sharedMemory_unlockStatus();
|
||||
#ifdef VIRTUAL
|
||||
void sharedMemory_setStatus(enum runStatus s);
|
||||
enum runStatus sharedMemory_getStatus();
|
||||
@@ -19,4 +19,8 @@ int sharedMemory_getStop();
|
||||
void sharedMemory_setScanStatus(enum runStatus s);
|
||||
enum runStatus sharedMemory_getScanStatus();
|
||||
void sharedMemory_setScanStop(int s);
|
||||
int sharedMemory_getScanStop();
|
||||
int sharedMemory_getScanStop();
|
||||
#ifdef EIGERD
|
||||
void sharedMemory_lockLocalLink();
|
||||
void sharedMemory_unlockLocalLink();
|
||||
#endif
|
||||
@@ -8,14 +8,21 @@
|
||||
#include <sys/shm.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define SHM_NAME "sls_server_shared_memory"
|
||||
#define SHM_NAME "sls_server_shared_memory"
|
||||
#ifdef EIGERD
|
||||
#define SHM_VERSION 0x200915
|
||||
#else
|
||||
#define SHM_VERSION 0x200625
|
||||
#define SHM_KEY 5678
|
||||
#define MEM_SIZE 128
|
||||
#endif
|
||||
#define SHM_KEY 5678
|
||||
#define MEM_SIZE 128
|
||||
|
||||
typedef struct Memory {
|
||||
int version;
|
||||
pthread_mutex_t lock;
|
||||
pthread_mutex_t lockStatus;
|
||||
#ifdef EIGERD
|
||||
pthread_mutex_t lockLocalLink;
|
||||
#endif
|
||||
enum runStatus scanStatus; // idle, running or error
|
||||
int scanStop;
|
||||
#ifdef VIRTUAL
|
||||
@@ -80,11 +87,18 @@ int sharedMemory_create(int port) {
|
||||
|
||||
int sharedMemory_initialize() {
|
||||
shm->version = SHM_VERSION;
|
||||
if (pthread_mutex_init(&(shm->lock), NULL) != 0) {
|
||||
LOG(logERROR,
|
||||
("Failed to initialize pthread lock for shared memory\n"));
|
||||
if (pthread_mutex_init(&(shm->lockStatus), NULL) != 0) {
|
||||
LOG(logERROR, ("Failed to initialize pthread_mutex_t lockStatus for "
|
||||
"shared memory\n"));
|
||||
return FAIL;
|
||||
}
|
||||
#ifdef EIGERD
|
||||
if (pthread_mutex_init(&(shm->lockLocalLink), NULL) != 0) {
|
||||
LOG(logERROR, ("Failed to initialize pthread_mutex_t lockLocalLink for "
|
||||
"shared memory\n"));
|
||||
return FAIL;
|
||||
}
|
||||
#endif
|
||||
shm->scanStatus = IDLE;
|
||||
shm->scanStop = 0;
|
||||
#ifdef VIRTUAL
|
||||
@@ -141,64 +155,72 @@ int sharedMemory_remove() {
|
||||
return OK;
|
||||
}
|
||||
|
||||
void sharedMemory_lock() { pthread_mutex_lock(&(shm->lock)); }
|
||||
void sharedMemory_lockStatus() { pthread_mutex_lock(&(shm->lockStatus)); }
|
||||
|
||||
void sharedMemory_unlock() { pthread_mutex_unlock(&(shm->lock)); }
|
||||
void sharedMemory_unlockStatus() { pthread_mutex_unlock(&(shm->lockStatus)); }
|
||||
|
||||
#ifdef VIRTUAL
|
||||
void sharedMemory_setStatus(enum runStatus s) {
|
||||
sharedMemory_lock();
|
||||
sharedMemory_lockStatus();
|
||||
shm->status = s;
|
||||
sharedMemory_unlock();
|
||||
sharedMemory_unlockStatus();
|
||||
}
|
||||
|
||||
enum runStatus sharedMemory_getStatus() {
|
||||
enum runStatus s = 0;
|
||||
sharedMemory_lock();
|
||||
sharedMemory_lockStatus();
|
||||
s = shm->status;
|
||||
sharedMemory_unlock();
|
||||
sharedMemory_unlockStatus();
|
||||
return s;
|
||||
}
|
||||
|
||||
void sharedMemory_setStop(int s) {
|
||||
sharedMemory_lock();
|
||||
sharedMemory_lockStatus();
|
||||
shm->stop = s;
|
||||
sharedMemory_unlock();
|
||||
sharedMemory_unlockStatus();
|
||||
}
|
||||
|
||||
int sharedMemory_getStop() {
|
||||
int s = 0;
|
||||
sharedMemory_lock();
|
||||
sharedMemory_lockStatus();
|
||||
s = shm->stop;
|
||||
sharedMemory_unlock();
|
||||
sharedMemory_unlockStatus();
|
||||
return s;
|
||||
}
|
||||
#endif
|
||||
|
||||
void sharedMemory_setScanStatus(enum runStatus s) {
|
||||
sharedMemory_lock();
|
||||
sharedMemory_lockStatus();
|
||||
shm->scanStatus = s;
|
||||
sharedMemory_unlock();
|
||||
sharedMemory_unlockStatus();
|
||||
}
|
||||
|
||||
enum runStatus sharedMemory_getScanStatus() {
|
||||
enum runStatus s = IDLE;
|
||||
sharedMemory_lock();
|
||||
sharedMemory_lockStatus();
|
||||
s = shm->scanStatus;
|
||||
sharedMemory_unlock();
|
||||
sharedMemory_unlockStatus();
|
||||
return s;
|
||||
}
|
||||
|
||||
void sharedMemory_setScanStop(int s) {
|
||||
sharedMemory_lock();
|
||||
sharedMemory_lockStatus();
|
||||
shm->scanStop = s;
|
||||
sharedMemory_unlock();
|
||||
sharedMemory_unlockStatus();
|
||||
}
|
||||
|
||||
int sharedMemory_getScanStop() {
|
||||
int s = 0;
|
||||
sharedMemory_lock();
|
||||
sharedMemory_lockStatus();
|
||||
s = shm->scanStop;
|
||||
sharedMemory_unlock();
|
||||
sharedMemory_unlockStatus();
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef EIGERD
|
||||
void sharedMemory_lockLocalLink() { pthread_mutex_lock(&(shm->lockLocalLink)); }
|
||||
|
||||
void sharedMemory_unlockLocalLink() {
|
||||
pthread_mutex_unlock(&(shm->lockLocalLink));
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user