0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-05-29 08:13:46 +02:00

ircd:Ⓜ️:vm: Remove the vm::phase; create fetch_hook.

This commit is contained in:
Jason Volk 2018-09-06 01:21:37 -07:00
parent 3b7f2f3fd3
commit d97a5ac571
6 changed files with 21 additions and 90 deletions

View file

@ -19,7 +19,6 @@ namespace ircd::m::vm
struct opts;
struct copts;
struct eval;
struct phase;
struct accepted;
enum fault :uint;
using fault_t = std::underlying_type<fault>::type;
@ -58,7 +57,6 @@ struct ircd::m::vm::eval
string_view room_id;
const json::iov *issue {nullptr};
const event *event_ {nullptr};
vm::phase *phase {nullptr};
uint64_t sequence {0};
db::txn *txn {nullptr};
event::id::buf event_id;
@ -248,17 +246,6 @@ struct ircd::m::vm::copts
bool infolog_postcommit {false};
};
struct ircd::m::vm::phase
:instance_list<phase>
{
string_view name;
std::function<void (eval &)> function;
void operator()(eval &);
phase(const string_view &name, decltype(function) = nullptr);
};
struct ircd::m::vm::accepted
:m::event
{

View file

@ -696,37 +696,6 @@ catch(...)
throw;
}
//
// vm::phase
//
/// Instance list linkage for all of the vm phases
template<>
decltype(ircd::util::instance_list<ircd::m::vm::phase>::list)
ircd::util::instance_list<ircd::m::vm::phase>::list
{};
ircd::m::vm::phase::phase(const string_view &name,
decltype(function) function)
:name{name}
,function{std::move(function)}
{
}
void
ircd::m::vm::phase::operator()(eval &eval)
{
auto theirs(eval.phase);
eval.phase = this;
const unwind _{[&eval, &theirs]
{
eval.phase = theirs;
}};
if(likely(function))
function(eval);
}
//
// accepted
//

View file

@ -8162,7 +8162,6 @@ console_cmd__vm__eval(opt &out, const string_view &line)
out << std::setw(9) << std::right << eval->id
<< " | " << std::setw(4) << std::right << id(*eval->ctx)
<< " | " << std::setw(4) << std::right << eval->sequence
<< " | " << std::setw(16) << std::left << (eval->phase? eval->phase->name : "")
<< " | " << std::setw(64) << std::left << eval->event_id
;

View file

@ -11,10 +11,9 @@
namespace ircd::m::vm
{
extern hook::site<> commit_hook;
extern hook::site<eval &> fetch_hook;
extern hook::site<> eval_hook;
extern hook::site<> notify_hook;
extern phase enter;
extern phase leave;
static void write_commit(eval &);
static fault _eval_edu(eval &, const event &);
@ -41,6 +40,12 @@ ircd::m::vm::commit_hook
{ "name", "vm.commit" }
};
decltype(ircd::m::vm::fetch_hook)
ircd::m::vm::fetch_hook
{
{ "name", "vm.fetch" }
};
decltype(ircd::m::vm::eval_hook)
ircd::m::vm::eval_hook
{
@ -120,10 +125,8 @@ ircd::m::vm::eval__commit_room(eval &eval,
// eval is attempting to do.
eval.issue = &event;
eval.room_id = room.room_id;
eval.phase = &vm::enter;
const unwind deissue{[&eval]
{
eval.phase = &vm::leave;
eval.room_id = {};
eval.issue = nullptr;
}};
@ -263,20 +266,14 @@ ircd::m::vm::eval__commit(eval &eval,
// eval is attempting to do.
assert(!eval.room_id || eval.issue == &event);
if(!eval.room_id)
{
eval.issue = &event;
eval.phase = &enter;
}
const unwind deissue{[&eval]
{
// issue is untouched when room_id is set; that indicates it was set
// and will be unset by another eval function (i.e above).
if(!eval.room_id)
{
eval.phase = &leave;
eval.issue = nullptr;
}
}};
assert(eval.issue);
@ -410,14 +407,8 @@ try
// allows other parallel evals to have deep access to exactly what this
// eval is working on. The pointer must be nulled on the way out.
eval.event_ = &event;
if(!eval.issue)
eval.phase = &enter;
const unwind null_event{[&eval]
{
if(!eval.issue)
eval.phase = &leave;
eval.event_ = nullptr;
}};
@ -655,7 +646,8 @@ ircd::m::vm::_eval_pdu(eval &eval,
// Obtain sequence number here
eval.sequence = ++vm::current_sequence;
eval_hook(event);
// Fetch dependencies
fetch_hook(event, eval);
int64_t top;
id::event::buf head;
@ -672,7 +664,8 @@ ircd::m::vm::_eval_pdu(eval &eval,
"vm_fetch", "phase"
};
fetch(eval);
// Evaluation by module hooks
eval_hook(event);
if(!opts.write)
return fault::ACCEPT;
@ -777,23 +770,3 @@ ircd::m::vm::retired_sequence(event::id::buf &event_id)
event_id = it->second;
return ret;
}
//
// phase enter
//
decltype(ircd::m::vm::enter)
ircd::m::vm::enter
{
"enter"
};
//
// phase leave
//
decltype(ircd::m::vm::leave)
ircd::m::vm::leave
{
"leave"
};

View file

@ -54,16 +54,19 @@ _fini()
// fetch_phase
//
decltype(m::vm::fetch::phase)
m::vm::fetch::phase
decltype(m::vm::fetch::hook)
m::vm::fetch::hook
{
"fetch", enter
enter,
{
{ "_site", "vm.fetch" }
}
};
void
m::vm::fetch::enter(eval &eval)
m::vm::fetch::enter(const event &event,
eval &eval)
{
assert(eval.event_);
assert(eval.opts);
const event::prev prev

View file

@ -27,8 +27,8 @@ namespace ircd::m::vm::fetch
extern ctx::dock dock;
extern std::set<request, request> fetching;
extern std::deque<request *> fetched;
extern hookfn<eval &> hook;
extern ctx::context context;
extern "C" vm::phase phase;
// worker stack
static bool requesting();
@ -42,7 +42,7 @@ namespace ircd::m::vm::fetch
extern "C" json::object acquire(const m::room::id &, const m::event::id &, const mutable_buffer &);
// phase stack
static void enter(m::vm::eval &);
static void enter(const event &, vm::eval &);
}
/// Fetch entity state