Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added mutex to MLT code to protect against a race condition in which a TD is sent to the DFO after triggers are disabled #249

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions plugins/ModuleLevelTrigger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,11 @@ ModuleLevelTrigger::do_start(const nlohmann::json& startobj)

m_inhibit_input->add_callback(std::bind(&ModuleLevelTrigger::dfo_busy_callback, this, std::placeholders::_1));

m_bitword_check = false; // this needs to be before the send thread is started, or it needs to be removed; why is it a class data member anyway?
m_send_trigger_decisions_thread = std::thread(&ModuleLevelTrigger::send_trigger_decisions, this);
pthread_setname_np(m_send_trigger_decisions_thread.native_handle(), "mlt-trig-dec");

ers::info(TriggerStartOfRun(ERS_HERE, m_run_number));

m_bitword_check = false;
}

void
Expand Down Expand Up @@ -218,7 +217,10 @@ ModuleLevelTrigger::do_pause(const nlohmann::json& /*pauseobj*/)
// Drop all TDs in vetors at run stage change
clear_td_vectors();

m_paused.store(true);
{
std::lock_guard<std::mutex> lock(m_pause_resume_mutex);
m_paused.store(true);
}
m_livetime_counter->set_state(LivetimeCounter::State::kPaused);
TLOG() << "******* Triggers PAUSED! in run " << m_run_number << " *********";
ers::info(TriggerPaused(ERS_HERE));
Expand All @@ -234,7 +236,10 @@ ModuleLevelTrigger::do_resume(const nlohmann::json& /*resumeobj*/)
ers::info(TriggerActive(ERS_HERE));
TLOG() << "******* Triggers RESUMED! in run " << m_run_number << " *********";
m_livetime_counter->set_state(LivetimeCounter::State::kLive);
m_paused.store(false);
{
std::lock_guard<std::mutex> lock(m_pause_resume_mutex);
m_paused.store(false);
}
TLOG_DEBUG(3) << "TS Start: "
<< std::chrono::duration_cast<std::chrono::microseconds>(
std::chrono::system_clock::now().time_since_epoch())
Expand Down Expand Up @@ -447,6 +452,7 @@ ModuleLevelTrigger::call_tc_decision(const ModuleLevelTrigger::PendingTD& pendin
}

if ((!m_use_bitwords) || (m_bitword_check)) {
std::lock_guard<std::mutex> lock(m_pause_resume_mutex);

dfmessages::TriggerDecision decision = create_decision(pending_td);

Expand Down
1 change: 1 addition & 0 deletions plugins/ModuleLevelTrigger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ class ModuleLevelTrigger : public dunedaq::appfwk::DAQModule
std::vector<PendingTD> m_pending_tds;
std::vector<PendingTD> m_sent_tds;
std::mutex m_td_vector_mutex;
std::mutex m_pause_resume_mutex;

void add_tc(const triggeralgs::TriggerCandidate& tc);
void add_td(const PendingTD& pending_td);
Expand Down