From a8bb37f522c6e3427410feac35bb7fdd02f79ddb Mon Sep 17 00:00:00 2001 From: "Lars T. Kyllingstad" Date: Thu, 22 Feb 2024 12:13:25 +0100 Subject: [PATCH] Drop explicit dependency on Boost --- CMakeLists.txt | 3 +-- src/cosim.cpp | 21 ++++++++------------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b06268a..6fd905d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -116,7 +116,6 @@ if(LIBCOSIMC_USING_CONAN) endif() find_package(libcosim REQUIRED) -find_package(Boost REQUIRED COMPONENTS fiber) # ============================================================================== # Targets @@ -140,7 +139,7 @@ add_library(cosimc "include/cosim.h" "src/cosim.cpp" ${generatedSourcesFull}) target_compile_features(cosimc PRIVATE "cxx_std_17") target_include_directories(cosimc PUBLIC "$") -target_link_libraries(cosimc PUBLIC libcosim::cosim Boost::fiber) +target_link_libraries(cosimc PUBLIC libcosim::cosim) if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") target_link_libraries(cosimc PUBLIC stdc++) endif() diff --git a/src/cosim.cpp b/src/cosim.cpp index bf7822f..5ddf165 100644 --- a/src/cosim.cpp +++ b/src/cosim.cpp @@ -21,13 +21,12 @@ #include #include -#include - #include #include #include #include #include +#include #include #include #include @@ -153,8 +152,7 @@ struct cosim_execution_s std::shared_ptr real_time_metrics; cosim::entity_index_maps entity_maps; std::thread t; - boost::fibers::future simulate_result; - std::exception_ptr simulate_exception_ptr; + std::future simulate_result; std::atomic state; int error_code; }; @@ -559,7 +557,7 @@ int cosim_execution_start(cosim_execution* execution) } else { try { execution->state = COSIM_EXECUTION_RUNNING; - auto task = boost::fibers::packaged_task([execution]() { + auto task = std::packaged_task([execution]() { return execution->cpp_execution->simulate_until(std::nullopt); }); execution->simulate_result = task.get_future(); @@ -577,15 +575,10 @@ void execution_async_health_check(cosim_execution* execution) { if (execution->simulate_result.valid()) { const auto status = execution->simulate_result.wait_for(std::chrono::duration()); - if (boost::fibers::future_status::ready == status) { - if (auto ep = execution->simulate_result.get_exception_ptr()) { - execution->simulate_exception_ptr = ep; - } + if (status == std::future_status::ready) { + execution->simulate_result.get(); } } - if (auto ep = execution->simulate_exception_ptr) { - std::rethrow_exception(ep); - } } int cosim_execution_stop(cosim_execution* execution) @@ -593,7 +586,9 @@ int cosim_execution_stop(cosim_execution* execution) try { execution->cpp_execution->stop_simulation(); if (execution->t.joinable()) { - execution->simulate_result.get(); + if (execution->simulate_result.valid()) { + execution->simulate_result.get(); + } execution->t.join(); } execution->state = COSIM_EXECUTION_STOPPED;