0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-02 10:08:56 +02:00

ircd:Ⓜ️:vm: Add tools for evals on a specific stack/ctx.

This commit is contained in:
Jason Volk 2019-03-21 14:11:42 -07:00
parent 507c256eb4
commit a7f6549c27
2 changed files with 25 additions and 1 deletions

View file

@ -40,8 +40,8 @@ namespace ircd::m::vm::sequence
extern uint64_t uncommitted; // evaluating; not monotonic
extern ctx::dock dock;
uint64_t get(id::event::buf &); // [GET]
const uint64_t &get(const eval &);
uint64_t get(id::event::buf &); // [GET]
uint64_t max();
uint64_t min();
};
@ -95,7 +95,9 @@ struct ircd::m::vm::eval
eval(const eval &) = delete;
~eval() noexcept;
static bool for_each(const ctx::ctx *const &, const std::function<bool (eval &)> &);
static bool for_each(const std::function<bool (eval &)> &);
static size_t count(const ctx::ctx *const &);
static eval *find(const event::id &);
static eval &get(const event::id &);
static bool sequnique(const uint64_t &seq);

View file

@ -1259,6 +1259,16 @@ ircd::m::vm::eval::find(const event::id &event_id)
return ret;
}
size_t
ircd::m::vm::eval::count(const ctx::ctx *const &c)
{
return std::count_if(begin(eval::list), end(eval::list), [&c]
(const eval *const &eval)
{
return eval->ctx == c;
});
}
bool
ircd::m::vm::eval::for_each(const std::function<bool (eval &)> &closure)
{
@ -1269,6 +1279,18 @@ ircd::m::vm::eval::for_each(const std::function<bool (eval &)> &closure)
return true;
}
bool
ircd::m::vm::eval::for_each(const ctx::ctx *const &c,
const std::function<bool (eval &)> &closure)
{
for(eval *const &eval : eval::list)
if(eval->ctx == c)
if(!closure(*eval))
return false;
return true;
}
//
// eval::eval
//