From: Jens Axboe Date: Fri, 19 Dec 2014 02:44:18 +0000 (-0700) Subject: mutex: add __fio_mutex_remove() X-Git-Tag: fio-2.2.1~4 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=f5a425247db49bf1c35738ab50d947c5550f9425;hp=83e16fe060881ec991fcf08e4d7a4f219e9f1d5e 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 --- 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; }