Skip to content

Commit

Permalink
Match error behaviour of old boost::fibers-based code
Browse files Browse the repository at this point in the history
  • Loading branch information
kyllingstad committed Feb 22, 2024
1 parent 3cc12bc commit d107ce5
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/cosim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ struct cosim_execution_s
cosim::entity_index_maps entity_maps;
std::thread t;
std::future<bool> simulate_result;
std::exception_ptr simulate_exception_ptr;
std::atomic<cosim_execution_state> state;
int error_code;
};
Expand Down Expand Up @@ -576,16 +577,26 @@ void execution_async_health_check(cosim_execution* execution)
if (execution->simulate_result.valid()) {
const auto status = execution->simulate_result.wait_for(std::chrono::duration<int64_t>());
if (status == std::future_status::ready) {
execution->simulate_result.get();
try {
execution->simulate_result.get();
} catch (...) {
execution->simulate_exception_ptr = std::current_exception();
}
}
}
if (auto ep = execution->simulate_exception_ptr) {
std::rethrow_exception(ep);
}
}

int cosim_execution_stop(cosim_execution* execution)
{
try {
execution->cpp_execution->stop_simulation();
if (execution->t.joinable()) {
if (execution->simulate_exception_ptr) {
std::rethrow_exception(execution->simulate_exception_ptr);
}
if (execution->simulate_result.valid()) {
execution->simulate_result.get();
}
Expand Down

0 comments on commit d107ce5

Please sign in to comment.