diff options
author | Jens Axboe <jens.axboe@oracle.com> | 2007-03-09 12:40:02 +0100 |
---|---|---|
committer | Jens Axboe <jens.axboe@oracle.com> | 2007-03-09 12:40:02 +0100 |
commit | f7c9e00eee87dc4eb24fc6e6ad68af38ba2bbe98 (patch) | |
tree | d87149ac9bb80147523959ac17f612c20886067f /mutex.c | |
parent | 09629a90d5b68b220e3fb98318e2dcd019943eda (diff) | |
download | fio-f7c9e00eee87dc4eb24fc6e6ad68af38ba2bbe98.tar.gz |
Shrink the semaphores a little
The downside is that they hold the fd open, so it steals one
possible file open per-file. Will fix that in the next commit.
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
Diffstat (limited to 'mutex.c')
-rw-r--r-- | mutex.c | 12 |
1 files changed, 6 insertions, 6 deletions
@@ -10,18 +10,17 @@ 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]; int fd; - sprintf(sem_name, "/tmp/.fio_lock.XXXXXX"); fd = mkstemp(sem_name); if (fd < 0) { perror("open sem"); @@ -42,9 +41,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"); @@ -62,7 +61,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; } |