0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-09-30 04:38:52 +02:00

ircd::json::stack: Add conditional exception rollback toggle.

This commit is contained in:
Jason Volk 2019-03-30 14:35:07 -07:00
parent e0864a1911
commit 9b2de5f4fc
2 changed files with 13 additions and 4 deletions

View file

@ -248,7 +248,7 @@ struct ircd::json::stack::const_chase
/// rollback() pitfall. /// rollback() pitfall.
/// ///
/// - Destruction under an exception is equivalent to a decommit() and will /// - Destruction under an exception is equivalent to a decommit() and will
/// perform a rollback(). /// perform a rollback() if exception_rollback is set.
/// ///
/// Flushes are avoided under the scope of a checkpoint, but they are still /// Flushes are avoided under the scope of a checkpoint, but they are still
/// forced if the json::stack buffer fills up. In this case all active /// forced if the json::stack buffer fills up. In this case all active
@ -261,6 +261,7 @@ struct ircd::json::stack::checkpoint
size_t point {0}; size_t point {0};
size_t vc {0}; size_t vc {0};
bool committed {true}; bool committed {true};
bool exception_rollback {true};
public: public:
bool committing() const; ///< When false, destructor will rollback() bool committing() const; ///< When false, destructor will rollback()
@ -268,7 +269,10 @@ struct ircd::json::stack::checkpoint
bool decommit(); ///< Sets committing() to false. bool decommit(); ///< Sets committing() to false.
bool rollback(); ///< Performs rollback of buffer. bool rollback(); ///< Performs rollback of buffer.
checkpoint(stack &s, const bool &committed = true); checkpoint(stack &s,
const bool &committed = true,
const bool &exception_rollback = true);
checkpoint(checkpoint &&) = delete; checkpoint(checkpoint &&) = delete;
checkpoint(const checkpoint &) = delete; checkpoint(const checkpoint &) = delete;
~checkpoint() noexcept; ~checkpoint() noexcept;

View file

@ -1459,7 +1459,8 @@ ircd::json::stack::member::_post_append()
// //
ircd::json::stack::checkpoint::checkpoint(stack &s, ircd::json::stack::checkpoint::checkpoint(stack &s,
const bool &committed) const bool &committed,
const bool &exception_rollback)
:s{&s} :s{&s}
,pc{s.cp} ,pc{s.cp}
,point ,point
@ -1486,6 +1487,10 @@ ircd::json::stack::checkpoint::checkpoint(stack &s,
{ {
committed committed
} }
,exception_rollback
{
exception_rollback
}
{ {
s.cp = this; s.cp = this;
} }
@ -1496,7 +1501,7 @@ noexcept
if(!s) if(!s)
return; return;
if(std::uncaught_exceptions()) if(std::uncaught_exceptions() && exception_rollback)
decommit(); decommit();
if(!committing()) if(!committing())