diff --git a/include/libnuraft/global_mgr.hxx b/include/libnuraft/global_mgr.hxx index bac112a3..c2c9f0fd 100644 --- a/include/libnuraft/global_mgr.hxx +++ b/include/libnuraft/global_mgr.hxx @@ -20,7 +20,6 @@ limitations under the License. #pragma once #include "basic_types.hxx" -#include "event_awaiter.h" #include "pp_util.hxx" #include "ptr.hxx" @@ -121,22 +120,7 @@ public: void request_commit(ptr server); private: - struct worker_handle { - worker_handle(size_t id = 0); - ~worker_handle(); - void shutdown(); - - enum status { - SLEEPING = 0, - WORKING = 1, - }; - - size_t id_; - EventAwaiter ea_; - ptr thread_; - bool stopping_; - std::atomic status_; - }; + struct worker_handle; static std::mutex instance_lock_; static std::atomic instance_; diff --git a/src/global_mgr.cxx b/src/global_mgr.cxx index c2e80687..caf1a5cb 100644 --- a/src/global_mgr.cxx +++ b/src/global_mgr.cxx @@ -19,6 +19,7 @@ limitations under the License. #include "global_mgr.hxx" +#include "event_awaiter.h" #include "logger.hxx" #include "raft_server.hxx" #include "tracer.hxx" @@ -28,29 +29,40 @@ namespace nuraft { std::atomic nuraft_global_mgr::instance_(nullptr); std::mutex nuraft_global_mgr::instance_lock_; +struct nuraft_global_mgr::worker_handle { + worker_handle(size_t id = 0) + : id_(id) + , thread_(nullptr) + , stopping_(false) + , status_(SLEEPING) + {} -nuraft_global_mgr::worker_handle::worker_handle(size_t id) - : id_(id) - , thread_(nullptr) - , stopping_(false) - , status_(SLEEPING) -{ -} - -nuraft_global_mgr::worker_handle::~worker_handle() { - shutdown(); -} + ~worker_handle() { + shutdown(); + } -void nuraft_global_mgr::worker_handle::shutdown() { - stopping_ = true; - if (thread_) { - if (thread_->joinable()) { - ea_.invoke(); - thread_->join(); + void shutdown() { + stopping_ = true; + if (thread_) { + if (thread_->joinable()) { + ea_.invoke(); + thread_->join(); + } + thread_.reset(); } - thread_.reset(); } -} + + enum status { + SLEEPING = 0, + WORKING = 1, + }; + + size_t id_; + EventAwaiter ea_; + ptr thread_; + bool stopping_; + std::atomic status_; +}; nuraft_global_mgr::nuraft_global_mgr() : thread_id_counter_(0)