mutex: add __fio_mutex_remove()
authorJens Axboe <axboe@fb.com>
Fri, 19 Dec 2014 02:44:18 +0000 (19:44 -0700)
committerJens Axboe <axboe@fb.com>
Fri, 19 Dec 2014 02:44:18 +0000 (19:44 -0700)
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>
filelock.c
mutex.c
mutex.h
server.c

index b252a975aebabcd254fe828c503457514022e066..18e8875ed94211d88c93615cd09b373695af2704 100644 (file)
@@ -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 9ee3bd838cb1ae801b71f2604f94441264130343..53f9651a9887538be42addc8db55a5969bd7b974 100644 (file)
--- a/mutex.c
+++ b/mutex.c
 #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 246afeed0675678e24d2535372be5d64d8793ad1..17380de289a36cb7a76e34870db3c64efd7aa1a5 100644 (file)
--- 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 *);
index ede291fab8f754c4459107d94e97f7ff4870b284..3171979e650e38587c1db6b22b15a04efd2969a2 100644 (file)
--- 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;
 }