streamline program stop call and implement temp file deletion when ref counter is 0

This commit is contained in:
Fabian Posch 2024-01-12 18:31:36 -05:00
parent 7003b3d211
commit f1cca2506b
3 changed files with 12 additions and 8 deletions

View file

@ -31,14 +31,14 @@
#include <atomic>
#include <condition_variable>
#include <mutex>
#include <cluster/artifact.hpp>
#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();

View file

@ -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;

View file

@ -23,6 +23,7 @@
**************************************************************************
*/
#include <cstdio>
#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();