From f1cca2506b3e69bfd66fb3a132e6f78f9ed916e6 Mon Sep 17 00:00:00 2001 From: Fabian Posch Date: Fri, 12 Jan 2024 18:31:36 -0500 Subject: [PATCH] streamline program stop call and implement temp file deletion when ref counter is 0 --- include/actsim_agent/task_interface.hpp | 9 ++++----- src/actsim_agent/actsim_agent.cpp | 1 - src/actsim_agent/task_interface.cpp | 10 ++++++++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/include/actsim_agent/task_interface.hpp b/include/actsim_agent/task_interface.hpp index 4ddb68a..0e15c3a 100644 --- a/include/actsim_agent/task_interface.hpp +++ b/include/actsim_agent/task_interface.hpp @@ -31,14 +31,14 @@ #include #include #include -#include +#include "agent_artifact.hpp" /** * If you want to use this interface for different types, you only need to change it here. * This can be any type, as long as it publicly derives form pl::Artifact. */ -using InputType = pl::SimConfigArtifact; -using OutputType = pl::SimOutputArtifact; +using InputType = DBSimConfigArtifact; +using OutputType = DBSimOutputArtifact; class TaskInterface { @@ -54,7 +54,6 @@ class TaskInterface { void wait_for_download_halt(); void notify_cleanup_ready(); - void notify_download_program_halt(); void notify_workers_program_halt(); void notify_download_halt(); @@ -71,7 +70,7 @@ class TaskInterface { bool running() { return this->running_.load(std::memory_order_relaxed); }; bool is_stop_immediate() { return this->immediate_stop.load(std::memory_order_relaxed); }; - void stop() { this->running_.store(false, std::memory_order_relaxed); }; + void stop(); void stop_immediately() { this->immediate_stop.store(true, std::memory_order_relaxed); }; bool fresh_queue_empty(); diff --git a/src/actsim_agent/actsim_agent.cpp b/src/actsim_agent/actsim_agent.cpp index 2ff0c5c..f2869bb 100644 --- a/src/actsim_agent/actsim_agent.cpp +++ b/src/actsim_agent/actsim_agent.cpp @@ -133,7 +133,6 @@ void sigint_handler(int signal) { interface.stop_immediately(); } else { interface.stop(); - interface.notify_download_program_halt(); std::cout << "Finishing all running simulations, then closing the agent." << std::endl; std::cout << "To stop immediately instead, press Ctrl+C again." << std::endl; diff --git a/src/actsim_agent/task_interface.cpp b/src/actsim_agent/task_interface.cpp index 9a13a5a..f9dc960 100644 --- a/src/actsim_agent/task_interface.cpp +++ b/src/actsim_agent/task_interface.cpp @@ -23,6 +23,7 @@ ************************************************************************** */ +#include #include "task_interface.hpp" TaskInterface::TaskInterface(size_t buffer_size) { @@ -165,6 +166,10 @@ void TaskInterface::decrement_design(const db::uuid_t& id) { // if the reference counter hit 0, erase the design entry from the list // of available designs if (design_entry.first == 0) { + DEBUG_PRINT("Reference counter has hit 0. Deleting temp file from disk..."); + + std::remove(design_entry.second.c_str()); + DEBUG_PRINT("Erasing design from store."); this->designs.erase(id); } @@ -221,9 +226,10 @@ void TaskInterface::wait_for_download_halt() { this->download_halt_condition.wait(lock, [&] { return !this->running(); }); } -void TaskInterface::notify_download_program_halt() { +void TaskInterface::stop() { + this->running_.store(false, std::memory_order_relaxed); this->fresh_queue_full_condition.notify_all(); -} +}; void TaskInterface::notify_workers_program_halt() { this->finished_queue_empty_condition.notify_all();