Don't force iodepth == 1 for SYNC io engine
[fio.git] / mutex.c
diff --git a/mutex.c b/mutex.c
index 6ec5d573e8a30145f9c53801f560c7edc329acc7..17e62c9f5152c0ab29966915b8874a4a1592ce45 100644 (file)
--- a/mutex.c
+++ b/mutex.c
 
 void fio_sem_remove(struct fio_sem *sem)
 {
-       unlink(sem->sem_name);
+       close(sem->sem_fd);
        munmap(sem, sizeof(*sem));
 }
 
 struct fio_sem *fio_sem_init(int value)
 {
+       char sem_name[] = "/tmp/.fio_sem.XXXXXX";
        struct fio_sem *sem = NULL;
        pthread_mutexattr_t attr;
-       char sem_name[32];
+       pthread_condattr_t cond;
        int fd;
 
-       sprintf(sem_name, "/tmp/.fio_lock.XXXXXX");
        fd = mkstemp(sem_name);
        if (fd < 0) {
                perror("open sem");
@@ -42,9 +42,9 @@ struct fio_sem *fio_sem_init(int value)
                goto err;
        }
 
-       close(fd);
+       unlink(sem_name);
+       sem->sem_fd = fd;
        sem->value = value;
-       strcpy(sem->sem_name, sem_name);
 
        if (pthread_mutexattr_init(&attr)) {
                perror("pthread_mutexattr_init");
@@ -54,6 +54,11 @@ struct fio_sem *fio_sem_init(int value)
                perror("pthread_mutexattr_setpshared");
                goto err;
        }
+
+       pthread_condattr_init(&cond);
+       pthread_condattr_setpshared(&cond, PTHREAD_PROCESS_SHARED);
+       pthread_cond_init(&sem->cond, &cond);
+
        if (pthread_mutex_init(&sem->lock, &attr)) {
                perror("pthread_mutex_init");
                goto err;
@@ -62,7 +67,8 @@ struct fio_sem *fio_sem_init(int value)
        return sem;
 err:
        if (sem)
-               munmap(sem, sizeof(*sem));
+               fio_sem_remove(sem);
+
        unlink(sem_name);
        return NULL;
 }