From 325bf271686d5a280ba9f79cf00ba7e034f925c5 Mon Sep 17 00:00:00 2001 From: neverchanje Date: Mon, 15 Oct 2018 12:55:55 +0800 Subject: [PATCH 1/4] valgrind: use function-local initialization to implement singleton --- include/dsn/utility/singleton.h | 54 ++----------------- src/core/core/logging.cpp | 4 +- src/core/core/rpc_engine.cpp | 2 +- src/core/core/service_api_c.cpp | 24 ++++----- src/core/core/service_engine.cpp | 16 +++--- src/core/core/task.cpp | 2 +- src/core/core/task_engine.cpp | 6 +-- src/core/core/tool_api.cpp | 8 +-- src/core/tests/netprovider.cpp | 6 +-- src/core/tests/service_api_c.cpp | 8 +-- src/core/tests/sim_lock.cpp | 9 ++-- src/core/tests/task_engine.cpp | 2 +- .../replication/test/simple_kv/checker.cpp | 2 +- .../replication/test/simple_kv/client.cpp | 12 ++--- .../replication/test/simple_kv/common.cpp | 4 +- .../distributed_lock_service_zookeeper.cpp | 2 +- .../meta_state_service_zookeeper.cpp | 2 +- 17 files changed, 59 insertions(+), 104 deletions(-) diff --git a/include/dsn/utility/singleton.h b/include/dsn/utility/singleton.h index a38aa83961..7b9fabe34e 100644 --- a/include/dsn/utility/singleton.h +++ b/include/dsn/utility/singleton.h @@ -24,19 +24,11 @@ * THE SOFTWARE. */ -/* - * Description: - * What is this file about? - * - * Revision history: - * xxxx-xx-xx, author, first version - * xxxx-xx-xx, author, fix bug about xxx - */ - #pragma once #include #include +#include namespace dsn { namespace utils { @@ -45,48 +37,12 @@ template class singleton { public: - singleton() {} - static T &instance() { - if (nullptr == _instance) { - // lock - while (0 != _l.exchange(1, std::memory_order_acquire)) { - while (_l.load(std::memory_order_consume) == 1) { - } - } - - // re-check and assign - if (nullptr == _instance) { - auto tmp = new T(); - std::atomic_thread_fence(std::memory_order::memory_order_seq_cst); - _instance = tmp; - } - - // unlock - _l.store(0, std::memory_order_release); - } - return *_instance; + static T _instance; + return _instance; } - - static T &fast_instance() { return *_instance; } - - static bool is_instance_created() { return nullptr != _instance; } - -protected: - static T *_instance; - static std::atomic _l; - -private: - singleton(const singleton &); - singleton &operator=(const singleton &); }; -// ----- inline implementations ------------------------------------------------------------------- - -template -T *singleton::_instance = 0; -template -std::atomic singleton::_l(0); -} -} // end namespace dsn::utils +} // namespace utils +} // namespace dsn diff --git a/src/core/core/logging.cpp b/src/core/core/logging.cpp index 6711e3f7e8..b6ee0721bf 100644 --- a/src/core/core/logging.cpp +++ b/src/core/core/logging.cpp @@ -45,7 +45,7 @@ DSN_API dsn_log_level_t dsn_log_start_level = dsn_log_level_t::LOG_LEVEL_INFORMA static void log_on_sys_exit(::dsn::sys_exit_type) { - ::dsn::logging_provider *logger = ::dsn::service_engine::fast_instance().logging(); + ::dsn::logging_provider *logger = ::dsn::service_engine::instance().logging(); if (logger != nullptr) { logger->flush(); } @@ -76,7 +76,7 @@ void dsn_log_init() "flush-log - flush log to stderr or log file", "flush-log", [](const std::vector &args) { - ::dsn::logging_provider *logger = ::dsn::service_engine::fast_instance().logging(); + ::dsn::logging_provider *logger = ::dsn::service_engine::instance().logging(); if (logger != nullptr) { logger->flush(); } diff --git a/src/core/core/rpc_engine.cpp b/src/core/core/rpc_engine.cpp index e46f1ae34c..700908d61c 100644 --- a/src/core/core/rpc_engine.cpp +++ b/src/core/core/rpc_engine.cpp @@ -432,7 +432,7 @@ network *rpc_engine::create_network(const network_server_config &netcs, bool client_only, network_header_format client_hdr_format) { - const service_spec &spec = service_engine::fast_instance().spec(); + const service_spec &spec = service_engine::instance().spec(); network *net = utils::factory_store::create( netcs.factory_name.c_str(), ::dsn::PROVIDER_TYPE_MAIN, this, nullptr); net->reset_parser_attr(client_hdr_format, netcs.message_buffer_block_size); diff --git a/src/core/core/service_api_c.cpp b/src/core/core/service_api_c.cpp index 7ad322bf47..7525c5d9ab 100644 --- a/src/core/core/service_api_c.cpp +++ b/src/core/core/service_api_c.cpp @@ -81,12 +81,12 @@ DSN_API dsn_handle_t dsn_exlock_create(bool recursive) { if (recursive) { ::dsn::lock_provider *last = ::dsn::utils::factory_store<::dsn::lock_provider>::create( - ::dsn::service_engine::fast_instance().spec().lock_factory_name.c_str(), + ::dsn::service_engine::instance().spec().lock_factory_name.c_str(), ::dsn::PROVIDER_TYPE_MAIN, nullptr); // TODO: perf opt by saving the func ptrs somewhere - for (auto &s : ::dsn::service_engine::fast_instance().spec().lock_aspects) { + for (auto &s : ::dsn::service_engine::instance().spec().lock_aspects) { last = ::dsn::utils::factory_store<::dsn::lock_provider>::create( s.c_str(), ::dsn::PROVIDER_TYPE_ASPECT, last); } @@ -95,12 +95,12 @@ DSN_API dsn_handle_t dsn_exlock_create(bool recursive) } else { ::dsn::lock_nr_provider *last = ::dsn::utils::factory_store<::dsn::lock_nr_provider>::create( - ::dsn::service_engine::fast_instance().spec().lock_nr_factory_name.c_str(), + ::dsn::service_engine::instance().spec().lock_nr_factory_name.c_str(), ::dsn::PROVIDER_TYPE_MAIN, nullptr); // TODO: perf opt by saving the func ptrs somewhere - for (auto &s : ::dsn::service_engine::fast_instance().spec().lock_nr_aspects) { + for (auto &s : ::dsn::service_engine::instance().spec().lock_nr_aspects) { last = ::dsn::utils::factory_store<::dsn::lock_nr_provider>::create( s.c_str(), ::dsn::PROVIDER_TYPE_ASPECT, last); } @@ -137,12 +137,12 @@ DSN_API dsn_handle_t dsn_rwlock_nr_create() { ::dsn::rwlock_nr_provider *last = ::dsn::utils::factory_store<::dsn::rwlock_nr_provider>::create( - ::dsn::service_engine::fast_instance().spec().rwlock_nr_factory_name.c_str(), + ::dsn::service_engine::instance().spec().rwlock_nr_factory_name.c_str(), ::dsn::PROVIDER_TYPE_MAIN, nullptr); // TODO: perf opt by saving the func ptrs somewhere - for (auto &s : ::dsn::service_engine::fast_instance().spec().rwlock_nr_aspects) { + for (auto &s : ::dsn::service_engine::instance().spec().rwlock_nr_aspects) { last = ::dsn::utils::factory_store<::dsn::rwlock_nr_provider>::create( s.c_str(), ::dsn::PROVIDER_TYPE_ASPECT, last); } @@ -195,13 +195,13 @@ DSN_API dsn_handle_t dsn_semaphore_create(int initial_count) { ::dsn::semaphore_provider *last = ::dsn::utils::factory_store<::dsn::semaphore_provider>::create( - ::dsn::service_engine::fast_instance().spec().semaphore_factory_name.c_str(), + ::dsn::service_engine::instance().spec().semaphore_factory_name.c_str(), ::dsn::PROVIDER_TYPE_MAIN, initial_count, nullptr); // TODO: perf opt by saving the func ptrs somewhere - for (auto &s : ::dsn::service_engine::fast_instance().spec().semaphore_aspects) { + for (auto &s : ::dsn::service_engine::instance().spec().semaphore_aspects) { last = ::dsn::utils::factory_store<::dsn::semaphore_provider>::create( s.c_str(), ::dsn::PROVIDER_TYPE_ASPECT, initial_count, last); } @@ -606,7 +606,7 @@ bool run(const char *config_file, ::dsn::tls_trans_mem_init(tls_trans_memory_KB * 1024); // prepare minimum necessary - ::dsn::service_engine::fast_instance().init_before_toollets(spec); + ::dsn::service_engine::instance().init_before_toollets(spec); // init logging dsn_log_init(); @@ -630,7 +630,7 @@ bool run(const char *config_file, // TODO: register sys_exit execution // init runtime - ::dsn::service_engine::fast_instance().init_after_toollets(); + ::dsn::service_engine::instance().init_after_toollets(); dsn_all.engine_ready = true; @@ -663,11 +663,11 @@ bool run(const char *config_file, } if (create_it) { - ::dsn::service_engine::fast_instance().start_node(sp); + ::dsn::service_engine::instance().start_node(sp); } } - if (::dsn::service_engine::fast_instance().get_all_nodes().size() == 0) { + if (::dsn::service_engine::instance().get_all_nodes().size() == 0) { printf("no app are created, usually because \n" "app_name is not specified correctly, should be 'xxx' in [apps.xxx]\n" "or app_index (1-based) is greater than specified count in config file\n"); diff --git a/src/core/core/service_engine.cpp b/src/core/core/service_engine.cpp index c22b1c7c7c..4a171df3e0 100644 --- a/src/core/core/service_engine.cpp +++ b/src/core/core/service_engine.cpp @@ -71,7 +71,7 @@ bool service_node::rpc_unregister_handler(dsn::task_code rpc_code) error_code service_node::init_io_engine() { - auto &spec = service_engine::fast_instance().spec(); + auto &spec = service_engine::instance().spec(); error_code err = ERR_OK; // init disk engine @@ -92,7 +92,7 @@ error_code service_node::init_io_engine() error_code service_node::start_io_engine_in_main() { - auto &spec = service_engine::fast_instance().spec(); + auto &spec = service_engine::instance().spec(); error_code err = ERR_OK; // start disk engine @@ -294,16 +294,16 @@ std::string service_engine::get_runtime_info(const std::vector &arg { std::stringstream ss; if (args.size() == 0) { - ss << "" << service_engine::fast_instance()._nodes_by_app_id.size() + ss << "" << service_engine::instance()._nodes_by_app_id.size() << " nodes available:" << std::endl; - for (auto &kv : service_engine::fast_instance()._nodes_by_app_id) { + for (auto &kv : service_engine::instance()._nodes_by_app_id) { ss << "\t" << kv.second->id() << "." << kv.second->full_name() << std::endl; } } else { std::string indent = ""; int id = atoi(args[0].c_str()); - auto it = service_engine::fast_instance()._nodes_by_app_id.find(id); - if (it != service_engine::fast_instance()._nodes_by_app_id.end()) { + auto it = service_engine::instance()._nodes_by_app_id.find(id); + if (it != service_engine::instance()._nodes_by_app_id.end()) { auto args2 = args; args2.erase(args2.begin()); it->second->get_runtime_info(indent, args2, ss); @@ -318,8 +318,8 @@ std::string service_engine::get_queue_info(const std::vector &args) { std::stringstream ss; ss << "["; - for (auto &it : service_engine::fast_instance()._nodes_by_app_id) { - if (it.first != service_engine::fast_instance()._nodes_by_app_id.begin()->first) + for (auto &it : service_engine::instance()._nodes_by_app_id) { + if (it.first != service_engine::instance()._nodes_by_app_id.begin()->first) ss << ","; it.second->get_queue_info(ss); } diff --git a/src/core/core/task.cpp b/src/core/core/task.cpp index c5357b0855..677ae99d14 100644 --- a/src/core/core/task.cpp +++ b/src/core/core/task.cpp @@ -75,7 +75,7 @@ __thread uint16_t tls_dsn_lower32_task_id_mask = 0; tls_dsn.current_task = nullptr; tls_dsn.rpc = node->rpc(); tls_dsn.disk = node->disk(); - tls_dsn.env = service_engine::fast_instance().env(); + tls_dsn.env = service_engine::instance().env(); } tls_dsn.node_pool_thread_ids = (node ? ((uint64_t)(uint8_t)node->id()) : 0) diff --git a/src/core/core/task_engine.cpp b/src/core/core/task_engine.cpp index f57b5bc5cf..452f66c35d 100644 --- a/src/core/core/task_engine.cpp +++ b/src/core/core/task_engine.cpp @@ -80,11 +80,11 @@ void task_worker_pool::create() for (int i = 0; i < qCount; ++i) { auto tsvc = factory_store::create( - service_engine::fast_instance().spec().timer_factory_name.c_str(), + service_engine::instance().spec().timer_factory_name.c_str(), PROVIDER_TYPE_MAIN, _node, nullptr); - for (auto &s : service_engine::fast_instance().spec().timer_aspects) { + for (auto &s : service_engine::instance().spec().timer_aspects) { tsvc = factory_store::create(s.c_str(), PROVIDER_TYPE_ASPECT, _node, tsvc); } @@ -230,7 +230,7 @@ void task_engine::create(const std::list &pools) // init pools _pools.resize(threadpool_code::max() + 1, nullptr); for (auto &p : pools) { - auto &s = service_engine::fast_instance().spec().threadpool_specs[p]; + auto &s = service_engine::instance().spec().threadpool_specs[p]; auto workerPool = new task_worker_pool(s, this); workerPool->create(); _pools[p] = workerPool; diff --git a/src/core/core/tool_api.cpp b/src/core/core/tool_api.cpp index 33949854b2..3f41414a9f 100644 --- a/src/core/core/tool_api.cpp +++ b/src/core/core/tool_api.cpp @@ -80,7 +80,7 @@ tool_app::tool_app(const char *name) : tool_base(name) {} void tool_app::start_all_apps() { - auto apps = service_engine::fast_instance().get_all_nodes(); + auto apps = service_engine::instance().get_all_nodes(); for (auto &kv : apps) { task *t = new service_control_task(kv.second, true); t->set_delay(1000 * kv.second->spec().delay_seconds); @@ -90,16 +90,16 @@ void tool_app::start_all_apps() void tool_app::stop_all_apps(bool cleanup) { - auto apps = service_engine::fast_instance().get_all_nodes(); + auto apps = service_engine::instance().get_all_nodes(); for (auto &kv : apps) { task *t = new service_control_task(kv.second, false, cleanup); t->enqueue(); } } -const service_spec &tool_app::get_service_spec() { return service_engine::fast_instance().spec(); } +const service_spec &tool_app::get_service_spec() { return service_engine::instance().spec(); } -const service_spec &spec() { return service_engine::fast_instance().spec(); } +const service_spec &spec() { return service_engine::instance().spec(); } const char *get_service_node_name(service_node *node) { return node->full_name(); } diff --git a/src/core/tests/netprovider.cpp b/src/core/tests/netprovider.cpp index 2cba226761..0cd9232baa 100644 --- a/src/core/tests/netprovider.cpp +++ b/src/core/tests/netprovider.cpp @@ -113,7 +113,7 @@ void rpc_client_session_send(rpc_session_ptr client_session) TEST(tools_common, asio_net_provider) { - if (dsn::service_engine::fast_instance().spec().semaphore_factory_name == + if (dsn::service_engine::instance().spec().semaphore_factory_name == "dsn::tools::sim_semaphore_provider") return; @@ -160,7 +160,7 @@ TEST(tools_common, asio_net_provider) TEST(tools_common, asio_udp_provider) { - if (dsn::service_engine::fast_instance().spec().semaphore_factory_name == + if (dsn::service_engine::instance().spec().semaphore_factory_name == "dsn::tools::sim_semaphore_provider") return; @@ -202,7 +202,7 @@ TEST(tools_common, asio_udp_provider) TEST(tools_common, sim_net_provider) { - if (dsn::service_engine::fast_instance().spec().semaphore_factory_name == + if (dsn::service_engine::instance().spec().semaphore_factory_name == "dsn::tools::sim_semaphore_provider") return; diff --git a/src/core/tests/service_api_c.cpp b/src/core/tests/service_api_c.cpp index ba9139a72d..8ea1a7202f 100644 --- a/src/core/tests/service_api_c.cpp +++ b/src/core/tests/service_api_c.cpp @@ -147,7 +147,7 @@ TEST(core, dsn_config) TEST(core, dsn_exlock) { - if (dsn::service_engine::fast_instance().spec().semaphore_factory_name == + if (dsn::service_engine::instance().spec().semaphore_factory_name == "dsn::tools::sim_semaphore_provider") return; { @@ -176,7 +176,7 @@ TEST(core, dsn_exlock) TEST(core, dsn_rwlock) { - if (dsn::service_engine::fast_instance().spec().semaphore_factory_name == + if (dsn::service_engine::instance().spec().semaphore_factory_name == "dsn::tools::sim_semaphore_provider") return; dsn_handle_t l = dsn_rwlock_nr_create(); @@ -190,7 +190,7 @@ TEST(core, dsn_rwlock) TEST(core, dsn_semaphore) { - if (dsn::service_engine::fast_instance().spec().semaphore_factory_name == + if (dsn::service_engine::instance().spec().semaphore_factory_name == "dsn::tools::sim_semaphore_provider") return; dsn_handle_t s = dsn_semaphore_create(2); @@ -283,7 +283,7 @@ TEST(core, dsn_file) TEST(core, dsn_env) { - if (dsn::service_engine::fast_instance().spec().tool == "simulator") + if (dsn::service_engine::instance().spec().tool == "simulator") return; uint64_t now1 = dsn_now_ns(); std::this_thread::sleep_for(std::chrono::milliseconds(1)); diff --git a/src/core/tests/sim_lock.cpp b/src/core/tests/sim_lock.cpp index 0586b545df..e13f95a2e8 100644 --- a/src/core/tests/sim_lock.cpp +++ b/src/core/tests/sim_lock.cpp @@ -49,7 +49,7 @@ TEST(tools_simulator, dsn_semaphore) { if (dsn::task::get_current_worker() == nullptr) return; - if (dsn::service_engine::fast_instance().spec().semaphore_factory_name != + if (dsn::service_engine::instance().spec().semaphore_factory_name != "dsn::tools::sim_semaphore_provider") return; dsn_handle_t s = dsn_semaphore_create(2); @@ -65,7 +65,7 @@ TEST(tools_simulator, dsn_lock_nr) { if (dsn::task::get_current_worker() == nullptr) return; - if (dsn::service_engine::fast_instance().spec().lock_nr_factory_name != + if (dsn::service_engine::instance().spec().lock_nr_factory_name != "dsn::tools::sim_lock_nr_provider") return; @@ -81,8 +81,7 @@ TEST(tools_simulator, dsn_lock) { if (dsn::task::get_current_worker() == nullptr) return; - if (dsn::service_engine::fast_instance().spec().lock_factory_name != - "dsn::tools::sim_lock_provider") + if (dsn::service_engine::instance().spec().lock_factory_name != "dsn::tools::sim_lock_provider") return; dsn::tools::sim_lock_provider *s = new dsn::tools::sim_lock_provider(nullptr); @@ -102,7 +101,7 @@ TEST(tools_simulator, scheduler) { if (dsn::task::get_current_worker() == nullptr) return; - if (dsn::service_engine::fast_instance().spec().tool != "simulator") + if (dsn::service_engine::instance().spec().tool != "simulator") return; dsn::tools::sim_worker_state *s = diff --git a/src/core/tests/task_engine.cpp b/src/core/tests/task_engine.cpp index 973f6176ee..b7584f24b7 100644 --- a/src/core/tests/task_engine.cpp +++ b/src/core/tests/task_engine.cpp @@ -70,7 +70,7 @@ DEFINE_THREAD_POOL_CODE(THREAD_POOL_FOR_TEST_2) TEST(core, task_engine) { - if (dsn::service_engine::fast_instance().spec().tool == "simulator") + if (dsn::service_engine::instance().spec().tool == "simulator") return; service_node *node = task::get_current_node2(); ASSERT_NE(nullptr, node); diff --git a/src/dist/replication/test/simple_kv/checker.cpp b/src/dist/replication/test/simple_kv/checker.cpp index 8bb672545a..93d3999bc1 100644 --- a/src/dist/replication/test/simple_kv/checker.cpp +++ b/src/dist/replication/test/simple_kv/checker.cpp @@ -173,7 +173,7 @@ bool test_checker::init(const std::string &name, const std::vectorid(); std::string name = node.second->full_name(); diff --git a/src/dist/replication/test/simple_kv/client.cpp b/src/dist/replication/test/simple_kv/client.cpp index 8ad9abbd0c..96cd4ac864 100644 --- a/src/dist/replication/test/simple_kv/client.cpp +++ b/src/dist/replication/test/simple_kv/client.cpp @@ -94,19 +94,19 @@ void simple_kv_client_app::run() rpc_address node; while (!g_done) { - if (test_case::fast_instance().check_client_write(id, key, value, timeout_ms)) { + if (test_case::instance().check_client_write(id, key, value, timeout_ms)) { begin_write(id, key, value, timeout_ms); continue; } - if (test_case::fast_instance().check_replica_config(receiver, type, node)) { + if (test_case::instance().check_replica_config(receiver, type, node)) { send_config_to_meta(receiver, type, node); continue; } - if (test_case::fast_instance().check_client_read(id, key, timeout_ms)) { + if (test_case::instance().check_client_read(id, key, timeout_ms)) { begin_read(id, key, timeout_ms); continue; } - test_case::fast_instance().wait_check_client(); + test_case::instance().wait_check_client(); } } @@ -135,7 +135,7 @@ void simple_kv_client_app::begin_write(int id, auto &req = ctx->req; _simple_kv_client->write(req, [ctx](error_code err, int32_t resp) { - test_case::fast_instance().on_end_write(ctx->id, err, resp); + test_case::instance().on_end_write(ctx->id, err, resp); }, std::chrono::milliseconds(timeout_ms)); } @@ -172,7 +172,7 @@ void simple_kv_client_app::begin_read(int id, const std::string &key, int timeou ctx->timeout_ms = timeout_ms; _simple_kv_client->read(key, [ctx](error_code err, std::string &&resp) { - test_case::fast_instance().on_end_read(ctx->id, err, resp); + test_case::instance().on_end_read(ctx->id, err, resp); }, std::chrono::milliseconds(timeout_ms)); } diff --git a/src/dist/replication/test/simple_kv/common.cpp b/src/dist/replication/test/simple_kv/common.cpp index 22bfce4fd2..a204e4246a 100644 --- a/src/dist/replication/test/simple_kv/common.cpp +++ b/src/dist/replication/test/simple_kv/common.cpp @@ -94,7 +94,7 @@ std::string address_to_node(rpc_address addr) if (addr.is_invalid()) return "-"; dassert(test_checker::s_inited, ""); - return test_checker::fast_instance().address_to_node_name(addr); + return test_checker::instance().address_to_node_name(addr); } rpc_address node_to_address(const std::string &name) @@ -102,7 +102,7 @@ rpc_address node_to_address(const std::string &name) if (name == "-") return rpc_address(); dassert(test_checker::s_inited, ""); - return test_checker::fast_instance().node_name_to_address(name); + return test_checker::instance().node_name_to_address(name); } std::string gpid_to_string(gpid gpid) diff --git a/src/dist/replication/zookeeper/distributed_lock_service_zookeeper.cpp b/src/dist/replication/zookeeper/distributed_lock_service_zookeeper.cpp index 0b3998750f..1dff571f5b 100644 --- a/src/dist/replication/zookeeper/distributed_lock_service_zookeeper.cpp +++ b/src/dist/replication/zookeeper/distributed_lock_service_zookeeper.cpp @@ -102,7 +102,7 @@ error_code distributed_lock_service_zookeeper::initialize(const std::vector Date: Mon, 15 Oct 2018 23:15:11 +0800 Subject: [PATCH 2/4] make singleton noncopyable --- include/dsn/utility/singleton.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/dsn/utility/singleton.h b/include/dsn/utility/singleton.h index 7b9fabe34e..491defe9d9 100644 --- a/include/dsn/utility/singleton.h +++ b/include/dsn/utility/singleton.h @@ -37,11 +37,18 @@ template class singleton { public: + singleton() = default; + static T &instance() { static T _instance; return _instance; } + +private: + // disallow copy and assign + singleton(const singleton &) = delete; + singleton &operator=(const singleton &) = delete; }; } // namespace utils From c8446946a3c64a71be7a85c8503bbeff5b9e3908 Mon Sep 17 00:00:00 2001 From: neverchanje Date: Mon, 15 Oct 2018 23:17:33 +0800 Subject: [PATCH 3/4] make deleted member public --- include/dsn/utility/singleton.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/include/dsn/utility/singleton.h b/include/dsn/utility/singleton.h index 491defe9d9..145567eae0 100644 --- a/include/dsn/utility/singleton.h +++ b/include/dsn/utility/singleton.h @@ -39,16 +39,15 @@ class singleton public: singleton() = default; + // disallow copy and assign + singleton(const singleton &) = delete; + singleton &operator=(const singleton &) = delete; + static T &instance() { static T _instance; return _instance; } - -private: - // disallow copy and assign - singleton(const singleton &) = delete; - singleton &operator=(const singleton &) = delete; }; } // namespace utils From 74b593d30921480956438f12d4fcf83bb1e77683 Mon Sep 17 00:00:00 2001 From: neverchanje Date: Tue, 16 Oct 2018 16:38:42 +0800 Subject: [PATCH 4/4] remove redundant headers in singleton.h --- include/dsn/utility/singleton.h | 4 ---- src/core/core/utils.cpp | 1 + 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/include/dsn/utility/singleton.h b/include/dsn/utility/singleton.h index 145567eae0..8d65b56de6 100644 --- a/include/dsn/utility/singleton.h +++ b/include/dsn/utility/singleton.h @@ -26,10 +26,6 @@ #pragma once -#include -#include -#include - namespace dsn { namespace utils { diff --git a/src/core/core/utils.cpp b/src/core/core/utils.cpp index 9fb0df09c9..4eebf3df34 100644 --- a/src/core/core/utils.cpp +++ b/src/core/core/utils.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #if defined(__linux__) #include