Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some code cleanup #2449

Merged
merged 4 commits into from
Jan 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions nano/core_test/locks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ TEST (locks, no_conflicts)

TEST (locks, lock_guard)
{
// This test can end up taking a long time, as it sleeps for the NANO_TIMED_LOCKS amount
ASSERT_LE (NANO_TIMED_LOCKS, 10000);

std::stringstream ss;
nano::cout_redirect redirect (ss.rdbuf ());

Expand Down Expand Up @@ -72,6 +75,9 @@ TEST (locks, lock_guard)

TEST (locks, unique_lock)
{
// This test can end up taking a long time, as it sleeps for the NANO_TIMED_LOCKS amount
ASSERT_LE (NANO_TIMED_LOCKS, 10000);

std::stringstream ss;
nano::cout_redirect redirect (ss.rdbuf ());

Expand Down
11 changes: 4 additions & 7 deletions nano/lib/alarm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,15 @@ void nano::alarm::add (std::chrono::steady_clock::time_point const & wakeup_a, s
condition.notify_all ();
}

namespace nano
std::unique_ptr<nano::container_info_component> nano::collect_container_info (alarm & alarm, const std::string & name)
{
std::unique_ptr<seq_con_info_component> collect_seq_con_info (alarm & alarm, const std::string & name)
{
auto composite = std::make_unique<seq_con_info_composite> (name);
size_t count = 0;
size_t count;
{
nano::lock_guard<std::mutex> guard (alarm.mutex);
count = alarm.operations.size ();
}
auto sizeof_element = sizeof (decltype (alarm.operations)::value_type);
composite->add_component (std::make_unique<seq_con_info_leaf> (seq_con_info{ "operations", count, sizeof_element }));
auto composite = std::make_unique<container_info_composite> (name);
composite->add_component (std::make_unique<container_info_leaf> (container_info{ "operations", count, sizeof_element }));
return composite;
}
}
4 changes: 2 additions & 2 deletions nano/lib/alarm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ class alarm final
std::priority_queue<operation, std::vector<operation>, std::greater<operation>> operations;
std::thread thread;
};
class seq_con_info_component;
std::unique_ptr<seq_con_info_component> collect_seq_con_info (alarm & alarm, const std::string & name);
class container_info_component;
std::unique_ptr<container_info_component> collect_container_info (alarm & alarm, const std::string & name);
}
9 changes: 3 additions & 6 deletions nano/lib/blocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1619,14 +1619,11 @@ size_t nano::block_uniquer::size ()
return blocks.size ();
}

namespace nano
{
std::unique_ptr<seq_con_info_component> collect_seq_con_info (block_uniquer & block_uniquer, const std::string & name)
std::unique_ptr<nano::container_info_component> nano::collect_container_info (block_uniquer & block_uniquer, const std::string & name)
{
auto count = block_uniquer.size ();
auto sizeof_element = sizeof (block_uniquer::value_type);
auto composite = std::make_unique<seq_con_info_composite> (name);
composite->add_component (std::make_unique<seq_con_info_leaf> (seq_con_info{ "blocks", count, sizeof_element }));
auto composite = std::make_unique<container_info_composite> (name);
composite->add_component (std::make_unique<container_info_leaf> (container_info{ "blocks", count, sizeof_element }));
return composite;
}
}
2 changes: 1 addition & 1 deletion nano/lib/blocks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ class block_uniquer
static unsigned constexpr cleanup_count = 2;
};

std::unique_ptr<seq_con_info_component> collect_seq_con_info (block_uniquer & block_uniquer, const std::string & name);
std::unique_ptr<container_info_component> collect_container_info (block_uniquer & block_uniquer, const std::string & name);

std::shared_ptr<nano::block> deserialize_block (nano::stream &);
std::shared_ptr<nano::block> deserialize_block (nano::stream &, nano::block_type, nano::block_uniquer * = nullptr);
Expand Down
10 changes: 5 additions & 5 deletions nano/lib/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ namespace filesystem
/**
* Returns build version information
*/
static const char * NANO_VERSION_STRING = xstr (TAG_VERSION_STRING);
const char * const NANO_VERSION_STRING = xstr (TAG_VERSION_STRING);

static const char * BUILD_INFO = xstr (GIT_COMMIT_HASH BOOST_COMPILER) " \"BOOST " xstr (BOOST_VERSION) "\" BUILT " xstr (__DATE__);
const char * const BUILD_INFO = xstr (GIT_COMMIT_HASH BOOST_COMPILER) " \"BOOST " xstr (BOOST_VERSION) "\" BUILT " xstr (__DATE__);

/** Is TSAN/ASAN test build */
#if defined(__has_feature)
#if __has_feature(thread_sanitizer) || __has_feature(address_sanitizer)
static const bool is_sanitizer_build = true;
const bool is_sanitizer_build = true;
#else
static const bool is_sanitizer_build = false;
const bool is_sanitizer_build = false;
#endif
#else
static const bool is_sanitizer_build = false;
const bool is_sanitizer_build = false;
#endif

namespace nano
Expand Down
8 changes: 4 additions & 4 deletions nano/lib/rep_weights.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,16 @@ nano::uint128_t nano::rep_weights::get (nano::account const & account_a)
}
}

std::unique_ptr<nano::seq_con_info_component> nano::collect_seq_con_info (nano::rep_weights & rep_weights, const std::string & name)
std::unique_ptr<nano::container_info_component> nano::collect_container_info (nano::rep_weights & rep_weights, const std::string & name)
{
size_t rep_amounts_count = 0;
size_t rep_amounts_count;

{
nano::lock_guard<std::mutex> guard (rep_weights.mutex);
rep_amounts_count = rep_weights.rep_amounts.size ();
}
auto sizeof_element = sizeof (decltype (rep_weights.rep_amounts)::value_type);
auto composite = std::make_unique<nano::seq_con_info_composite> (name);
composite->add_component (std::make_unique<nano::seq_con_info_leaf> (seq_con_info{ "rep_amounts", rep_amounts_count, sizeof_element }));
auto composite = std::make_unique<nano::container_info_composite> (name);
composite->add_component (std::make_unique<nano::container_info_leaf> (container_info{ "rep_amounts", rep_amounts_count, sizeof_element }));
return composite;
}
4 changes: 2 additions & 2 deletions nano/lib/rep_weights.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class rep_weights
void put (nano::account const & account_a, nano::uint128_union const & representation_a);
nano::uint128_t get (nano::account const & account_a);

friend std::unique_ptr<seq_con_info_component> collect_seq_con_info (rep_weights &, const std::string &);
friend std::unique_ptr<container_info_component> collect_container_info (rep_weights &, const std::string &);
};

std::unique_ptr<seq_con_info_component> collect_seq_con_info (rep_weights &, const std::string &);
std::unique_ptr<container_info_component> collect_container_info (rep_weights &, const std::string &);
}
161 changes: 77 additions & 84 deletions nano/lib/threading.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,104 +2,97 @@

#include <iostream>

namespace nano
namespace
{
namespace thread_role
thread_local nano::thread_role::name current_thread_role = nano::thread_role::name::unknown;
}

nano::thread_role::name nano::thread_role::get ()
{
/*
* nano::thread_role namespace
*
* Manage thread role
*/
static thread_local nano::thread_role::name current_thread_role = nano::thread_role::name::unknown;
nano::thread_role::name get ()
{
return current_thread_role;
}
return current_thread_role;
}

