Skip to content

Commit

Permalink
Drop explicit dependency on Boost
Browse files Browse the repository at this point in the history
  • Loading branch information
kyllingstad committed Feb 22, 2024
1 parent af43aeb commit a8bb37f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
3 changes: 1 addition & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ if(LIBCOSIMC_USING_CONAN)
endif()

find_package(libcosim REQUIRED)
find_package(Boost REQUIRED COMPONENTS fiber)

# ==============================================================================
# Targets
Expand All @@ -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 "$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>")
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()
Expand Down
21 changes: 8 additions & 13 deletions src/cosim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@
#include <cosim/ssp/ssp_loader.hpp>
#include <cosim/time.hpp>

#include <boost/fiber/future.hpp>

#include <algorithm>
#include <atomic>
#include <cassert>
#include <cerrno>
#include <cstring>
#include <future>
#include <iostream>
#include <mutex>
#include <optional>
Expand Down Expand Up @@ -153,8 +152,7 @@ struct cosim_execution_s
std::shared_ptr<const cosim::real_time_metrics> real_time_metrics;
cosim::entity_index_maps entity_maps;
std::thread t;
boost::fibers::future<bool> simulate_result;
std::exception_ptr simulate_exception_ptr;
std::future<bool> simulate_result;
std::atomic<cosim_execution_state> state;
int error_code;
};
Expand Down Expand Up @@ -559,7 +557,7 @@ int cosim_execution_start(cosim_execution* execution)
} else {
try {
execution->state = COSIM_EXECUTION_RUNNING;
auto task = boost::fibers::packaged_task<bool()>([execution]() {
auto task = std::packaged_task<bool()>([execution]() {
return execution->cpp_execution->simulate_until(std::nullopt);
});
execution->simulate_result = task.get_future();
Expand All @@ -577,23 +575,20 @@ 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 (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)
{
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;
Expand Down

0 comments on commit a8bb37f

Please sign in to comment.