Bug/issue317 #682

Closed
pavel.baykov wants to merge 4 commits from bug/issue317 into develop
2 changed files with 26 additions and 1 deletions
Showing only changes of commit 73db2e5037 - Show all commits

View file

@ -25,6 +25,9 @@
#include <graphene/db/object.hpp>
#include <deque>
#include <fc/exception/exception.hpp>
#include <fc/thread/spin_yield_lock.hpp>
#include <fc/fwd.hpp>
#include <fc/thread/unique_lock.hpp>
namespace graphene { namespace db {
@ -132,6 +135,8 @@ namespace graphene { namespace db {
std::deque<undo_state> _stack;
object_database& _db;
size_t _max_size = 256;
mutable fc::spin_yield_lock _spin_yield;
};
} } // graphene::db

View file

@ -25,6 +25,8 @@
#include <graphene/db/undo_database.hpp>
#include <fc/reflect/variant.hpp>
#include <fc/thread/spin_yield_lock.hpp>
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();
}