streamline program stop call and implement temp file deletion when ref counter is 0
This commit is contained in:
parent
7003b3d211
commit
f1cca2506b
3 changed files with 12 additions and 8 deletions
|
|
@ -31,14 +31,14 @@
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
#include <mutex>
|
#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.
|
* 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.
|
* This can be any type, as long as it publicly derives form pl::Artifact.
|
||||||
*/
|
*/
|
||||||
using InputType = pl::SimConfigArtifact;
|
using InputType = DBSimConfigArtifact;
|
||||||
using OutputType = pl::SimOutputArtifact;
|
using OutputType = DBSimOutputArtifact;
|
||||||
|
|
||||||
class TaskInterface {
|
class TaskInterface {
|
||||||
|
|
||||||
|
|
@ -54,7 +54,6 @@ class TaskInterface {
|
||||||
void wait_for_download_halt();
|
void wait_for_download_halt();
|
||||||
|
|
||||||
void notify_cleanup_ready();
|
void notify_cleanup_ready();
|
||||||
void notify_download_program_halt();
|
|
||||||
void notify_workers_program_halt();
|
void notify_workers_program_halt();
|
||||||
void notify_download_halt();
|
void notify_download_halt();
|
||||||
|
|
||||||
|
|
@ -71,7 +70,7 @@ class TaskInterface {
|
||||||
|
|
||||||
bool running() { return this->running_.load(std::memory_order_relaxed); };
|
bool running() { return this->running_.load(std::memory_order_relaxed); };
|
||||||
bool is_stop_immediate() { return this->immediate_stop.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); };
|
void stop_immediately() { this->immediate_stop.store(true, std::memory_order_relaxed); };
|
||||||
|
|
||||||
bool fresh_queue_empty();
|
bool fresh_queue_empty();
|
||||||
|
|
|
||||||
|
|
@ -133,7 +133,6 @@ void sigint_handler(int signal) {
|
||||||
interface.stop_immediately();
|
interface.stop_immediately();
|
||||||
} else {
|
} else {
|
||||||
interface.stop();
|
interface.stop();
|
||||||
interface.notify_download_program_halt();
|
|
||||||
|
|
||||||
std::cout << "Finishing all running simulations, then closing the agent." << std::endl;
|
std::cout << "Finishing all running simulations, then closing the agent." << std::endl;
|
||||||
std::cout << "To stop immediately instead, press Ctrl+C again." << std::endl;
|
std::cout << "To stop immediately instead, press Ctrl+C again." << std::endl;
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@
|
||||||
**************************************************************************
|
**************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <cstdio>
|
||||||
#include "task_interface.hpp"
|
#include "task_interface.hpp"
|
||||||
|
|
||||||
TaskInterface::TaskInterface(size_t buffer_size) {
|
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
|
// if the reference counter hit 0, erase the design entry from the list
|
||||||
// of available designs
|
// of available designs
|
||||||
if (design_entry.first == 0) {
|
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.");
|
DEBUG_PRINT("Erasing design from store.");
|
||||||
this->designs.erase(id);
|
this->designs.erase(id);
|
||||||
}
|
}
|
||||||
|
|
@ -221,9 +226,10 @@ void TaskInterface::wait_for_download_halt() {
|
||||||
this->download_halt_condition.wait(lock, [&] { return !this->running(); });
|
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();
|
this->fresh_queue_full_condition.notify_all();
|
||||||
}
|
};
|
||||||
|
|
||||||
void TaskInterface::notify_workers_program_halt() {
|
void TaskInterface::notify_workers_program_halt() {
|
||||||
this->finished_queue_empty_condition.notify_all();
|
this->finished_queue_empty_condition.notify_all();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue