From 089585c8d7bbf626ceab3bb71687632212584e5e Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Wed, 1 May 2019 05:35:21 -0700 Subject: [PATCH] rocksdb: use C++ constructor for global channel This is similar to what's been done on master, but 19.01 doesn't have the fs_thread_ctx changes, so this looks a bit different. Signed-off-by: Jim Harris Change-Id: I9578bf0f17953b4a7a120de6718cb97258719447 Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/452784 Reviewed-by: Ben Walker --- lib/rocksdb/env_spdk.cc | 47 ++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/lib/rocksdb/env_spdk.cc b/lib/rocksdb/env_spdk.cc index 8c2fe1052..04594e0dc 100644 --- a/lib/rocksdb/env_spdk.cc +++ b/lib/rocksdb/env_spdk.cc @@ -58,11 +58,29 @@ uint32_t g_lcore = 0; std::string g_bdev_name; volatile bool g_spdk_ready = false; volatile bool g_spdk_start_failure = false; -struct sync_args { + +void SpdkInitializeThread(void); + +class SpdkThreadCtx +{ +public: struct spdk_io_channel *channel; + + SpdkThreadCtx(void) : channel(NULL) + { + SpdkInitializeThread(); + } + + ~SpdkThreadCtx(void) + { + } + +private: + SpdkThreadCtx(const SpdkThreadCtx &); + SpdkThreadCtx &operator=(const SpdkThreadCtx &); }; -__thread struct sync_args g_sync_args; +thread_local SpdkThreadCtx g_sync_args; static void __call_fn(void *arg1, void *arg2) @@ -510,7 +528,6 @@ public: } return Status::OK(); } - virtual void StartThread(void (*function)(void *arg), void *arg) override; virtual Status LockFile(const std::string &fname, FileLock **lock) override { std::string name = sanitize_path(fname, mDirectory); @@ -583,35 +600,13 @@ void SpdkInitializeThread(void) { struct spdk_thread *thread; - if (g_fs != NULL) { + if (g_fs != NULL && g_sync_args.channel == NULL) { thread = spdk_thread_create("spdk_rocksdb"); spdk_set_thread(thread); g_sync_args.channel = spdk_fs_alloc_io_channel_sync(g_fs); } } -struct SpdkThreadState { - void (*user_function)(void *); - void *arg; -}; - -static void SpdkStartThreadWrapper(void *arg) -{ - SpdkThreadState *state = reinterpret_cast(arg); - - SpdkInitializeThread(); - state->user_function(state->arg); - delete state; -} - -void SpdkEnv::StartThread(void (*function)(void *arg), void *arg) -{ - SpdkThreadState *state = new SpdkThreadState; - state->user_function = function; - state->arg = arg; - EnvWrapper::StartThread(SpdkStartThreadWrapper, state); -} - static void fs_load_cb(__attribute__((unused)) void *ctx, struct spdk_filesystem *fs, int fserrno)