stat: move stat mutex grab to thread
authorJens Axboe <axboe@fb.com>
Mon, 21 Jul 2014 09:32:13 +0000 (11:32 +0200)
committerJens Axboe <axboe@fb.com>
Mon, 21 Jul 2014 09:32:13 +0000 (11:32 +0200)
No need to grab it from the parent.

Signed-off-by: Jens Axboe <axboe@fb.com>
stat.c

diff --git a/stat.c b/stat.c
index 979c8100d37881fa2a99ee1c184e504b656e6b7c..d8365811b25f8f485724c2a18cf7b43f2af77465 100644 (file)
--- a/stat.c
+++ b/stat.c
@@ -1411,13 +1411,15 @@ void show_run_stats(void)
        fio_mutex_up(stat_mutex);
 }
 
-static void *__show_running_run_stats(void fio_unused *arg)
+static void *__show_running_run_stats(void *arg)
 {
        struct thread_data *td;
        unsigned long long *rt;
        struct timeval tv;
        int i;
 
+       fio_mutex_down(stat_mutex);
+
        rt = malloc(thread_number * sizeof(unsigned long long));
        fio_gettime(&tv, NULL);
 
@@ -1458,6 +1460,7 @@ static void *__show_running_run_stats(void fio_unused *arg)
 
        free(rt);
        fio_mutex_up(stat_mutex);
+       free(arg);
        return NULL;
 }
 
@@ -1468,21 +1471,23 @@ static void *__show_running_run_stats(void fio_unused *arg)
  */
 void show_running_run_stats(void)
 {
-       pthread_t thread;
+       pthread_t *thread;
 
-       fio_mutex_down(stat_mutex);
+       thread = calloc(1, sizeof(*thread));
+       if (!thread)
+               return;
 
-       if (!pthread_create(&thread, NULL, __show_running_run_stats, NULL)) {
+       if (!pthread_create(thread, NULL, __show_running_run_stats, thread)) {
                int err;
 
-               err = pthread_detach(thread);
+               err = pthread_detach(*thread);
                if (err)
                        log_err("fio: DU thread detach failed: %s\n", strerror(err));
 
                return;
        }
 
-       fio_mutex_up(stat_mutex);
+       free(thread);
 }
 
 static int status_interval_init;