mirror of
https://github.com/matrix-construct/construct
synced 2024-12-27 07:54:05 +01:00
ircd: Move main_thread assertion related to ctx; adjust condition.
This commit is contained in:
parent
3c1b03adc4
commit
18f215d3f0
4 changed files with 22 additions and 27 deletions
|
@ -42,6 +42,8 @@ namespace ircd::ctx
|
||||||
struct terminated {}; // Special exception
|
struct terminated {}; // Special exception
|
||||||
|
|
||||||
IRCD_OVERLOAD(threadsafe)
|
IRCD_OVERLOAD(threadsafe)
|
||||||
|
bool is_main_thread() noexcept;
|
||||||
|
void assert_main_thread();
|
||||||
|
|
||||||
const uint64_t &id(const ctx &) noexcept; // Unique ID for context
|
const uint64_t &id(const ctx &) noexcept; // Unique ID for context
|
||||||
string_view name(const ctx &) noexcept; // User's optional label for context
|
string_view name(const ctx &) noexcept; // User's optional label for context
|
||||||
|
@ -128,4 +130,23 @@ namespace ircd
|
||||||
|
|
||||||
using ctx::critical_assertion;
|
using ctx::critical_assertion;
|
||||||
using ctx::critical_indicator;
|
using ctx::critical_indicator;
|
||||||
|
|
||||||
|
using ctx::is_main_thread;
|
||||||
|
using ctx::assert_main_thread;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void
|
||||||
|
__attribute__((always_inline))
|
||||||
|
ircd::ctx::assert_main_thread()
|
||||||
|
{
|
||||||
|
assert(is_main_thread());
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool
|
||||||
|
__attribute__((always_inline))
|
||||||
|
ircd::ctx::is_main_thread()
|
||||||
|
noexcept
|
||||||
|
{
|
||||||
|
return current ||
|
||||||
|
std::this_thread::get_id() == ios::main_thread_id;
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,8 +48,6 @@ namespace ircd::ios
|
||||||
extern asio::executor main;
|
extern asio::executor main;
|
||||||
|
|
||||||
bool available() noexcept;
|
bool available() noexcept;
|
||||||
bool is_main_thread() noexcept;
|
|
||||||
void assert_main_thread();
|
|
||||||
|
|
||||||
const string_view &name(const descriptor &);
|
const string_view &name(const descriptor &);
|
||||||
const string_view &name(const handler &);
|
const string_view &name(const handler &);
|
||||||
|
@ -63,8 +61,6 @@ namespace ircd::ios
|
||||||
|
|
||||||
namespace ircd
|
namespace ircd
|
||||||
{
|
{
|
||||||
using ios::assert_main_thread;
|
|
||||||
using ios::is_main_thread;
|
|
||||||
using ios::dispatch;
|
using ios::dispatch;
|
||||||
using ios::defer;
|
using ios::defer;
|
||||||
using ios::post;
|
using ios::post;
|
||||||
|
@ -274,19 +270,3 @@ noexcept
|
||||||
{
|
{
|
||||||
return handler::epoch;
|
return handler::epoch;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void
|
|
||||||
__attribute__((always_inline))
|
|
||||||
ircd::ios::assert_main_thread()
|
|
||||||
{
|
|
||||||
assert(is_main_thread());
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool
|
|
||||||
__attribute__((always_inline))
|
|
||||||
ircd::ios::is_main_thread()
|
|
||||||
noexcept
|
|
||||||
{
|
|
||||||
return std::this_thread::get_id() == main_thread_id ||
|
|
||||||
main_thread_id == std::thread::id();
|
|
||||||
}
|
|
||||||
|
|
|
@ -47,8 +47,7 @@ ircd::ios::init(asio::executor &&user)
|
||||||
// Sample the ID of this thread. Since this is the first transfer of
|
// Sample the ID of this thread. Since this is the first transfer of
|
||||||
// control to libircd after static initialization we have nothing to
|
// control to libircd after static initialization we have nothing to
|
||||||
// consider a main thread yet. We need something set for many assertions
|
// consider a main thread yet. We need something set for many assertions
|
||||||
// to pass until ircd::main() is entered which will reset this to where
|
// to pass.
|
||||||
// ios.run() is really running.
|
|
||||||
main_thread_id = std::this_thread::get_id();
|
main_thread_id = std::this_thread::get_id();
|
||||||
|
|
||||||
// Set a reference to the user's ios_service
|
// Set a reference to the user's ios_service
|
||||||
|
|
|
@ -281,11 +281,6 @@ void
|
||||||
ircd::main()
|
ircd::main()
|
||||||
noexcept try
|
noexcept try
|
||||||
{
|
{
|
||||||
// Resamples the thread this context was executed on which should be where
|
|
||||||
// the user ran ios.run(). The user may have invoked ios.run() on multiple
|
|
||||||
// threads, but we consider this one thread a main thread for now...
|
|
||||||
ircd::ios::main_thread_id = std::this_thread::get_id();
|
|
||||||
|
|
||||||
// When this function completes without exception, subsystems are done shutting down and IRCd
|
// When this function completes without exception, subsystems are done shutting down and IRCd
|
||||||
// transitions to HALT.
|
// transitions to HALT.
|
||||||
const unwind_defer halted{[]
|
const unwind_defer halted{[]
|
||||||
|
|
Loading…
Reference in a new issue