Skip to content

Commit

Permalink
GH-2021 Simplify pause implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
heifner committed Jan 3, 2024
1 parent 6d52486 commit c4ed79a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 32 deletions.
15 changes: 6 additions & 9 deletions libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3247,18 +3247,15 @@ fc::sha256 controller::calculate_integrity_hash() { try {

void controller::write_snapshot( const snapshot_writer_ptr& snapshot ) {
EOS_ASSERT( !my->pending, block_validate_exception, "cannot take a consistent snapshot with a pending block" );
my->writing_snapshot = true;
try {
my->add_to_snapshot(snapshot);
my->writing_snapshot = false;
} catch(...) {
my->writing_snapshot = false;
throw;
}
my->writing_snapshot.store(true, std::memory_order_release);
fc::scoped_exit<std::function<void()>> e = [&] {
my->writing_snapshot.store(false, std::memory_order_release);
};
my->add_to_snapshot(snapshot);
}

bool controller::is_writing_snapshot() const {
return my->writing_snapshot;
return my->writing_snapshot.load(std::memory_order_acquire);
}

int64_t controller::set_proposed_producers( vector<producer_authority> producers ) {
Expand Down
26 changes: 3 additions & 23 deletions plugins/net_plugin/net_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,11 +522,6 @@ namespace eosio {
mutable fc::mutex chain_info_mtx; // protects chain_info_t
chain_info_t chain_info GUARDED_BY(chain_info_mtx);

alignas(hardware_destructive_interference_size)
std::mutex pause_mtx;
std::condition_variable pause_cv;
bool paused = false;

public:
void update_chain_info();
chain_info_t get_chain_info() const;
Expand All @@ -542,25 +537,11 @@ namespace eosio {
void start_expire_timer();
void start_monitors();

// we currently pause on snapshot generation
void wait_if_paused() {
controller& cc = chain_plug->chain();
if (!cc.is_writing_snapshot())
return;

std::unique_lock l(pause_mtx);
paused = true;
while (!pause_cv.wait_for(l, std::chrono::milliseconds(10), [&]{ return !paused; } )) {
if (!cc.is_writing_snapshot()) {
paused = false;
}
}
}

void unpause() {
std::lock_guard g(pause_mtx);
if (paused) {
paused = false;
pause_cv.notify_all();
while (cc.is_writing_snapshot()) {
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
}

Expand Down Expand Up @@ -3919,7 +3900,6 @@ namespace eosio {

// called from application thread
void net_plugin_impl::on_accepted_block_header(const block_state_ptr& bs) {
unpause();
update_chain_info();

dispatcher->strand.post([bs]() {
Expand Down

0 comments on commit c4ed79a

Please sign in to comment.