Merge branch 'developer' into zmqhwm

This commit is contained in:
maliakal_d 2020-10-07 18:02:53 +02:00
commit c9bba6fbdc
9 changed files with 69 additions and 26 deletions

View File

@ -2,26 +2,22 @@
#include "clogger.h" #include "clogger.h"
#include <errno.h> #include <errno.h>
#include <semaphore.h> #include <pthread.h>
#include <string.h> #include <string.h>
#include <sys/ipc.h> #include <sys/ipc.h>
#include <sys/shm.h> #include <sys/shm.h>
#include <unistd.h> #include <unistd.h>
#define SHM_NAME "sls_server_shared_memory" #define SHM_NAME "sls_server_shared_memory"
#ifdef EIGERD #define SHM_VERSION 0x201007
#define SHM_VERSION 0x200915
#else
#define SHM_VERSION 0x200625
#endif
#define SHM_KEY 5678 #define SHM_KEY 5678
#define MEM_SIZE 128 #define MEM_SIZE 128
typedef struct Memory { typedef struct Memory {
int version; int version;
sem_t semStatus; pthread_mutex_t lockStatus;
#ifdef EIGERD #ifdef EIGERD
sem_t semLocalLink; pthread_mutex_t lockLocalLink;
#endif #endif
enum runStatus scanStatus; // idle, running or error enum runStatus scanStatus; // idle, running or error
int scanStop; int scanStop;
@ -87,14 +83,59 @@ int sharedMemory_create(int port) {
int sharedMemory_initialize() { int sharedMemory_initialize() {
shm->version = SHM_VERSION; shm->version = SHM_VERSION;
if (sem_init(&(shm->semStatus), 1, 1) != 0) {
LOG(logERROR, ("Failed to initialize semaphore semStatus for " // powerpc, Nios and normal pc allows setting mutex attribute to shared
#if defined(EIGERD) || defined(GOTTHARD2D) || defined(MYTHEN3D) || \
defined(VIRTUAL)
pthread_mutexattr_t lockStatusAttribute;
if (pthread_mutexattr_init(&lockStatusAttribute) != 0) {
LOG(logERROR,
("Failed to initialize mutex attribute for lockStatus for "
"shared memory\n")); "shared memory\n"));
return FAIL; return FAIL;
} }
if (pthread_mutexattr_setpshared(&lockStatusAttribute,
PTHREAD_PROCESS_SHARED) != 0) {
LOG(logERROR, ("Failed to set attribute property to process shared for "
"lockStatus for shared memory\n"));
return FAIL;
}
if (pthread_mutex_init(&(shm->lockStatus), &lockStatusAttribute) != 0) {
LOG(logERROR, ("Failed to initialize pthread_mutex_t lockStatus for "
"shared memory\n"));
return FAIL;
}
// only blackfins cannot set mutex attribute (but it is shared by default)
#else
if (pthread_mutex_init(&(shm->lockStatus), NULL) != 0) {
LOG(logERROR, ("Failed to initialize pthread_mutex_t lockStatus for "
"shared memory\n"));
return FAIL;
}
#endif
#ifdef EIGERD #ifdef EIGERD
if (sem_init(&(shm->semLocalLink), 1, 1) != 0) { pthread_mutexattr_t lockLocalLinkAttribute;
LOG(logERROR, ("Failed to initialize semaphore semLocalLink for " if (pthread_mutexattr_init(&lockLocalLinkAttribute) != 0) {
LOG(logERROR,
("Failed to initialize mutex attribute for lockLocalLink for "
"shared memory\n"));
return FAIL;
}
if (pthread_mutexattr_setpshared(&lockLocalLinkAttribute,
PTHREAD_PROCESS_SHARED) != 0) {
LOG(logERROR, ("Failed to set attribute property to process shared for "
"lockLocalLink for shared memory\n"));
return FAIL;
}
if (pthread_mutex_init(&(shm->lockLocalLink), &lockLocalLinkAttribute) !=
0) {
LOG(logERROR, ("Failed to initialize pthread_mutex_t lockLocalLink for "
"shared memory\n")); "shared memory\n"));
return FAIL; return FAIL;
} }
@ -155,9 +196,9 @@ int sharedMemory_remove() {
return OK; return OK;
} }
void sharedMemory_lockStatus() { sem_wait(&(shm->semStatus)); } void sharedMemory_lockStatus() { pthread_mutex_lock(&(shm->lockStatus)); }
void sharedMemory_unlockStatus() { sem_post(&(shm->semStatus)); } void sharedMemory_unlockStatus() { pthread_mutex_unlock(&(shm->lockStatus)); }
#ifdef VIRTUAL #ifdef VIRTUAL
void sharedMemory_setStatus(enum runStatus s) { void sharedMemory_setStatus(enum runStatus s) {
@ -218,7 +259,9 @@ int sharedMemory_getScanStop() {
} }
#ifdef EIGERD #ifdef EIGERD
void sharedMemory_lockLocalLink() { sem_wait(&(shm->semLocalLink)); } void sharedMemory_lockLocalLink() { pthread_mutex_lock(&(shm->lockLocalLink)); }
void sharedMemory_unlockLocalLink() { sem_post(&(shm->semLocalLink)); } void sharedMemory_unlockLocalLink() {
pthread_mutex_unlock(&(shm->lockLocalLink));
}
#endif #endif

View File

@ -3,10 +3,10 @@
#define APILIB 0x201002 #define APILIB 0x201002
#define APIRECEIVER 0x201002 #define APIRECEIVER 0x201002
#define APIGUI 0x201002 #define APIGUI 0x201002
#define APIGOTTHARD 0x201005 #define APIEIGER 0x201007
#define APIGOTTHARD2 0x201005 #define APICTB 0x201007
#define APIJUNGFRAU 0x201005 #define APIGOTTHARD 0x201007
#define APIMYTHEN3 0x201005 #define APIGOTTHARD2 0x201007
#define APIEIGER 0x201005 #define APIJUNGFRAU 0x201007
#define APICTB 0x201006 #define APIMYTHEN3 0x201007
#define APIMOENCH 0x201006 #define APIMOENCH 0x201007