X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;ds=inline;f=ucw%2Fsemaphore.h;h=7b211f8e1c9d1d3a0b746bad68531074b87c9c41;hb=0eb6d8317cdbdb28663ff779d31684b3c7a47274;hp=140ba9b9f09c055926273df884655076bbfb56e2;hpb=7ac12546e977cc7b951879529f082ec946619abf;p=libucw.git diff --git a/ucw/semaphore.h b/ucw/semaphore.h index 140ba9b9..7b211f8e 100644 --- a/ucw/semaphore.h +++ b/ucw/semaphore.h @@ -18,36 +18,34 @@ #include #include -#include "ucw/fastbuf.h" // For the temp_file_name +#include // For the temp_file_name /* In Darwin, sem_init() is unfortunately not implemented and the guide * recommends emulating it using sem_open(). */ -static inline sem_t * -sem_alloc(void) +static inline sem_t *sem_alloc(void) { char buf[TEMP_FILE_NAME_LEN]; int mode, retry = 10; + sem_t *sem; do { temp_file_name(buf, &mode); - sem_t *sem = sem_open(buf, mode | O_CREAT, 0777, 0); + sem = sem_open(buf, mode | O_CREAT, 0777, 0); } while (sem == (sem_t*) SEM_FAILED && errno == EEXIST && retry --); ASSERT(sem != (sem_t*) SEM_FAILED); return sem; } -static inline void -sem_free(sem_t *sem) +static inline void sem_free(sem_t *sem) { sem_close(sem); } #else -static inline sem_t * -sem_alloc(void) +static inline sem_t *sem_alloc(void) { sem_t *sem = xmalloc(sizeof(sem_t)); int res = sem_init(sem, 0, 0); @@ -55,8 +53,7 @@ sem_alloc(void) return sem; } -static inline void -sem_free(sem_t *sem) +static inline void sem_free(sem_t *sem) { sem_destroy(sem); xfree(sem);