Browse Source

shm: Add semget() and semop() replacement for QNX

Change-Id: I7ea831b96cb774fc69b7934c65797a51e9b9ec6a
Signed-off-by: Timo Wischer <twischer@de.adit-jv.com>
pull/463/head
Timo Wischer 6 years ago
parent
commit
012fe027db
1 changed files with 54 additions and 8 deletions
  1. +54
    -8
      common/shm.c

+ 54
- 8
common/shm.c View File

@@ -153,8 +153,6 @@ static jack_shm_registry_t *jack_shm_registry = NULL;
#define JACK_SHM_REGISTRY_KEY JACK_SEMAPHORE_KEY
#endif

static int semid = -1;

#ifdef WIN32

#include <psapi.h>
@@ -183,12 +181,61 @@ static BOOL check_process_running(DWORD process_id)
}

static int
semaphore_init () {return 0;}
jack_shm_lock_registry () {return 0;}

static void
jack_shm_unlock_registry () { }

#elif __QNXNTO__
#include <semaphore.h>

static sem_t* semid = SEM_FAILED;

static int
semaphore_init ()
{
const char name[] = "/jack-shm-registry-lock";
const int oflag = O_CREAT | O_RDWR;
const mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
if ((semid = sem_open(name, oflag, mode, 1)) == SEM_FAILED) {
jack_error("Creating semaphore %s failed", name);
return -1;
}

return 0;
}

static int
jack_shm_lock_registry (void)
{
if (semid == SEM_FAILED) {
if (semaphore_init () < 0)
return -1;
}

// TODO automatically unblock in case the process terminates
const int ret = sem_wait(semid);
if (ret < 0) {
jack_error("sem_wait() failed with %s", strerror(ret));
return -1;
}

return 0;
}

static void
jack_shm_unlock_registry (void)
{
const int ret = sem_post(semid);

static int
semaphore_add (int value) {return 0;}
if (ret < 0) {
jack_error("sem_post() failed with %s", strerror(ret));
}
}

#else
static int semid = -1;

/* all semaphore errors are fatal -- issue message, but do not return */
static void
semaphore_error (char *msg)
@@ -252,8 +299,6 @@ semaphore_add (int value)
return 0;
}

#endif

static int
jack_shm_lock_registry (void)
{
@@ -271,6 +316,8 @@ jack_shm_unlock_registry (void)
semaphore_add (1);
}

#endif

static void
jack_shm_init_registry ()
{
@@ -1313,4 +1360,3 @@ jack_attach_shm_read (jack_shm_info_t* si)
}

#endif /* !USE_POSIX_SHM */


Loading…
Cancel
Save