mirror of
https://github.com/matrix-construct/construct
synced 2024-12-27 07:54:05 +01:00
ircd::ctx: Add strand()/notify() with threadsafe_t.
This commit is contained in:
parent
a89d499557
commit
b579d7dfc3
2 changed files with 24 additions and 2 deletions
|
@ -35,13 +35,18 @@ namespace ctx {
|
|||
|
||||
struct ctx;
|
||||
|
||||
IRCD_OVERLOAD(threadsafe)
|
||||
|
||||
const uint64_t &id(const ctx &); // Unique ID for context
|
||||
string_view name(const ctx &); // User's optional label for context
|
||||
const int64_t ¬es(const ctx &); // Peeks at internal semaphore count (you don't need this)
|
||||
bool finished(const ctx &); // Context function returned (or exception).
|
||||
bool started(const ctx &); // Context was ever entered.
|
||||
|
||||
void interrupt(ctx &); // Interrupt the context for termination.
|
||||
bool notify(ctx &); // Queue context switch (only library ppl need this)
|
||||
void strand(ctx &, std::function<void ()>); // Post function to context strand
|
||||
void notify(ctx &, threadsafe_t); // Notify context with threadsafety.
|
||||
bool notify(ctx &); // Queue a context switch (only library ppl need this)
|
||||
void yield(ctx &); // Direct context switch (only library ppl need this)
|
||||
|
||||
//
|
||||
|
|
19
ircd/ctx.cc
19
ircd/ctx.cc
|
@ -289,12 +289,29 @@ ircd::ctx::yield(ctx &ctx)
|
|||
ctx.jump();
|
||||
}
|
||||
|
||||
void
|
||||
ircd::ctx::notify(ctx &ctx,
|
||||
threadsafe_t)
|
||||
{
|
||||
strand(ctx, [&ctx]
|
||||
{
|
||||
notify(ctx);
|
||||
});
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::ctx::notify(ctx &ctx)
|
||||
{
|
||||
return ctx.note();
|
||||
}
|
||||
|
||||
void
|
||||
ircd::ctx::strand(ctx &ctx,
|
||||
std::function<void ()> func)
|
||||
{
|
||||
ctx.strand.post(std::move(func));
|
||||
}
|
||||
|
||||
void
|
||||
ircd::ctx::interrupt(ctx &ctx)
|
||||
{
|
||||
|
@ -785,7 +802,7 @@ ircd::ctx::ole::offload(const std::function<void ()> &func)
|
|||
eptr = std::current_exception();
|
||||
}
|
||||
|
||||
context->strand.post(kick);
|
||||
strand(*context, kick);
|
||||
});
|
||||
|
||||
push(std::move(closure)); do
|
||||
|
|
Loading…
Reference in a new issue