From f5a425247db49bf1c35738ab50d947c5550f9425 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Thu, 18 Dec 2014 19:44:18 -0700 Subject: [PATCH] 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 --- filelock.c | 5 +++-- mutex.c | 7 ++++++- mutex.h | 1 + server.c | 1 + 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; } -- 2.25.1