0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-25 21:38:18 +02:00

ircd::ctx: Simplify main thread conditions with tls bit.

This commit is contained in:
Jason Volk 2021-03-10 22:49:18 -08:00
parent 7e188fa7f6
commit d115d88e6c
4 changed files with 11 additions and 6 deletions

View file

@ -204,6 +204,5 @@ __attribute__((always_inline))
ircd::ctx::is_main_thread()
noexcept
{
return current ||
std::this_thread::get_id() == ios::main_thread_id;
return ios::is_main_thread;
}

View file

@ -29,6 +29,7 @@ namespace ircd::ios
extern log::log log;
extern asio::executor user, main;
extern std::thread::id main_thread_id;
extern thread_local bool is_main_thread;
bool available() noexcept;
const uint64_t &epoch() noexcept;

View file

@ -1712,8 +1712,5 @@ bool
ircd::ctx::posix::is_main_thread()
noexcept
{
return false
|| ircd::ios::handler::current != nullptr
|| ircd::ctx::current != nullptr
|| ircd::ctx::is_main_thread();
return ircd::ios::is_main_thread;
}

View file

@ -22,6 +22,11 @@ ircd::ios::main_thread_id
std::this_thread::get_id()
};
/// True only for the main thread.
decltype(ircd::ios::is_main_thread)
thread_local
ircd::ios::is_main_thread;
/// The embedder/executable's (library user) asio::executor provided on init.
decltype(ircd::ios::user)
ircd::ios::user;
@ -56,6 +61,9 @@ ircd::ios::init(asio::executor &&user)
// to pass.
main_thread_id = std::this_thread::get_id();
// Set the thread-local bit to true; all other threads will see false.
is_main_thread = true;
// Set a reference to the user's ios_service
ios::user = std::move(user);