X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=ucw%2Fsemaphore.h;h=a2bc8959118f84d66eee67a6b976a5a75511ad06;hb=1ddc0f01053b355c5805df3659866e11d50d60d0;hp=fa2e0ee473d58318e59bc3683d22eb33d94a8895;hpb=031256ad2e123eec58521f8e3eb9496c197641d2;p=libucw.git diff --git a/ucw/semaphore.h b/ucw/semaphore.h index fa2e0ee4..a2bc8959 100644 --- a/ucw/semaphore.h +++ b/ucw/semaphore.h @@ -16,6 +16,9 @@ #include #include +#include + +#include "ucw/fastbuf.h" // For the temp_file_name /* In Darwin, sem_init() is unfortunately not implemented and the guide * recommends emulating it using sem_open(). */ @@ -23,10 +26,15 @@ static inline sem_t * sem_alloc(void) { - static uns cnt = 0; - char buf[20]; - sprintf(buf, "tmp/sem-%d-%d", getpid(), cnt++); - sem_t *sem = sem_open(buf, O_CREAT, 0777, 0); + char buf[TEMP_FILE_NAME_LEN]; + int mode, retry = 10; + sem_t *sem; + do + { + temp_file_name(buf, &mode); + 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; }