0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-29 10:12:39 +01:00

ircd::ctx: Add direct flags reference accessor to interface.

This commit is contained in:
Jason Volk 2020-05-18 19:04:31 -07:00
parent 215a0148b4
commit 00fe4baa2a
4 changed files with 25 additions and 3 deletions

View file

@ -44,7 +44,7 @@ namespace ircd::ctx
///
struct ircd::ctx::context
{
enum flags :uint;
enum flags :uint32_t;
using function = std::function<void ()>;
private:
@ -96,7 +96,7 @@ struct ircd::ctx::context
};
enum ircd::ctx::context::flags
:uint
:uint32_t
{
POST = 0x0001, ///< Defers spawn with an ios.post()
DISPATCH = 0x0002, ///< Defers spawn with an ios.dispatch()

View file

@ -47,6 +47,7 @@ namespace ircd::ctx
const uint64_t &id(const ctx &) noexcept; // Unique ID for context
string_view name(const ctx &) noexcept; // User's optional label for context
const uint32_t &flags(const ctx &) noexcept; // Direct flags access
const int32_t &notes(const ctx &) noexcept; // Peeks at internal semaphore count
const uint64_t &epoch(const ctx &) noexcept; // Context switching counter
const ulong &cycles(const ctx &) noexcept; // Accumulated tsc (not counting cur slice)
@ -61,6 +62,7 @@ namespace ircd::ctx
bool waiting(const ctx &) noexcept; // started() && !finished() && !running()
bool queued(const ctx &) noexcept; // !running() && notes() > 0
uint32_t &flags(ctx &) noexcept; // Direct flags access
int8_t ionice(ctx &, const int8_t &); // IO priority nice-value
int8_t nice(ctx &, const int8_t &); // Scheduling priority nice-value
void interruptible(ctx &, const bool &); // False for interrupt suppression.

View file

@ -537,6 +537,15 @@ ircd::ctx::ionice(ctx &ctx,
return ctx.ionice;
}
/// Returns writable reference to the flags of ctx
[[gnu::hot]]
uint32_t &
ircd::ctx::flags(ctx &ctx)
noexcept
{
return ctx.flags;
}
/// !running() && notes > 0
[[gnu::hot]]
bool
@ -654,6 +663,15 @@ noexcept
return ctx.notes;
}
/// Returns reference to the flags of ctx
[[gnu::hot]]
const uint32_t &
ircd::ctx::flags(const ctx &ctx)
noexcept
{
return ctx.flags;
}
/// Returns the developer's optional name literal for `ctx`
[[gnu::hot]]
ircd::string_view

View file

@ -28,12 +28,14 @@ namespace ircd::ctx::prof
struct ircd::ctx::ctx
:instance_list<ctx>
{
using flags_type = std::underlying_type<context::flags>::type;
static uint64_t id_ctr; // monotonic
static ios::descriptor ios_desc;
uint64_t id {++id_ctr}; // Unique runtime ID
string_view name; // User given name (optional)
context::flags flags; // User given flags
flags_type flags; // User given flags
int8_t nice {0}; // Scheduling priority nice-value
int8_t ionice {0}; // IO priority nice-value (defaults for fs::opts)
int32_t notes {0}; // norm: 0 = asleep; 1 = awake; inc by others; dec by self