std::string get_string (nano::thread_role::name role)
{
std::string thread_role_name_string;
std::string nano::thread_role::get_string (nano::thread_role::name role)
{
std::string thread_role_name_string;

switch (role)
{
case nano::thread_role::name::unknown:
thread_role_name_string = "<unknown>";
break;
case nano::thread_role::name::io:
thread_role_name_string = "I/O";
break;
case nano::thread_role::name::work:
thread_role_name_string = "Work pool";
break;
case nano::thread_role::name::packet_processing:
thread_role_name_string = "Pkt processing";
break;
case nano::thread_role::name::alarm:
thread_role_name_string = "Alarm";
break;
case nano::thread_role::name::vote_processing:
thread_role_name_string = "Vote processing";
break;
case nano::thread_role::name::block_processing:
thread_role_name_string = "Blck processing";
break;
case nano::thread_role::name::request_loop:
thread_role_name_string = "Request loop";
break;
case nano::thread_role::name::wallet_actions:
thread_role_name_string = "Wallet actions";
break;
case nano::thread_role::name::work_watcher:
thread_role_name_string = "Work watcher";
break;
case nano::thread_role::name::bootstrap_initiator:
thread_role_name_string = "Bootstrap init";
break;
case nano::thread_role::name::voting:
thread_role_name_string = "Voting";
break;
case nano::thread_role::name::signature_checking:
thread_role_name_string = "Signature check";
break;
case nano::thread_role::name::rpc_request_processor:
thread_role_name_string = "RPC processor";
break;
case nano::thread_role::name::rpc_process_container:
thread_role_name_string = "RPC process";
break;
case nano::thread_role::name::confirmation_height_processing:
thread_role_name_string = "Conf height";
break;
case nano::thread_role::name::worker:
thread_role_name_string = "Worker";
break;
}
switch (role)
{
case nano::thread_role::name::unknown:
thread_role_name_string = "<unknown>";
break;
case nano::thread_role::name::io:
thread_role_name_string = "I/O";
break;
case nano::thread_role::name::work:
thread_role_name_string = "Work pool";
break;
case nano::thread_role::name::packet_processing:
thread_role_name_string = "Pkt processing";
break;
case nano::thread_role::name::alarm:
thread_role_name_string = "Alarm";
break;
case nano::thread_role::name::vote_processing:
thread_role_name_string = "Vote processing";
break;
case nano::thread_role::name::block_processing:
thread_role_name_string = "Blck processing";
break;
case nano::thread_role::name::request_loop:
thread_role_name_string = "Request loop";
break;
case nano::thread_role::name::wallet_actions:
thread_role_name_string = "Wallet actions";
break;
case nano::thread_role::name::work_watcher:
thread_role_name_string = "Work watcher";
break;
case nano::thread_role::name::bootstrap_initiator:
thread_role_name_string = "Bootstrap init";
break;
case nano::thread_role::name::voting:
thread_role_name_string = "Voting";
break;
case nano::thread_role::name::signature_checking:
thread_role_name_string = "Signature check";
break;
case nano::thread_role::name::rpc_request_processor:
thread_role_name_string = "RPC processor";
break;
case nano::thread_role::name::rpc_process_container:
thread_role_name_string = "RPC process";
break;
case nano::thread_role::name::confirmation_height_processing:
thread_role_name_string = "Conf height";
break;
case nano::thread_role::name::worker:
thread_role_name_string = "Worker";
break;
}

/*
/*
* We want to constrain the thread names to 15
* characters, since this is the smallest maximum
* length supported by the platforms we support
* (specifically, Linux)
*/
assert (thread_role_name_string.size () < 16);
return (thread_role_name_string);
}
assert (thread_role_name_string.size () < 16);
return (thread_role_name_string);
}

std::string get_string ()
{
return get_string (current_thread_role);
}
std::string nano::thread_role::get_string ()
{
return get_string (current_thread_role);
}

void set (nano::thread_role::name role)
{
auto thread_role_name_string (get_string (role));
void nano::thread_role::set (nano::thread_role::name role)
{
auto thread_role_name_string (get_string (role));

nano::thread_role::set_os_name (thread_role_name_string);
nano::thread_role::set_os_name (thread_role_name_string);

nano::thread_role::current_thread_role = role;
}
}
current_thread_role = role;
}

void nano::thread_attributes::set (boost::thread::attributes & attrs)
Expand Down
23 changes: 10 additions & 13 deletions nano/lib/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,61 +27,58 @@
#endif
#endif

namespace nano
{
seq_con_info_composite::seq_con_info_composite (const std::string & name) :
nano::container_info_composite::container_info_composite (const std::string & name) :
name (name)
{
}

bool seq_con_info_composite::is_composite () const
bool nano::container_info_composite::is_composite () const
{
return true;
}

void seq_con_info_composite::add_component (std::unique_ptr<seq_con_info_component> child)
void nano::container_info_composite::add_component (std::unique_ptr<container_info_component> child)
{
children.push_back (std::move (child));
}

const std::vector<std::unique_ptr<seq_con_info_component>> & seq_con_info_composite::get_children () const
const std::vector<std::unique_ptr<nano::container_info_component>> & nano::container_info_composite::get_children () const
{
return children;
}

const std::string & seq_con_info_composite::get_name () const
const std::string & nano::container_info_composite::get_name () const
{
return name;
}

seq_con_info_leaf::seq_con_info_leaf (const seq_con_info & info) :
nano::container_info_leaf::container_info_leaf (const container_info & info) :
info (info)
{
}

bool seq_con_info_leaf::is_composite () const
bool nano::container_info_leaf::is_composite () const
{
return false;
}

const seq_con_info & seq_con_info_leaf::get_info () const
const nano::container_info & nano::container_info_leaf::get_info () const
{
return info;
}

void dump_crash_stacktrace ()
void nano::dump_crash_stacktrace ()
{
boost::stacktrace::safe_dump_to ("nano_node_backtrace.dump");
}

std::string generate_stacktrace ()
std::string nano::generate_stacktrace ()
{
auto stacktrace = boost::stacktrace::stacktrace ();
std::stringstream ss;
ss << stacktrace;
return ss.str ();
}
}

void nano::remove_all_files_in_dir (boost::filesystem::path const & dir)
{
Expand Down
Loading