0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2025-01-14 16:46:50 +01:00

ircd::ctx: Add strand()/notify() with threadsafe_t.

This commit is contained in:
Jason Volk 2017-04-02 20:52:30 -07:00
parent a89d499557
commit b579d7dfc3
2 changed files with 24 additions and 2 deletions

View file

@ -35,13 +35,18 @@ namespace ctx {
struct ctx; struct ctx;
IRCD_OVERLOAD(threadsafe)
const uint64_t &id(const ctx &); // Unique ID for context const uint64_t &id(const ctx &); // Unique ID for context
string_view name(const ctx &); // User's optional label for context string_view name(const ctx &); // User's optional label for context
const int64_t &notes(const ctx &); // Peeks at internal semaphore count (you don't need this) const int64_t &notes(const ctx &); // Peeks at internal semaphore count (you don't need this)
bool finished(const ctx &); // Context function returned (or exception). bool finished(const ctx &); // Context function returned (or exception).
bool started(const ctx &); // Context was ever entered. bool started(const ctx &); // Context was ever entered.
void interrupt(ctx &); // Interrupt the context for termination. 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) void yield(ctx &); // Direct context switch (only library ppl need this)
// //

View file

@ -289,12 +289,29 @@ ircd::ctx::yield(ctx &ctx)
ctx.jump(); ctx.jump();
} }
void
ircd::ctx::notify(ctx &ctx,
threadsafe_t)
{
strand(ctx, [&ctx]
{
notify(ctx);
});
}
bool bool
ircd::ctx::notify(ctx &ctx) ircd::ctx::notify(ctx &ctx)
{ {
return ctx.note(); return ctx.note();
} }
void
ircd::ctx::strand(ctx &ctx,
std::function<void ()> func)
{
ctx.strand.post(std::move(func));
}
void void
ircd::ctx::interrupt(ctx &ctx) ircd::ctx::interrupt(ctx &ctx)
{ {
@ -785,7 +802,7 @@ ircd::ctx::ole::offload(const std::function<void ()> &func)
eptr = std::current_exception(); eptr = std::current_exception();
} }
context->strand.post(kick); strand(*context, kick);
}); });
push(std::move(closure)); do push(std::move(closure)); do