X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=mutex.c;h=bbbcccbd0587a7139b247ac4eb38350337fcd912;hp=88044f3a818753feb374bc0370e545fb2095d248;hb=31d23f47d5ee53f74fbf20e17e83c7cb42e39878;hpb=3a8600b4ae9027d02aca7eb1990e5cda4e9f423a diff --git a/mutex.c b/mutex.c index 88044f3a..bbbcccbd 100644 --- a/mutex.c +++ b/mutex.c @@ -15,48 +15,25 @@ void fio_mutex_remove(struct fio_mutex *mutex) { - close(mutex->mutex_fd); munmap((void *) mutex, sizeof(*mutex)); } struct fio_mutex *fio_mutex_init(int value) { - char mutex_name[] = "/tmp/.fio_mutex.XXXXXX"; struct fio_mutex *mutex = NULL; pthread_mutexattr_t attr; pthread_condattr_t cond; - int fd, ret, mflag; - - fd = mkstemp(mutex_name); - if (fd < 0) { - perror("open mutex"); - return NULL; - } - -#ifdef FIO_HAVE_FALLOCATE - ret = posix_fallocate(fd, 0, sizeof(struct fio_mutex)); - if (ret > 0) { - fprintf(stderr, "posix_fallocate mutex failed: %s\n", strerror(ret)); - goto err; - } -#endif - - if (ftruncate(fd, sizeof(struct fio_mutex)) < 0) { - perror("ftruncate mutex"); - goto err; - } + int ret, mflag; mutex = (void *) mmap(NULL, sizeof(struct fio_mutex), - PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + PROT_READ | PROT_WRITE, + OS_MAP_ANON | MAP_SHARED, -1, 0); if (mutex == MAP_FAILED) { perror("mmap mutex"); - close(fd); mutex = NULL; goto err; } - unlink(mutex_name); - mutex->mutex_fd = fd; mutex->value = value; /* @@ -93,12 +70,14 @@ struct fio_mutex *fio_mutex_init(int value) goto err; } + pthread_condattr_destroy(&cond); + pthread_mutexattr_destroy(&attr); + return mutex; err: if (mutex) fio_mutex_remove(mutex); - unlink(mutex_name); return NULL; }