From 5e3557d2c30f9f1a206d93441897793a993f3618 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Mon, 22 Feb 2016 19:34:09 +0000 Subject: [PATCH] move g_test_dbg_lock_sleep from a global to a function level static This avoids the need to define that variable in every program which uses epee. --- contrib/epee/include/syncobj.h | 17 ++++++++++++----- .../blockchain_converter.cpp | 2 -- src/blockchain_utilities/blockchain_dump.cpp | 2 -- src/blockchain_utilities/blockchain_export.cpp | 2 -- src/blockchain_utilities/blockchain_import.cpp | 2 -- src/blockchain_utilities/cn_deserialize.cpp | 2 -- src/connectivity_tool/conn_tool.cpp | 2 -- src/daemon/daemon.cpp | 2 -- src/daemon/main.cpp | 2 +- src/miner/simpleminer.cpp | 1 - src/simplewallet/simplewallet.cpp | 2 -- tests/core_proxy/core_proxy.cpp | 2 -- tests/core_tests/chaingen_main.cpp | 2 -- tests/functional_tests/main.cpp | 2 -- tests/net_load_tests/clt.cpp | 2 -- tests/net_load_tests/srv.cpp | 2 -- tests/performance_tests/main.cpp | 2 -- tests/unit_tests/main.cpp | 2 -- 18 files changed, 13 insertions(+), 37 deletions(-) diff --git a/contrib/epee/include/syncobj.h b/contrib/epee/include/syncobj.h index 27532443..0833b411 100644 --- a/contrib/epee/include/syncobj.h +++ b/contrib/epee/include/syncobj.h @@ -39,7 +39,14 @@ namespace epee { - extern unsigned int g_test_dbg_lock_sleep; + namespace debug + { + inline unsigned int &g_test_dbg_lock_sleep() + { + static unsigned int value = 0; + return value; + } + } struct simple_event { @@ -217,10 +224,10 @@ namespace epee #define SHARED_CRITICAL_REGION_BEGIN(x) { shared_guard critical_region_var(x) #define EXCLUSIVE_CRITICAL_REGION_BEGIN(x) { exclusive_guard critical_region_var(x) -#define CRITICAL_REGION_LOCAL(x) {std::this_thread::sleep_for(std::chrono::milliseconds(epee::g_test_dbg_lock_sleep));} epee::critical_region_t critical_region_var(x) -#define CRITICAL_REGION_BEGIN(x) { std::this_thread::sleep_for(std::chrono::milliseconds(epee::g_test_dbg_lock_sleep)); epee::critical_region_t critical_region_var(x) -#define CRITICAL_REGION_LOCAL1(x) {std::this_thread::sleep_for(std::chrono::milliseconds(epee::g_test_dbg_lock_sleep));} epee::critical_region_t critical_region_var1(x) -#define CRITICAL_REGION_BEGIN1(x) { std::this_thread::sleep_for(std::chrono::milliseconds(epee::g_test_dbg_lock_sleep)); epee::critical_region_t critical_region_var1(x) +#define CRITICAL_REGION_LOCAL(x) {std::this_thread::sleep_for(std::chrono::milliseconds(epee::debug::g_test_dbg_lock_sleep()));} epee::critical_region_t critical_region_var(x) +#define CRITICAL_REGION_BEGIN(x) { std::this_thread::sleep_for(std::chrono::milliseconds(epee::debug::g_test_dbg_lock_sleep())); epee::critical_region_t critical_region_var(x) +#define CRITICAL_REGION_LOCAL1(x) {std::this_thread::sleep_for(std::chrono::milliseconds(epee::debug::g_test_dbg_lock_sleep()));} epee::critical_region_t critical_region_var1(x) +#define CRITICAL_REGION_BEGIN1(x) { std::this_thread::sleep_for(std::chrono::milliseconds(epee::debug::g_test_dbg_lock_sleep())); epee::critical_region_t critical_region_var1(x) #define CRITICAL_REGION_END() } diff --git a/src/blockchain_utilities/blockchain_converter.cpp b/src/blockchain_utilities/blockchain_converter.cpp index 17b6d81b..7c33ec39 100644 --- a/src/blockchain_utilities/blockchain_converter.cpp +++ b/src/blockchain_utilities/blockchain_converter.cpp @@ -45,8 +45,6 @@ #include -unsigned int epee::g_test_dbg_lock_sleep = 0; - namespace { diff --git a/src/blockchain_utilities/blockchain_dump.cpp b/src/blockchain_utilities/blockchain_dump.cpp index 53dc22f8..6fa5ce80 100644 --- a/src/blockchain_utilities/blockchain_dump.cpp +++ b/src/blockchain_utilities/blockchain_dump.cpp @@ -38,8 +38,6 @@ #include "common/command_line.h" #include "version.h" -unsigned int epee::g_test_dbg_lock_sleep = 0; - namespace po = boost::program_options; using namespace epee; // log_space diff --git a/src/blockchain_utilities/blockchain_export.cpp b/src/blockchain_utilities/blockchain_export.cpp index f5dea731..d90175a7 100644 --- a/src/blockchain_utilities/blockchain_export.cpp +++ b/src/blockchain_utilities/blockchain_export.cpp @@ -31,8 +31,6 @@ #include "common/command_line.h" #include "version.h" -unsigned int epee::g_test_dbg_lock_sleep = 0; - namespace po = boost::program_options; using namespace epee; // log_space diff --git a/src/blockchain_utilities/blockchain_import.cpp b/src/blockchain_utilities/blockchain_import.cpp index 67ad2403..1aaf2bdd 100644 --- a/src/blockchain_utilities/blockchain_import.cpp +++ b/src/blockchain_utilities/blockchain_import.cpp @@ -44,8 +44,6 @@ #include "fake_core.h" -unsigned int epee::g_test_dbg_lock_sleep = 0; - namespace { // CONFIG diff --git a/src/blockchain_utilities/cn_deserialize.cpp b/src/blockchain_utilities/cn_deserialize.cpp index 6c6288ae..bf02dc15 100644 --- a/src/blockchain_utilities/cn_deserialize.cpp +++ b/src/blockchain_utilities/cn_deserialize.cpp @@ -32,8 +32,6 @@ #include "common/command_line.h" #include "version.h" -unsigned int epee::g_test_dbg_lock_sleep = 0; - namespace po = boost::program_options; using namespace epee; // log_space diff --git a/src/connectivity_tool/conn_tool.cpp b/src/connectivity_tool/conn_tool.cpp index 9f00300a..458d30cc 100644 --- a/src/connectivity_tool/conn_tool.cpp +++ b/src/connectivity_tool/conn_tool.cpp @@ -49,8 +49,6 @@ namespace po = boost::program_options; using namespace cryptonote; using namespace nodetool; -unsigned int epee::g_test_dbg_lock_sleep = 0; - namespace { const command_line::arg_descriptor arg_ip = {"ip", "set ip"}; diff --git a/src/daemon/daemon.cpp b/src/daemon/daemon.cpp index ed6a6672..e79823d0 100644 --- a/src/daemon/daemon.cpp +++ b/src/daemon/daemon.cpp @@ -46,8 +46,6 @@ using namespace epee; #include -unsigned int epee::g_test_dbg_lock_sleep = 0; - namespace daemonize { struct t_internals { diff --git a/src/daemon/main.cpp b/src/daemon/main.cpp index 089d8fb6..0717fd89 100644 --- a/src/daemon/main.cpp +++ b/src/daemon/main.cpp @@ -132,7 +132,7 @@ int main(int argc, char const * argv[]) return 0; } - epee::g_test_dbg_lock_sleep = command_line::get_arg(vm, command_line::arg_test_dbg_lock_sleep); + epee::debug::g_test_dbg_lock_sleep() = command_line::get_arg(vm, command_line::arg_test_dbg_lock_sleep); std::string db_type = command_line::get_arg(vm, command_line::arg_db_type); diff --git a/src/miner/simpleminer.cpp b/src/miner/simpleminer.cpp index e04ffbbc..ba956d90 100644 --- a/src/miner/simpleminer.cpp +++ b/src/miner/simpleminer.cpp @@ -41,7 +41,6 @@ using namespace epee; namespace po = boost::program_options; -unsigned int epee::g_test_dbg_lock_sleep = 0; int main(int argc, char** argv) { diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 55bddcdd..e320a624 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -73,8 +73,6 @@ typedef cryptonote::simple_wallet sw; #define EXTENDED_LOGS_FILE "wallet_details.log" -unsigned int epee::g_test_dbg_lock_sleep = 0; - #define DEFAULT_MIX 4 namespace diff --git a/tests/core_proxy/core_proxy.cpp b/tests/core_proxy/core_proxy.cpp index 14a12e13..256faecc 100644 --- a/tests/core_proxy/core_proxy.cpp +++ b/tests/core_proxy/core_proxy.cpp @@ -62,8 +62,6 @@ using namespace crypto; BOOST_CLASS_VERSION(nodetool::node_server >, 1); -unsigned int epee::g_test_dbg_lock_sleep = 0; - int main(int argc, char* argv[]) { diff --git a/tests/core_tests/chaingen_main.cpp b/tests/core_tests/chaingen_main.cpp index 40bce1e4..9f8a5782 100644 --- a/tests/core_tests/chaingen_main.cpp +++ b/tests/core_tests/chaingen_main.cpp @@ -44,8 +44,6 @@ namespace const command_line::arg_descriptor arg_test_transactions = {"test_transactions", ""}; } -unsigned int epee::g_test_dbg_lock_sleep = 0; - int main(int argc, char* argv[]) { TRY_ENTRY(); diff --git a/tests/functional_tests/main.cpp b/tests/functional_tests/main.cpp index 0233c50b..58a2a5c9 100644 --- a/tests/functional_tests/main.cpp +++ b/tests/functional_tests/main.cpp @@ -55,8 +55,6 @@ namespace const command_line::arg_descriptor arg_test_repeat_count = {"test_repeat_count", "", 1}; } -unsigned int epee::g_test_dbg_lock_sleep = 0; - int main(int argc, char* argv[]) { TRY_ENTRY(); diff --git a/tests/net_load_tests/clt.cpp b/tests/net_load_tests/clt.cpp index e6b5c041..56089a4d 100644 --- a/tests/net_load_tests/clt.cpp +++ b/tests/net_load_tests/clt.cpp @@ -628,8 +628,6 @@ TEST_F(net_load_test_clt, permament_open_and_close_and_connections_closed_by_ser ASSERT_EQ(RESERVED_CONN_CNT, m_tcp_server.get_config_object().get_connections_count()); } -unsigned int epee::g_test_dbg_lock_sleep = 0; - int main(int argc, char** argv) { epee::debug::get_set_enable_assert(true, false); diff --git a/tests/net_load_tests/srv.cpp b/tests/net_load_tests/srv.cpp index 5a737e61..d8d3eae2 100644 --- a/tests/net_load_tests/srv.cpp +++ b/tests/net_load_tests/srv.cpp @@ -213,8 +213,6 @@ namespace }; } -unsigned int epee::g_test_dbg_lock_sleep = 0; - int main(int argc, char** argv) { //set up logging options diff --git a/tests/performance_tests/main.cpp b/tests/performance_tests/main.cpp index 2e390fab..84a51aa9 100644 --- a/tests/performance_tests/main.cpp +++ b/tests/performance_tests/main.cpp @@ -42,8 +42,6 @@ #include "generate_key_image_helper.h" #include "is_out_to_acc.h" -unsigned int epee::g_test_dbg_lock_sleep = 0; - int main(int argc, char** argv) { set_process_affinity(1); diff --git a/tests/unit_tests/main.cpp b/tests/unit_tests/main.cpp index b96129a3..faaf9475 100644 --- a/tests/unit_tests/main.cpp +++ b/tests/unit_tests/main.cpp @@ -32,8 +32,6 @@ #include "include_base_utils.h" -unsigned int epee::g_test_dbg_lock_sleep = 0; - int main(int argc, char** argv) { epee::debug::get_set_enable_assert(true, false);