From 5455e3448dce5352d2c8004d8c3e3d4f167955bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Sun, 27 Oct 2024 16:43:42 +0100 Subject: [PATCH] Assert no database operations on IO threads --- nano/lib/thread_roles.cpp | 11 +++++++---- nano/lib/thread_roles.hpp | 5 +++++ nano/store/transaction.cpp | 1 + 3 files changed, 13 insertions(+), 4 deletions(-) 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"); } /*