Skip to content

Commit

Permalink
Assert no database operations on IO threads
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Oct 27, 2024
1 parent 47539ac commit 251d3e7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
18 changes: 14 additions & 4 deletions nano/lib/thread_roles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,19 @@ 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 ()
{
switch (get ())
{
case nano::thread_role::name::io:
case nano::thread_role::name::io_daemon:
return true;
default:
return false;
}
}
5 changes: 5 additions & 0 deletions nano/lib/thread_roles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,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 ();
}
1 change: 1 addition & 0 deletions nano/store/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

/*
Expand Down

0 comments on commit 251d3e7

Please sign in to comment.