mirror of
https://github.com/matrix-construct/construct
synced 2024-11-25 08:12:37 +01:00
ircd::ctx: Simplify main thread conditions with tls bit.
This commit is contained in:
parent
7e188fa7f6
commit
d115d88e6c
4 changed files with 11 additions and 6 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue