summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Axboe <axboe@fb.com>2014-12-18 19:44:18 -0700
committerJens Axboe <axboe@fb.com>2014-12-18 19:44:18 -0700
commitf5a425247db49bf1c35738ab50d947c5550f9425 (patch)
tree810c0f8e407f02c05e070367316861605d31fa44
parent83e16fe060881ec991fcf08e4d7a4f219e9f1d5e (diff)
downloadfio-f5a425247db49bf1c35738ab50d947c5550f9425.tar.gz
fio-f5a425247db49bf1c35738ab50d947c5550f9425.tar.bz2
mutex: add __fio_mutex_remove()
We have to remember to free the condvar, so add a __fio_mutex_remove() for cases that init a mutex inside an smalloc'ed region with __fio_mutex_init(). Signed-off-by: Jens Axboe <axboe@fb.com>
-rw-r--r--filelock.c5
-rw-r--r--mutex.c7
-rw-r--r--mutex.h1
-rw-r--r--server.c1
4 files changed, 11 insertions, 3 deletions
diff --git a/filelock.c b/filelock.c
index b252a975..18e8875e 100644
--- a/filelock.c
+++ b/filelock.c
@@ -144,10 +144,11 @@ void fio_unlock_file(const char *fname)
ff = fio_hash_find(hash);
if (ff) {
- ff->references--;
+ int refs = --ff->references;
fio_mutex_up(&ff->lock);
- if (!ff->references) {
+ if (!refs) {
flist_del(&ff->list);
+ __fio_mutex_remove(&ff->lock);
sfree(ff);
}
} else
diff --git a/mutex.c b/mutex.c
index 9ee3bd83..53f9651a 100644
--- a/mutex.c
+++ b/mutex.c
@@ -18,10 +18,15 @@
#include "fio_time.h"
#include "gettime.h"
-void fio_mutex_remove(struct fio_mutex *mutex)
+void __fio_mutex_remove(struct fio_mutex *mutex)
{
assert(mutex->magic == FIO_MUTEX_MAGIC);
pthread_cond_destroy(&mutex->cond);
+}
+
+void fio_mutex_remove(struct fio_mutex *mutex)
+{
+ __fio_mutex_remove(mutex);
munmap((void *) mutex, sizeof(*mutex));
}
diff --git a/mutex.h b/mutex.h
index 246afeed..17380de2 100644
--- a/mutex.h
+++ b/mutex.h
@@ -26,6 +26,7 @@ enum {
extern int __fio_mutex_init(struct fio_mutex *, int);
extern struct fio_mutex *fio_mutex_init(int);
+extern void __fio_mutex_remove(struct fio_mutex *);
extern void fio_mutex_remove(struct fio_mutex *);
extern void fio_mutex_up(struct fio_mutex *);
extern void fio_mutex_down(struct fio_mutex *);
diff --git a/server.c b/server.c
index ede291fa..3171979e 100644
--- a/server.c
+++ b/server.c
@@ -1431,6 +1431,7 @@ fail:
*datap = data;
sfree(rep->data);
+ __fio_mutex_remove(&rep->lock);
sfree(rep);
return 0;
}