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 <james.r.harris@intel.com>
Change-Id: I9578bf0f17953b4a7a120de6718cb97258719447

Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/452784
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Jim Harris 2019-05-01 05:35:21 -07:00
parent fe3a2c4dcd
commit 089585c8d7

View File

@ -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<SpdkThreadState *>(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)