From 73db2e5037748ede92bf4819af5ea4bfcbabda7b Mon Sep 17 00:00:00 2001 From: Pavel Baykov Date: Wed, 20 Apr 2022 07:45:55 -0300 Subject: [PATCH] add spin_yield to undo DB --- .../db/include/graphene/db/undo_database.hpp | 5 +++++ libraries/db/undo_database.cpp | 22 ++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/libraries/db/include/graphene/db/undo_database.hpp b/libraries/db/include/graphene/db/undo_database.hpp index 0eb00f55..c7bb2de7 100644 --- a/libraries/db/include/graphene/db/undo_database.hpp +++ b/libraries/db/include/graphene/db/undo_database.hpp @@ -25,6 +25,9 @@ #include #include #include +#include +#include +#include namespace graphene { namespace db { @@ -132,6 +135,8 @@ namespace graphene { namespace db { std::deque _stack; object_database& _db; size_t _max_size = 256; + + mutable fc::spin_yield_lock _spin_yield; }; } } // graphene::db diff --git a/libraries/db/undo_database.cpp b/libraries/db/undo_database.cpp index bffd761d..ee3fc11b 100644 --- a/libraries/db/undo_database.cpp +++ b/libraries/db/undo_database.cpp @@ -25,6 +25,8 @@ #include #include +#include + namespace graphene { namespace db { void undo_database::enable() { _disabled = false; } @@ -44,6 +46,8 @@ undo_database::session::~session() { undo_database::session undo_database::start_undo_session( bool force_enable ) { + synchronized(_spin_yield) + if( _disabled && !force_enable ) return session(*this); bool disable_on_exit = _disabled && force_enable; if( force_enable ) @@ -58,6 +62,8 @@ undo_database::session undo_database::start_undo_session( bool force_enable ) } void undo_database::on_create( const object& obj ) { + synchronized(_spin_yield) + if( _disabled ) return; if( _stack.empty() ) @@ -73,6 +79,8 @@ void undo_database::on_modify( const object& obj ) { if( _disabled ) return; + synchronized(_spin_yield) + if( _stack.empty() ) _stack.emplace_back(); auto& state = _stack.back(); @@ -86,6 +94,8 @@ void undo_database::on_remove( const object& obj ) { if( _disabled ) return; + synchronized(_spin_yield) + if( _stack.empty() ) _stack.emplace_back(); undo_state& state = _stack.back(); @@ -105,7 +115,9 @@ void undo_database::on_remove( const object& obj ) } void undo_database::undo() -{ try { +{ + synchronized(_spin_yield) + try { FC_ASSERT( !_disabled ); FC_ASSERT( _active_sessions > 0 ); disable(); @@ -136,6 +148,8 @@ void undo_database::undo() void undo_database::merge() { + synchronized(_spin_yield) + FC_ASSERT( _active_sessions > 0 ); if( _active_sessions == 1 && _stack.size() == 1 ) { @@ -256,12 +270,16 @@ void undo_database::merge() } void undo_database::commit() { + synchronized(_spin_yield) + FC_ASSERT( _active_sessions > 0 ); --_active_sessions; } void undo_database::pop_commit() { + synchronized(_spin_yield) + FC_ASSERT( _active_sessions == 0 ); FC_ASSERT( !_stack.empty() ); @@ -299,6 +317,8 @@ void undo_database::pop_commit() } const undo_state& undo_database::head()const { + synchronized(_spin_yield) + FC_ASSERT( !_stack.empty() ); return _stack.back(); }