From dba54900006b4381e619660ffcfa042be88f2ba4 Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Wed, 10 May 2017 16:07:33 -0700 Subject: [PATCH] nvme/fio_plugin: make setup callback thread safe Change-Id: I40f858a204bf0ca5e594fc8efcb1a31849e6709b Signed-off-by: Daniel Verkamp --- examples/nvme/fio_plugin/fio_plugin.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/examples/nvme/fio_plugin/fio_plugin.c b/examples/nvme/fio_plugin/fio_plugin.c index 7bb6d302d..1a991bd0a 100644 --- a/examples/nvme/fio_plugin/fio_plugin.c +++ b/examples/nvme/fio_plugin/fio_plugin.c @@ -61,7 +61,7 @@ struct spdk_fio_ctrlr { struct spdk_fio_ctrlr *ctrlr_g; int td_count; -pthread_mutex_t mutex; +pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; struct spdk_fio_qpair { struct fio_file *f; @@ -216,6 +216,8 @@ static int spdk_fio_setup(struct thread_data *td) return 1; } + pthread_mutex_lock(&mutex); + fio_thread = calloc(1, sizeof(*fio_thread)); assert(fio_thread != NULL); @@ -233,7 +235,6 @@ static int spdk_fio_setup(struct thread_data *td) spdk_env_init(&opts); spdk_env_initialized = true; cpu_core_unaffinitized(); - pthread_mutex_init(&mutex, NULL); } for_each_file(td, f, i) { @@ -292,6 +293,8 @@ static int spdk_fio_setup(struct thread_data *td) td_count++; + pthread_mutex_unlock(&mutex); + return 0; }