0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-25 23:14:13 +01:00

ircd::json::stack: Simplify checkpoint interface controls.

This commit is contained in:
Jason Volk 2020-04-14 15:22:40 -07:00
parent d3ca5d6490
commit 79a4394626
7 changed files with 29 additions and 35 deletions

View file

@ -268,10 +268,9 @@ struct ircd::json::stack::checkpoint
bool exception_rollback {true};
public:
bool committing() const; ///< When false, destructor will rollback()
bool recommit(); ///< Sets committing() to true.
bool decommit(); ///< Sets committing() to false.
bool rollback(); ///< Performs rollback of buffer.
bool committing() const noexcept; ///< When false, destructor will rollback()
bool committing(const bool &) noexcept; ///< Sets committing() to value.
bool rollback(); ///< Performs rollback of buffer.
checkpoint(stack &s,
const bool &committed = true,
@ -351,3 +350,19 @@ ircd::json::stack::object::append(const json::tuple<T...> &t)
};
});
}
inline bool
ircd::json::stack::checkpoint::committing(const bool &committed)
noexcept
{
const bool ret(this->committed);
this->committed = committed;
return ret;
}
inline bool
ircd::json::stack::checkpoint::committing()
const noexcept
{
return committed;
}

View file

@ -1731,7 +1731,7 @@ ircd::json::stack::checkpoint::~checkpoint()
noexcept
{
if(std::uncaught_exceptions() && exception_rollback)
decommit();
committing(false);
if(!committing())
rollback();
@ -1772,31 +1772,10 @@ ircd::json::stack::checkpoint::rollback()
else if(top.m)
top.m->vc = vc;
recommit();
committing(true);
return true;
}
bool
ircd::json::stack::checkpoint::decommit()
{
committed = false;
return true;
}
bool
ircd::json::stack::checkpoint::recommit()
{
committed = true;
return true;
}
bool
ircd::json::stack::checkpoint::committing()
const
{
return committed;
}
//
// chase
//

View file

@ -40,7 +40,7 @@ ircd::m::room::auth::generate(const mutable_buffer &buf,
{
json::stack::array array{out};
if(!generate(array, room, event))
cp.decommit();
cp.committing(false);
}
return json::array{out.completed()};

View file

@ -478,7 +478,7 @@ try
ret = true;
data.out->invalidate_checkpoints();
}
else checkpoint.decommit();
else checkpoint.committing(false);
return true;
});
@ -518,7 +518,7 @@ try
}
if(!ret)
checkpoint.decommit();
checkpoint.committing(false);
if(!data.phased && stats_info) log::info
{
@ -618,7 +618,7 @@ try
json::merge(top, vector);
}
else checkpoint.decommit();
else checkpoint.committing(false);
log::debug
{

View file

@ -262,13 +262,13 @@ ircd::m::sync::_rooms_polylog_room(data &data,
ret = true;
data.out->invalidate_checkpoints();
}
else checkpoint.decommit();
else checkpoint.committing(false);
return true;
});
if(!ret)
checkpoint.decommit();
checkpoint.committing(false);
return ret;
}

View file

@ -152,7 +152,7 @@ get__make_join(client &client,
};
if(!m::room::auth::generate(auth_events, room, m::event{args}))
cp.decommit();
cp.committing(false);
}
json::stack::member

View file

@ -139,7 +139,7 @@ get__make_leave(client &client,
};
if(!m::room::auth::generate(auth_events, room, m::event{args}))
cp.decommit();
cp.committing(false);
}
json::stack::member