0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-07-06 02:28:38 +02:00

ircd:Ⓜ️:vm: Add preliminary phase state; minor movements.

This commit is contained in:
Jason Volk 2018-05-07 16:08:52 -07:00
parent b113322a28
commit 9792cb1435
2 changed files with 46 additions and 5 deletions

View file

@ -28,6 +28,7 @@ namespace ircd::m::vm
extern const opts default_opts; extern const opts default_opts;
extern const copts default_copts; extern const copts default_copts;
string_view reflect(const fault &);
const uint64_t &sequence(const eval &); const uint64_t &sequence(const eval &);
uint64_t retired_sequence(id::event::buf &); uint64_t retired_sequence(id::event::buf &);
uint64_t retired_sequence(); uint64_t retired_sequence();
@ -44,19 +45,23 @@ namespace ircd::m::vm
struct ircd::m::vm::eval struct ircd::m::vm::eval
:instance_list<eval> :instance_list<eval>
{ {
enum phase :uint8_t;
static uint64_t id_ctr; // monotonic static uint64_t id_ctr; // monotonic
const vm::opts *opts {&default_opts}; const vm::opts *opts {&default_opts};
const vm::copts *copts {nullptr}; const vm::copts *copts {nullptr};
ctx::ctx *ctx {ctx::current}; ctx::ctx *ctx {ctx::current};
uint64_t id {++id_ctr}; uint64_t id {++id_ctr};
uint64_t sequence {0}; string_view room_id;
db::txn *txn {nullptr};
const json::iov *issue {nullptr}; const json::iov *issue {nullptr};
const event *event_ {nullptr}; const event *event_ {nullptr};
string_view room_id; enum phase phase {(enum phase)0};
uint64_t sequence {0};
db::txn *txn {nullptr};
event::id::buf event_id; event::id::buf event_id;
public:
operator const event::id::buf &() const; operator const event::id::buf &() const;
fault operator()(const event &); fault operator()(const event &);
@ -73,7 +78,15 @@ struct ircd::m::vm::eval
eval(const eval &) = delete; eval(const eval &) = delete;
~eval() noexcept; ~eval() noexcept;
friend string_view reflect(const fault &); friend string_view reflect(const enum phase &);
};
/// Evaluation phases
enum ircd::m::vm::eval::phase
:uint8_t
{
ACCEPT = 0x00,
ENTER = 0x01,
}; };
/// Evaluation faults. These are reasons which evaluation has halted but may /// Evaluation faults. These are reasons which evaluation has halted but may

View file

@ -513,8 +513,10 @@ ircd::m::vm::eval::operator()(const room &room,
// eval is attempting to do. // eval is attempting to do.
issue = &event; issue = &event;
room_id = room.room_id; room_id = room.room_id;
phase = phase::ENTER;
const unwind deissue{[this] const unwind deissue{[this]
{ {
phase = phase::ACCEPT;
room_id = {}; room_id = {};
issue = nullptr; issue = nullptr;
}}; }};
@ -548,13 +550,21 @@ ircd::m::vm::eval::operator()(json::iov &event,
// allows other parallel evals to have deep access to exactly what this // allows other parallel evals to have deep access to exactly what this
// eval is attempting to do. // eval is attempting to do.
assert(!room_id || issue == &event); assert(!room_id || issue == &event);
issue = &event; if(!room_id)
{
issue = &event;
phase = phase::ENTER;
}
const unwind deissue{[this] const unwind deissue{[this]
{ {
// issue is untouched when room_id is set; that indicates it was set // issue is untouched when room_id is set; that indicates it was set
// and will be unset by another eval function (i.e above). // and will be unset by another eval function (i.e above).
if(!room_id) if(!room_id)
{
phase = phase::ACCEPT;
issue = nullptr; issue = nullptr;
}
}}; }};
return function(*this, event, contents); return function(*this, event, contents);
@ -574,8 +584,14 @@ ircd::m::vm::eval::operator()(const event &event)
// allows other parallel evals to have deep access to exactly what this // 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 is working on. The pointer must be nulled on the way out.
this->event_= &event; this->event_= &event;
if(!issue)
phase = phase::ENTER;
const unwind null_event{[this] const unwind null_event{[this]
{ {
if(!issue)
phase = phase::ACCEPT;
this->event_ = nullptr; this->event_ = nullptr;
}}; }};
@ -649,6 +665,18 @@ ircd::m::vm::reflect(const enum fault &code)
return "??????"; return "??????";
} }
ircd::string_view
ircd::m::vm::reflect(const enum eval::phase &phase)
{
switch(phase)
{
case eval::phase::ACCEPT: return "ACCEPT";
case eval::phase::ENTER: return "ENTER";
}
return "??????";
}
// //
// accepted // accepted
// //