split set_scontext_synced class
this is a refactor to prepare fixing of http://gna.org/bugs/?23331
This commit is contained in:
parent
a8b8dd8023
commit
2a8abdf199
2 changed files with 35 additions and 17 deletions
|
@ -341,14 +341,35 @@ config synced_context::ask_server(const std::string &name, const mp_sync::user_c
|
|||
}
|
||||
}
|
||||
|
||||
set_scontext_synced_base::set_scontext_synced_base()
|
||||
: new_rng_(synced_context::get_rng_for_action())
|
||||
, old_rng_(random_new::generator)
|
||||
{
|
||||
LOG_REPLAY << "set_scontext_synced_base::set_scontext_synced_base\n";
|
||||
assert(synced_context::get_synced_state() == synced_context::UNSYNCED);
|
||||
synced_context::set_synced_state(synced_context::SYNCED);
|
||||
synced_context::reset_is_simultaneously();
|
||||
old_rng_ = random_new::generator;
|
||||
random_new::generator = new_rng_.get();
|
||||
}
|
||||
set_scontext_synced_base::~set_scontext_synced_base()
|
||||
{
|
||||
LOG_REPLAY << "set_scontext_synced_base:: destructor\n";
|
||||
assert(synced_context::get_synced_state() == synced_context::SYNCED);
|
||||
random_new::generator = old_rng_;
|
||||
synced_context::set_synced_state(synced_context::UNSYNCED);
|
||||
}
|
||||
|
||||
set_scontext_synced::set_scontext_synced()
|
||||
: new_rng_(synced_context::get_rng_for_action()), new_checkup_(recorder.get_last_real_command().child_or_add("checkup")), disabler_()
|
||||
: set_scontext_synced_base()
|
||||
, new_checkup_(recorder.get_last_real_command().child_or_add("checkup")), disabler_()
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
set_scontext_synced::set_scontext_synced(int number)
|
||||
: new_rng_(synced_context::get_rng_for_action()), new_checkup_(recorder.get_last_real_command().child_or_add("checkup" + boost::lexical_cast<std::string>(number))), disabler_()
|
||||
: set_scontext_synced_base()
|
||||
, new_checkup_(recorder.get_last_real_command().child_or_add("checkup" + boost::lexical_cast<std::string>(number))), disabler_()
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
@ -358,22 +379,13 @@ set_scontext_synced::set_scontext_synced(int number)
|
|||
*/
|
||||
void set_scontext_synced::init()
|
||||
{
|
||||
|
||||
LOG_REPLAY << "set_scontext_synced::set_scontext_synced\n";
|
||||
assert(synced_context::get_synced_state() == synced_context::UNSYNCED);
|
||||
|
||||
synced_context::set_synced_state(synced_context::SYNCED);
|
||||
synced_context::reset_is_simultaneously();
|
||||
|
||||
old_checkup_ = checkup_instance;
|
||||
checkup_instance = & new_checkup_;
|
||||
old_rng_ = random_new::generator;
|
||||
random_new::generator = new_rng_.get();
|
||||
}
|
||||
set_scontext_synced::~set_scontext_synced()
|
||||
{
|
||||
LOG_REPLAY << "set_scontext_synced:: destructor\n";
|
||||
assert(synced_context::get_synced_state() == synced_context::SYNCED);
|
||||
assert(checkup_instance == &new_checkup_);
|
||||
config co;
|
||||
if(!checkup_instance->local_checkup(config_of("random_calls", new_rng_->get_random_calls()), co))
|
||||
|
@ -383,9 +395,6 @@ set_scontext_synced::~set_scontext_synced()
|
|||
ERR_REPLAY << co.debug() << "\n";
|
||||
}
|
||||
|
||||
random_new::generator = old_rng_;
|
||||
synced_context::set_synced_state(synced_context::UNSYNCED);
|
||||
|
||||
checkup_instance = old_checkup_;
|
||||
}
|
||||
|
||||
|
|
|
@ -127,10 +127,21 @@ private:
|
|||
static events::generic_event remote_user_input_required_;
|
||||
};
|
||||
|
||||
|
||||
class set_scontext_synced_base
|
||||
{
|
||||
public:
|
||||
set_scontext_synced_base();
|
||||
~set_scontext_synced_base();
|
||||
protected:
|
||||
boost::shared_ptr<random_new::rng> new_rng_;
|
||||
random_new::rng* old_rng_;
|
||||
};
|
||||
|
||||
/*
|
||||
a RAII object to enter the synced context, cannot be called if we are already in a synced context.
|
||||
*/
|
||||
class set_scontext_synced
|
||||
class set_scontext_synced : set_scontext_synced_base
|
||||
{
|
||||
public:
|
||||
set_scontext_synced();
|
||||
|
@ -143,8 +154,6 @@ public:
|
|||
private:
|
||||
//only called by contructors.
|
||||
void init();
|
||||
random_new::rng* old_rng_;
|
||||
boost::shared_ptr<random_new::rng> new_rng_;
|
||||
checkup* old_checkup_;
|
||||
synced_checkup new_checkup_;
|
||||
events::command_disabler disabler_;
|
||||
|
|
Loading…
Add table
Reference in a new issue