Skip to content

Commit

Permalink
checkpoint serialization synchronization
Browse files Browse the repository at this point in the history
Move the exit to the serialization block
and otherwise wait on a condvar to sleep until
the program exits.

Reduced the amount of code by combining things that happen in both branches.
  • Loading branch information
Brian Zhao committed Oct 7, 2023
1 parent e269d52 commit 0656048
Showing 1 changed file with 13 additions and 22 deletions.
35 changes: 13 additions & 22 deletions src/checkpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,38 +81,29 @@ void serialize_to_file(WASMExecEnv *instance) {
//
std::cout<<"dasfasdfasf"<< re.str()<<"dasfasdfasf\n";
auto cluster = wasm_exec_env_get_cluster(instance);
if (bh_list_length(&cluster->exec_env_list) > 1) {
auto all_count = bh_list_length(&cluster->exec_env_list);
int cur_count = 0;
if (all_count > 1) {
auto elem = (WASMExecEnv *)bh_list_first_elem(&cluster->exec_env_list);
int cur_count = 0;
while (elem) {
if (elem == instance) {
break;
}
cur_count++;
elem = (WASMExecEnv *)bh_list_elem_next(elem);
}
auto all_count = bh_list_length(&cluster->exec_env_list);
auto a = new WAMRExecEnv();
dump(a, instance);
as_mtx.lock();
as.emplace_back(a);
as.back().get()->cur_count = cur_count;
if (as.size() == all_count) {
struct_pack::serialize_to(writer, as);
LOGV(INFO) << "serialize to file" << cur_count << " " << all_count << "\n";
}
as_mtx.unlock();
if (cur_count == 0)
std::this_thread::sleep_for(std::chrono::seconds(100));
} else {
auto a = new WAMRExecEnv();
dump(a, instance);
as.emplace_back(a);
as.back().get()->cur_count = 0;
} // gets the element index
auto a = new WAMRExecEnv();
dump(a, instance);
as_mtx.lock();
as.emplace_back(a);
as.back().get()->cur_count = cur_count;
if (as.size() == all_count) {
struct_pack::serialize_to(writer, as);
LOGV(INFO) << "serialize to file" << cur_count << " " << all_count << "\n";
exit(0);
}

exit(0);
as_mtx.unlock();
}

#ifndef MVVM_DEBUG
Expand Down

0 comments on commit 0656048

Please sign in to comment.