0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-25 16:22:35 +01:00

ircd::ctx: Add utils for getting this_ctxt name and id; truncate default name literal.

This commit is contained in:
Jason Volk 2017-10-15 21:12:58 -07:00
parent e33e079230
commit 124f7ea12a
2 changed files with 21 additions and 2 deletions

View file

@ -82,6 +82,9 @@ namespace ircd::ctx { inline namespace this_ctx
ctx &cur(); // Assumptional reference to *current ctx &cur(); // Assumptional reference to *current
const uint64_t &id(); // Unique ID for cur ctx
string_view name(); // Optional label for cur ctx
void wait(); // Returns when context is woken up. void wait(); // Returns when context is woken up.
void yield(); // Allow other contexts to run before returning. void yield(); // Allow other contexts to run before returning.

View file

@ -57,7 +57,7 @@ struct ircd::ctx::ctx
void operator()(boost::asio::yield_context, const std::function<void ()>) noexcept; void operator()(boost::asio::yield_context, const std::function<void ()>) noexcept;
ctx(const char *const &name = "<unnamed context>", ctx(const char *const &name = "<noname>",
const size_t &stack_max = DEFAULT_STACK_SIZE, const size_t &stack_max = DEFAULT_STACK_SIZE,
const context::flags &flags = (context::flags)0, const context::flags &flags = (context::flags)0,
boost::asio::io_service *const &ios = ircd::ios); boost::asio::io_service *const &ios = ircd::ios);
@ -327,6 +327,22 @@ ircd::ctx::this_ctx::interruption_requested()
return interruption(cur()); return interruption(cur());
} }
/// Returns unique ID of currently running context
const uint64_t &
ircd::ctx::this_ctx::id()
{
static const uint64_t zero{0};
return current? id(cur()) : zero;
}
/// Returns optional developer-given name for currently running context
ircd::string_view
ircd::ctx::this_ctx::name()
{
static const string_view nada{"*"};
return current? name(cur()) : nada;
}
/// Yield to context `ctx`. /// Yield to context `ctx`.
/// ///
/// ///
@ -569,7 +585,7 @@ ircd::ctx::context::context(function func,
const flags &flags) const flags &flags)
:context :context
{ {
"<unnamed context>", DEFAULT_STACK_SIZE, flags, std::move(func) "<noname>", DEFAULT_STACK_SIZE, flags, std::move(func)
} }
{ {
} }