This commit is contained in:
Pavel Baykov 2022-04-20 07:38:29 -03:00
parent 746d4a345b
commit 307bd4e3ee
2 changed files with 37 additions and 6 deletions

View file

@ -9,8 +9,8 @@ set( GUI_CLIENT_EXECUTABLE_NAME Peerplays )
set( CUSTOM_URL_SCHEME "gcs" ) set( CUSTOM_URL_SCHEME "gcs" )
set( INSTALLER_APP_ID "68ad7005-8eee-49c9-95ce-9eed97e5b347" ) set( INSTALLER_APP_ID "68ad7005-8eee-49c9-95ce-9eed97e5b347" )
add_compile_options(-fsanitize=address -fsanitize-recover=address) #add_compile_options(-fsanitize=address -fsanitize-recover=address)
add_link_options(-fsanitize=address -fsanitize-recover=address -static-libasan) #add_link_options(-fsanitize=address -fsanitize-recover=address -static-libasan)
# http://stackoverflow.com/a/18369825 # http://stackoverflow.com/a/18369825
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")

View file

@ -58,6 +58,9 @@ undo_database::session undo_database::start_undo_session( bool force_enable )
_stack.emplace_back(); _stack.emplace_back();
++_active_sessions; ++_active_sessions;
ilog( "active_sessions = ${a}", ("a", _active_sessions));
return session(*this, disable_on_exit ); return session(*this, disable_on_exit );
} }
void undo_database::on_create( const object& obj ) void undo_database::on_create( const object& obj )
@ -74,6 +77,8 @@ void undo_database::on_create( const object& obj )
if( itr == state.old_index_next_ids.end() ) if( itr == state.old_index_next_ids.end() )
state.old_index_next_ids[index_id] = obj.id; state.old_index_next_ids[index_id] = obj.id;
state.new_ids.insert(obj.id); state.new_ids.insert(obj.id);
ilog("obj.id = ${id}", ("id", obj.id));
} }
void undo_database::on_modify( const object& obj ) void undo_database::on_modify( const object& obj )
{ {
@ -84,11 +89,18 @@ void undo_database::on_modify( const object& obj )
if( _stack.empty() ) if( _stack.empty() )
_stack.emplace_back(); _stack.emplace_back();
auto& state = _stack.back(); auto& state = _stack.back();
if( state.new_ids.find(obj.id) != state.new_ids.end() ) if( state.new_ids.find(obj.id) != state.new_ids.end() ){
ilog("can not modify new_ids obj.id = ${id}", ("id", obj.id));
return; return;
}
auto itr = state.old_values.find(obj.id); auto itr = state.old_values.find(obj.id);
if( itr != state.old_values.end() ) return; if( itr != state.old_values.end() ){
ilog("can not modify old_values obj.id = ${id}", ("id", obj.id));
return;
}
state.old_values[obj.id] = obj.clone(); state.old_values[obj.id] = obj.clone();
ilog("obj.id = ${id}", ("id", obj.id));
} }
void undo_database::on_remove( const object& obj ) void undo_database::on_remove( const object& obj )
{ {
@ -96,6 +108,8 @@ void undo_database::on_remove( const object& obj )
synchronized(_spin_yield) synchronized(_spin_yield)
ilog("obj.id = ${id}", ("id", obj.id));
if( _stack.empty() ) if( _stack.empty() )
_stack.emplace_back(); _stack.emplace_back();
undo_state& state = _stack.back(); undo_state& state = _stack.back();
@ -118,6 +132,8 @@ void undo_database::undo()
{ {
synchronized(_spin_yield) synchronized(_spin_yield)
try { try {
ilog("undo");
FC_ASSERT( !_disabled ); FC_ASSERT( !_disabled );
FC_ASSERT( _active_sessions > 0 ); FC_ASSERT( _active_sessions > 0 );
disable(); disable();
@ -150,6 +166,8 @@ void undo_database::merge()
{ {
synchronized(_spin_yield) synchronized(_spin_yield)
ilog("merge");
FC_ASSERT( _active_sessions > 0 ); FC_ASSERT( _active_sessions > 0 );
if( _active_sessions == 1 && _stack.size() == 1 ) if( _active_sessions == 1 && _stack.size() == 1 )
{ {
@ -272,6 +290,8 @@ void undo_database::commit()
{ {
synchronized(_spin_yield) synchronized(_spin_yield)
ilog("commit");
FC_ASSERT( _active_sessions > 0 ); FC_ASSERT( _active_sessions > 0 );
--_active_sessions; --_active_sessions;
} }
@ -280,6 +300,8 @@ void undo_database::pop_commit()
{ {
synchronized(_spin_yield) synchronized(_spin_yield)
ilog("pop_commit");
FC_ASSERT( _active_sessions == 0 ); FC_ASSERT( _active_sessions == 0 );
FC_ASSERT( !_stack.empty() ); FC_ASSERT( !_stack.empty() );
@ -289,23 +311,30 @@ void undo_database::pop_commit()
for( auto& item : state.old_values ) for( auto& item : state.old_values )
{ {
ilog("item modify = ${id}", ("id", item.second->id));
_db.modify( _db.get_object( item.second->id ), [&]( object& obj ){ obj.move_from( *item.second ); } ); _db.modify( _db.get_object( item.second->id ), [&]( object& obj ){ obj.move_from( *item.second ); } );
} }
for( auto ritr = state.new_ids.begin(); ritr != state.new_ids.end(); ++ritr ) for( auto ritr = state.new_ids.begin(); ritr != state.new_ids.end(); ++ritr )
{ {
ilog("item remove = ${id}", ("id", *ritr));
_db.remove( _db.get_object(*ritr) ); _db.remove( _db.get_object(*ritr) );
} }
for( auto& item : state.old_index_next_ids ) for( auto& item : state.old_index_next_ids )
{ {
ilog("item set_next_id = ${id}", ("id", item.second));
_db.get_mutable_index( item.first.space(), item.first.type() ).set_next_id( item.second ); _db.get_mutable_index( item.first.space(), item.first.type() ).set_next_id( item.second );
} }
for( auto& item : state.removed ) for( auto& item : state.removed ){
ilog("item insert = ${id}", ("id", item));
_db.insert( std::move(*item.second) ); _db.insert( std::move(*item.second) );
}
ilog("_stack.pop_back...");
_stack.pop_back(); _stack.pop_back();
ilog("_stack.pop_back done");
} }
catch ( const fc::exception& e ) catch ( const fc::exception& e )
{ {
@ -319,6 +348,8 @@ const undo_state& undo_database::head()const
{ {
synchronized(_spin_yield) synchronized(_spin_yield)
ilog("head()");
FC_ASSERT( !_stack.empty() ); FC_ASSERT( !_stack.empty() );
return _stack.back(); return _stack.back();
} }