Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tlemane committed Dec 18, 2023
1 parent c9f32c6 commit 01871f9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
11 changes: 7 additions & 4 deletions include/kmtricks/signals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ inline std::string signal_to_string(int signal)
}
}

static std::mutex SigLock;

class SignalHandler
{
public:
Expand Down Expand Up @@ -95,10 +97,11 @@ class SignalHandler

static void state_callback(int signal)
{
state::get().write();
spdlog::info("Killed after {}. The run can be resumed by running the same command again.",
signal_to_string(signal));
exit(signal);
std::unique_lock<std::mutex> _(SigLock);

state::get().write(
fmt::format(
"Killed after {}. The run can be resumed by running the same command again.", signal_to_string(signal)));
}

static void default_callback(int signal)
Expand Down
8 changes: 7 additions & 1 deletion include/kmtricks/state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace km {
inf.read(reinterpret_cast<char*>(m_merge.data()), sizeof(std::uint8_t) * p);
}

void write()
void write(const std::string& msg = "")
{
std::unique_lock<spinlock> _1(m_lock_1);
std::unique_lock<spinlock> _2(m_lock_2);
Expand All @@ -59,6 +59,12 @@ namespace km {
inf.write(reinterpret_cast<char*>(m_superk.data()), sizeof(std::uint8_t) * m_nb);
inf.write(reinterpret_cast<char*>(m_count.data()), sizeof(std::uint8_t) * (m_nb*m_part));
inf.write(reinterpret_cast<char*>(m_merge.data()), sizeof(std::uint8_t) * m_part);

if (!msg.empty())
{
spdlog::info(msg);
std::quick_exit(1);
}
}

public:
Expand Down
2 changes: 1 addition & 1 deletion include/kmtricks/task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,13 +403,13 @@ class HashCountTask : public ITask
void preprocess() {}
void postprocess()
{
state::get().count_done(m_sample_id, m_part_id);
if (this->m_clear)
{
m_superk_storage->closeFile(m_part_id);
Eraser::get().erase(m_superk_storage->getFileName(m_part_id));
}
this->m_finish = true;
state::get().count_done(m_sample_id, m_part_id);
this->exec_callback();
}

Expand Down

0 comments on commit 01871f9

Please sign in to comment.