45 sem =
malloc(
sizeof(sem_t));
48 if (sem_init(sem, 1,
count) < 0)
54#if PORTABLE_SEMAPHORES
56#define MAP_ANONYMOUS MAP_ANON
58 sem = mmap(
NULL, getpagesize(),
59 PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_SHARED, -1, 0);
60 if (sem == MAP_FAILED)
63 sprintf(
buf,
"/%d:sem%d:g", getpid(),
id);
65 sem->guard = sem_open(
buf, O_CREAT, 0600,
count);
67 sprintf(
buf,
"/%d:sem%d:s", getpid(),
id);
69 sem->sig = sem_open(
buf, O_CREAT, 0600,
count);
72 sprintf(
buf,
"/%d:sem%d", getpid(),
id);
74 sem = sem_open(
buf, O_CREAT, 0600,
count);
77#if !PORTABLE_SEMAPHORES
78 if (sem == SEM_FAILED || !sem)
98#if PORTABLE_SEMAPHORES
116#if PORTABLE_SEMAPHORES
117 int trywait = si_sem_trywait(
semaphore[
id]->sig);
119 int trywait = si_sem_trywait(
semaphore[
id]);
123#if PORTABLE_SEMAPHORES
139#if PORTABLE_SEMAPHORES
157#if PORTABLE_SEMAPHORES
169 if (strcmp(cmd,
"init")==0)
171 else if (strcmp(cmd,
"exists")==0)
173 else if (strcmp(cmd,
"acquire")==0)
175 else if (strcmp(cmd,
"try_acquire")==0)
177 else if (strcmp(cmd,
"release")==0)
179 else if (strcmp(cmd,
"get_value")==0)
181 else printf(
"unknown\n");
VAR volatile BOOLEAN do_shutdown
VAR volatile int defer_shutdown
const Variable & v
< [in] a sqrfree bivariate poly
int sipc_semaphore_get_value(int id)
int sipc_semaphore_acquire(int id)
VAR sipc_sem_t * semaphore[SIPC_MAX_SEMAPHORES]
VAR int sem_acquired[SIPC_MAX_SEMAPHORES]
int sipc_semaphore_release(int id)
int simpleipc_cmd(char *cmd, int id, int v)
int sipc_semaphore_exists(int id)
int sipc_semaphore_try_acquire(int id)
int sipc_semaphore_init(int id, int count)
int status int void size_t count
int status int void * buf
#define SIPC_MAX_SEMAPHORES