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 Nov 2, 2024
1 parent 988c5db commit c2c0a42
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
11 changes: 7 additions & 4 deletions nano/lib/thread_roles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
5 changes: 5 additions & 0 deletions nano/lib/thread_roles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
}
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 c2c0a42

Please sign in to comment.