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:
parent
e33e079230
commit
124f7ea12a
2 changed files with 21 additions and 2 deletions
|
@ -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.
|
||||||
|
|
||||||
|
|
20
ircd/ctx.cc
20
ircd/ctx.cc
|
@ -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)
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue