projects
/
fio.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Move setup_rate() out of log.c
[fio.git]
/
mutex.c
diff --git
a/mutex.c
b/mutex.c
index bb417c2741d3c22cd41c707d3a62bc34e0238de1..be3258df8347937a47bf68a99402283d2381b51a 100644
(file)
--- a/
mutex.c
+++ b/
mutex.c
@@
-10,18
+10,17
@@
void fio_sem_remove(struct fio_sem *sem)
{
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)
{
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;
pthread_mutexattr_t attr;
- struct fio_sem *sem;
- char sem_name[32];
int fd;
int fd;
- sprintf(sem_name, "/tmp/.fio_lock.XXXXXX");
fd = mkstemp(sem_name);
if (fd < 0) {
perror("open sem");
fd = mkstemp(sem_name);
if (fd < 0) {
perror("open sem");
@@
-30,7
+29,7
@@
struct fio_sem *fio_sem_init(int value)
if (ftruncate(fd, sizeof(struct fio_sem)) < 0) {
perror("ftruncate sem");
if (ftruncate(fd, sizeof(struct fio_sem)) < 0) {
perror("ftruncate sem");
-
return NULL
;
+
goto err
;
}
sem = mmap(NULL, sizeof(struct fio_sem), PROT_READ | PROT_WRITE,
}
sem = mmap(NULL, sizeof(struct fio_sem), PROT_READ | PROT_WRITE,
@@
-38,13
+37,13
@@
struct fio_sem *fio_sem_init(int value)
if (sem == MAP_FAILED) {
perror("mmap sem");
close(fd);
if (sem == MAP_FAILED) {
perror("mmap sem");
close(fd);
-
unlink(sem_name)
;
-
return NULL
;
+
sem = NULL
;
+
goto err
;
}
}
- close(fd);
+ unlink(sem_name);
+ sem->sem_fd = fd;
sem->value = value;
sem->value = value;
- strcpy(sem->sem_name, sem_name);
if (pthread_mutexattr_init(&attr)) {
perror("pthread_mutexattr_init");
if (pthread_mutexattr_init(&attr)) {
perror("pthread_mutexattr_init");
@@
-61,7
+60,9
@@
struct fio_sem *fio_sem_init(int value)
return sem;
err:
return sem;
err:
- munmap(sem, sizeof(*sem));
+ if (sem)
+ fio_sem_remove(sem);
+
unlink(sem_name);
return NULL;
}
unlink(sem_name);
return NULL;
}