diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/core/include/sem.h | 3 | ||||
| -rw-r--r-- | src/lib/core/semaphore.c | 9 |
2 files changed, 10 insertions, 2 deletions
diff --git a/src/lib/core/include/sem.h b/src/lib/core/include/sem.h index 947f9e8..583770a 100644 --- a/src/lib/core/include/sem.h +++ b/src/lib/core/include/sem.h @@ -38,6 +38,8 @@ struct Semaphore { * perror("semaphore_post failed"); * exit(1); * } + * + * semaphore_destroy(&s); * } * @endcode * @@ -50,7 +52,6 @@ struct Semaphore { int semaphore_init(struct Semaphore *s, const char *name, int value); int semaphore_wait(struct Semaphore *s); int semaphore_post(struct Semaphore *s); - void semaphore_destroy(struct Semaphore *s); #endif //STASIS_SEMAPHORE_H
\ No newline at end of file diff --git a/src/lib/core/semaphore.c b/src/lib/core/semaphore.c index 6a24726..5c0e904 100644 --- a/src/lib/core/semaphore.c +++ b/src/lib/core/semaphore.c @@ -9,7 +9,14 @@ #include "utils.h" int semaphore_init(struct Semaphore *s, const char *name, const int value) { - snprintf(s->name, sizeof(s->name), "/%s", name); +#if defined(STASIS_OS_DARWIN) + // see: sem_open(2) + const size_t max_namelen = PSEMNAMLEN; +#else + // see: sem_open(3) + const size_t max_namelen = STASIS_NAME_MAX; +#endif + snprintf(s->name, max_namelen, "/%s", name); s->sem = sem_open(s->name, O_CREAT, 0644, value); if (s->sem == SEM_FAILED) { return -1; |
