2 * The UCW Library -- POSIX semaphores wrapper
4 * (c) 2006 Robert Spalek <robert@ucw.cz>
6 * This software may be freely distributed and used according to the terms
7 * of the GNU Lesser General Public License.
10 #ifndef _UCW_SEMAPHORE_H
11 #define _UCW_SEMAPHORE_H
13 #include <semaphore.h>
21 #include <ucw/fastbuf.h> // For the temp_file_name
23 /* In Darwin, sem_init() is unfortunately not implemented and the guide
24 * recommends emulating it using sem_open(). */
26 static inline sem_t *sem_alloc(void)
28 char buf[TEMP_FILE_NAME_LEN];
33 temp_file_name(buf, &mode);
34 sem = sem_open(buf, mode | O_CREAT, 0777, 0);
36 while (sem == (sem_t*) SEM_FAILED && errno == EEXIST && retry --);
37 ASSERT(sem != (sem_t*) SEM_FAILED);
41 static inline void sem_free(sem_t *sem)
48 static inline sem_t *sem_alloc(void)
50 sem_t *sem = xmalloc(sizeof(sem_t));
51 int res = sem_init(sem, 0, 0);
56 static inline void sem_free(sem_t *sem)