mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-06 18:10:40 +02:00
switching to pthread with shared process attribute as sem_init doesnt work for blackfin
This commit is contained in:
parent
3b619f4488
commit
51bfa17c6a
@ -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
|
#define SHM_KEY 5678
|
||||||
#else
|
#define MEM_SIZE 128
|
||||||
#define SHM_VERSION 0x200625
|
|
||||||
#endif
|
|
||||||
#define SHM_KEY 5678
|
|
||||||
#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,47 @@ 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 "
|
pthread_mutexattr_t lockStatusAttribute;
|
||||||
|
if (pthread_mutexattr_init(&lockStatusAttribute) != 0) {
|
||||||
|
LOG(logERROR,
|
||||||
|
("Failed to initialize mutex attribute for lockStatus for "
|
||||||
|
"shared memory\n"));
|
||||||
|
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"));
|
"shared memory\n"));
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#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 +184,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 +247,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
|
Loading…
x
Reference in New Issue
Block a user