mirror of
https://github.com/matrix-construct/construct
synced 2024-11-16 15:00:51 +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()
|
ircd::ctx::is_main_thread()
|
||||||
noexcept
|
noexcept
|
||||||
{
|
{
|
||||||
return current ||
|
return ios::is_main_thread;
|
||||||
std::this_thread::get_id() == ios::main_thread_id;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ namespace ircd::ios
|
||||||
extern log::log log;
|
extern log::log log;
|
||||||
extern asio::executor user, main;
|
extern asio::executor user, main;
|
||||||
extern std::thread::id main_thread_id;
|
extern std::thread::id main_thread_id;
|
||||||
|
extern thread_local bool is_main_thread;
|
||||||
|
|
||||||
bool available() noexcept;
|
bool available() noexcept;
|
||||||
const uint64_t &epoch() noexcept;
|
const uint64_t &epoch() noexcept;
|
||||||
|
|
|
@ -1712,8 +1712,5 @@ bool
|
||||||
ircd::ctx::posix::is_main_thread()
|
ircd::ctx::posix::is_main_thread()
|
||||||
noexcept
|
noexcept
|
||||||
{
|
{
|
||||||
return false
|
return ircd::ios::is_main_thread;
|
||||||
|| ircd::ios::handler::current != nullptr
|
|
||||||
|| ircd::ctx::current != nullptr
|
|
||||||
|| ircd::ctx::is_main_thread();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,11 @@ ircd::ios::main_thread_id
|
||||||
std::this_thread::get_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.
|
/// The embedder/executable's (library user) asio::executor provided on init.
|
||||||
decltype(ircd::ios::user)
|
decltype(ircd::ios::user)
|
||||||
ircd::ios::user;
|
ircd::ios::user;
|
||||||
|
@ -56,6 +61,9 @@ ircd::ios::init(asio::executor &&user)
|
||||||
// to pass.
|
// to pass.
|
||||||
main_thread_id = std::this_thread::get_id();
|
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
|
// Set a reference to the user's ios_service
|
||||||
ios::user = std::move(user);
|
ios::user = std::move(user);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue