From a7f6549c2763ea61ffbaf8df7fab80e1060a11b1 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Thu, 21 Mar 2019 14:11:42 -0700 Subject: [PATCH] ircd::m::vm: Add tools for evals on a specific stack/ctx. --- include/ircd/m/vm.h | 4 +++- ircd/m.cc | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/include/ircd/m/vm.h b/include/ircd/m/vm.h index 2cfac0128..e7e283726 100644 --- a/include/ircd/m/vm.h +++ b/include/ircd/m/vm.h @@ -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 &); static bool for_each(const std::function &); + 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); diff --git a/ircd/m.cc b/ircd/m.cc index 3253e3a5b..670b4101a 100644 --- a/ircd/m.cc +++ b/ircd/m.cc @@ -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 &closure) { @@ -1269,6 +1279,18 @@ ircd::m::vm::eval::for_each(const std::function &closure) return true; } +bool +ircd::m::vm::eval::for_each(const ctx::ctx *const &c, + const std::function &closure) +{ + for(eval *const &eval : eval::list) + if(eval->ctx == c) + if(!closure(*eval)) + return false; + + return true; +} + // // eval::eval //