iolog: cleanup data wait
[fio.git] / iolog.c
diff --git a/iolog.c b/iolog.c
index 865722ea2fd95bac3d6072bcc25d5437d88212bb..0d4d26a599ab6c493af2efdd9096e087c8963d2b 100644 (file)
--- a/iolog.c
+++ b/iolog.c
@@ -996,6 +996,15 @@ static int finish_log(struct thread_data *td, struct io_log *log, int trylock)
 
 #ifdef CONFIG_ZLIB
 
+static void drop_data(struct iolog_flush_data *data, int refs)
+{
+       if (!refs) {
+               free(data);
+               pthread_mutex_destroy(&data->lock);
+               pthread_cond_destroy(&data->cv);
+       }
+}
+
 /*
  * Invoked from our compress helper thread, when logging would have exceeded
  * the specified memory limitation. Compresses the previously stored
@@ -1090,8 +1099,7 @@ done:
                pthread_cond_signal(&data->cv);
                refs = --data->refs;
                pthread_mutex_unlock(&data->lock);
-               if (!refs)
-                       free(data);
+               drop_data(data, refs);
        } else
                free(data);
        return ret;
@@ -1107,6 +1115,7 @@ err:
 
 static struct workqueue_ops log_compress_wq_ops = {
        .fn     = gz_work,
+       .nice   = 1,
 };
 
 int iolog_compress_init(struct thread_data *td)
@@ -1154,14 +1163,13 @@ int iolog_flush(struct io_log *log, int wait)
        data->nr_samples = log->nr_samples;
        log->nr_samples = 0;
 
-       if (wait) {
+       data->wait = wait;
+       if (data->wait) {
                pthread_mutex_init(&data->lock, NULL);
                pthread_cond_init(&data->cv, NULL);
                data->done = 0;
-               data->wait = 1;
                data->refs = 2;
-       } else
-               data->wait = 0;
+       }
 
        workqueue_enqueue(&log->td->log_compress_wq, &data->work);
 
@@ -1173,8 +1181,7 @@ int iolog_flush(struct io_log *log, int wait)
                        pthread_cond_wait(&data->cv, &data->lock);
                refs = --data->refs;
                pthread_mutex_unlock(&data->lock);
-               if (!refs)
-                       free(data);
+               drop_data(data, refs);
        }
 
        return 0;