diff --git a/nano/lib/thread_roles.cpp b/nano/lib/thread_roles.cpp index 89b2c5da0c..c8405c240a 100644 --- a/nano/lib/thread_roles.cpp +++ b/nano/lib/thread_roles.cpp @@ -206,9 +206,12 @@ std::string nano::thread_role::get_string () 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); - + auto thread_role_name_string = get_string (role); + nano::thread_role::set_os_name (thread_role_name_string); // Implementation is platform specific current_thread_role = role; } + +bool nano::thread_role::is_network_io () +{ + return nano::thread_role::get () == nano::thread_role::name::io; +} \ No newline at end of file diff --git a/nano/lib/thread_roles.hpp b/nano/lib/thread_roles.hpp index 15b4a511cb..18f26f1cd0 100644 --- a/nano/lib/thread_roles.hpp +++ b/nano/lib/thread_roles.hpp @@ -87,4 +87,9 @@ std::string get_string (); * Internal only, should not be called directly */ void set_os_name (std::string const &); + +/* + * Check if the current thread is a network IO thread + */ +bool is_network_io (); } diff --git a/nano/store/transaction.cpp b/nano/store/transaction.cpp index dcfc3d7e8d..0d1d6a9008 100644 --- a/nano/store/transaction.cpp +++ b/nano/store/transaction.cpp @@ -9,6 +9,7 @@ nano::store::transaction_impl::transaction_impl (nano::id_dispenser::id_t const store_id_a) : store_id{ store_id_a } { + debug_assert (!nano::thread_role::is_network_io (), "database operations are not allowed to run on network IO threads"); } /*