Skip to content
Snippets Groups Projects
Commit 1634b529 authored by Sonia Minolli's avatar Sonia Minolli
Browse files

Manage stop flag to avoid race condition between callback and stop counter (TANGODEVIC-1445)

parent 6ba0ae97
Branches
Tags
No related merge requests found
......@@ -96,6 +96,12 @@ namespace ni660Xsl
// timeout caller
TimeoutCallerDt * tmo_caller_;
// stop flag
bool stop_flag_;
// Mutex to protect stop flag
ACE_Thread_Mutex stop_lock_;
};
// ============================================================================
......
......@@ -96,6 +96,12 @@ namespace ni660Xsl
// timeout caller
TimeoutCallerEvt * tmo_caller_;
// stop flag
bool stop_flag_;
// Mutex to protect stop flag
ACE_Thread_Mutex stop_lock_;
};
// ============================================================================
......
......@@ -96,6 +96,12 @@ namespace ni660Xsl
// timeout caller
TimeoutCallerPeriod * tmo_caller_;
// stop flag
bool stop_flag_;
// Mutex to protect stop flag
ACE_Thread_Mutex stop_lock_;
};
// ============================================================================
......
......@@ -102,6 +102,12 @@ namespace ni660Xsl
// timeout caller
TimeoutCallerPos * tmo_caller_;
// stop flag
bool stop_flag_;
// Mutex to protect stop flag
ACE_Thread_Mutex stop_lock_;
};
// ============================================================================
......
......@@ -41,6 +41,18 @@ int32 CVICALLBACK scaled_buffer_callback_dt(ni::DAQTaskHandle _taskHandle,
BufferedDTMeasurement* buff_class_ = reinterpret_cast<BufferedDTMeasurement*>(_data);
if (buff_class_)
{
bool bStop;
{
ACE_GUARD_RETURN(ACE_SYNCH_MUTEX, ace_mon, buff_class_->stop_lock_, 0);
bStop = buff_class_->stop_flag_;
}
// If stop in progress, do not read data
if (!bStop)
{
// restart timeout
if (buff_class_->tmo_caller_)
{
......@@ -51,6 +63,8 @@ int32 CVICALLBACK scaled_buffer_callback_dt(ni::DAQTaskHandle _taskHandle,
// call internal function to read data from board
buff_class_->get_scaled_buffer();
}
}
return 0;
}
......@@ -63,6 +77,7 @@ BufferedDTMeasurement::BufferedDTMeasurement()
BufferedAcquisition()
{
tmo_caller_ = NULL;
stop_flag_ = false;
}
// ============================================================================
......@@ -88,6 +103,8 @@ void BufferedDTMeasurement::configure(void)
{
//std::cout<<<<"BufferedDTMeasurement::configure<-"<<std::endl;
stop_flag_ = false;
//-------------------------configure channel------------------------------------------
try
{
......@@ -388,6 +405,8 @@ void BufferedDTMeasurement::start(void)
// then, in case of callback mode enabled, start timeout pulsed object
if (use_callback_)
{
stop_flag_ = false;
tmo_caller_ = new TimeoutCallerDt();
if (tmo_caller_ == 0)
{
......@@ -411,6 +430,12 @@ void BufferedDTMeasurement::stop(void)
// then, in case of callback mode enabled, stop timeout pulsed object
if (use_callback_)
{
// set flag to avoid race condition with callback
{
ACE_GUARD(ACE_SYNCH_MUTEX, ace_mon, this->stop_lock_);
stop_flag_ = true;
}
if (tmo_caller_)
{
tmo_caller_->stop();
......@@ -432,6 +457,12 @@ void BufferedDTMeasurement::abort(void)
// then, in case of callback mode enabled, stop timeout pulsed object
if (use_callback_)
{
// set flag to avoid race condition with callback
{
ACE_GUARD(ACE_SYNCH_MUTEX, ace_mon, this->stop_lock_);
stop_flag_ = true;
}
if (tmo_caller_)
{
tmo_caller_->stop();
......
......@@ -41,6 +41,18 @@ int32 CVICALLBACK raw_buffer_callback_evt(ni::DAQTaskHandle _taskHandle,
BufferedEventCounting* buff_class_ = reinterpret_cast<BufferedEventCounting*>(_data);
if (buff_class_)
{
bool bStop;
{
ACE_GUARD_RETURN(ACE_SYNCH_MUTEX, ace_mon, buff_class_->stop_lock_, 0);
bStop = buff_class_->stop_flag_;
}
// If stop in progress, do not read data
if (!bStop)
{
// restart timeout
if (buff_class_->tmo_caller_)
{
......@@ -51,6 +63,8 @@ int32 CVICALLBACK raw_buffer_callback_evt(ni::DAQTaskHandle _taskHandle,
// call internal function to read data from board
buff_class_->get_raw_buffer();
}
}
return 0;
}
......@@ -63,6 +77,7 @@ BufferedEventCounting::BufferedEventCounting()
BufferedAcquisition()
{
tmo_caller_ = NULL;
stop_flag_ = false;
}
// ============================================================================
......@@ -88,6 +103,8 @@ void BufferedEventCounting::configure(void)
{
//std::cout<<<<"BufferedEventCounting::configure<-"<<std::endl;
stop_flag_ = false;
//-------------------------configure channel------------------------------------------
try
{
......@@ -385,6 +402,8 @@ void BufferedEventCounting::start(void)
// then, in case of callback mode enabled, start timeout pulsed object
if (use_callback_)
{
stop_flag_ = false;
tmo_caller_ = new TimeoutCallerEvt();
if (tmo_caller_ == 0)
{
......@@ -408,6 +427,12 @@ void BufferedEventCounting::stop(void)
// then, in case of callback mode enabled, stop timeout pulsed object
if (use_callback_)
{
// set flag to avoid race condition with callback
{
ACE_GUARD(ACE_SYNCH_MUTEX, ace_mon, this->stop_lock_);
stop_flag_ = true;
}
if (tmo_caller_)
{
tmo_caller_->stop();
......@@ -429,6 +454,12 @@ void BufferedEventCounting::abort(void)
// then, in case of callback mode enabled, stop timeout pulsed object
if (use_callback_)
{
// set flag to avoid race condition with callback
{
ACE_GUARD(ACE_SYNCH_MUTEX, ace_mon, this->stop_lock_);
stop_flag_ = true;
}
if (tmo_caller_)
{
tmo_caller_->stop();
......
......@@ -41,6 +41,18 @@ int32 CVICALLBACK scaled_buffer_callback_period(ni::DAQTaskHandle _taskHandle,
BufferedPeriodMeasurement* buff_class_ = reinterpret_cast<BufferedPeriodMeasurement*>(_data);
if (buff_class_)
{
bool bStop;
{
ACE_GUARD_RETURN(ACE_SYNCH_MUTEX, ace_mon, buff_class_->stop_lock_, 0);
bStop = buff_class_->stop_flag_;
}
// If stop in progress, do not read data
if (!bStop)
{
// restart timeout
if (buff_class_->tmo_caller_)
{
......@@ -51,6 +63,8 @@ int32 CVICALLBACK scaled_buffer_callback_period(ni::DAQTaskHandle _taskHandle,
// call internal function to read data from board
buff_class_->get_scaled_buffer();
}
}
return 0;
}
......@@ -63,6 +77,7 @@ BufferedPeriodMeasurement::BufferedPeriodMeasurement()
BufferedAcquisition()
{
tmo_caller_ = NULL;
stop_flag_ = false;
}
// ============================================================================
......@@ -88,6 +103,8 @@ void BufferedPeriodMeasurement::configure(void)
{
//std::cout<<<<"BufferedPeriodMeasurement::configure<-"<<std::endl;
stop_flag_ = false;
//-------------------------configure channel------------------------------------------
try
{
......@@ -388,6 +405,8 @@ void BufferedPeriodMeasurement::start(void)
// then, in case of callback mode enabled, start timeout pulsed object
if (use_callback_)
{
stop_flag_ = false;
tmo_caller_ = new TimeoutCallerPeriod();
if (tmo_caller_ == 0)
{
......@@ -411,6 +430,12 @@ void BufferedPeriodMeasurement::stop(void)
// then, in case of callback mode enabled, stop timeout pulsed object
if (use_callback_)
{
// set flag to avoid race condition with callback
{
ACE_GUARD(ACE_SYNCH_MUTEX, ace_mon, this->stop_lock_);
stop_flag_ = true;
}
if (tmo_caller_)
{
tmo_caller_->stop();
......@@ -432,6 +457,12 @@ void BufferedPeriodMeasurement::abort(void)
// then, in case of callback mode enabled, stop timeout pulsed object
if (use_callback_)
{
// set flag to avoid race condition with callback
{
ACE_GUARD(ACE_SYNCH_MUTEX, ace_mon, this->stop_lock_);
stop_flag_ = true;
}
if (tmo_caller_)
{
tmo_caller_->stop();
......
......@@ -39,6 +39,17 @@ int32 CVICALLBACK scaled_buffer_callback_pos(ni::DAQTaskHandle _taskHandle,
BufferedPositionMeasurement* buff_class_ = reinterpret_cast<BufferedPositionMeasurement*>(_data);
if (buff_class_)
{
bool bStop;
{
ACE_GUARD_RETURN(ACE_SYNCH_MUTEX, ace_mon, buff_class_->stop_lock_, 0);
bStop = buff_class_->stop_flag_;
}
// If stop in progress, do not read data
if (!bStop)
{
// restart timeout
if (buff_class_->tmo_caller_)
{
......@@ -49,6 +60,8 @@ int32 CVICALLBACK scaled_buffer_callback_pos(ni::DAQTaskHandle _taskHandle,
// call internal function to read data from board
buff_class_->get_scaled_buffer();
}
}
return 0;
}
......@@ -61,6 +74,7 @@ BufferedPositionMeasurement::BufferedPositionMeasurement()
BufferedAcquisition()
{
tmo_caller_ = NULL;
stop_flag_ = false;
}
// ============================================================================
......@@ -84,6 +98,8 @@ void BufferedPositionMeasurement::configure (void)
{
//std::cout<<<<"BufferedPositionMeasurement::configure<-"<<std::endl;
stop_flag_ = false;
//-------------------------configure channel------------------------------------------
try
{
......@@ -397,6 +413,8 @@ void BufferedPositionMeasurement::start(void)
// then, in case of callback mode enabled, start timeout pulsed object
if (use_callback_)
{
stop_flag_ = false;
tmo_caller_ = new TimeoutCallerPos();
if (tmo_caller_ == 0)
{
......@@ -420,6 +438,12 @@ void BufferedPositionMeasurement::stop(void)
// then, in case of callback mode enabled, stop timeout pulsed object
if (use_callback_)
{
// set flag to avoid race condition with callback
{
ACE_GUARD(ACE_SYNCH_MUTEX, ace_mon, this->stop_lock_);
stop_flag_ = true;
}
if (tmo_caller_)
{
tmo_caller_->stop();
......@@ -441,6 +465,12 @@ void BufferedPositionMeasurement::abort(void)
// then, in case of callback mode enabled, stop timeout pulsed object
if (use_callback_)
{
// set flag to avoid race condition with callback
{
ACE_GUARD(ACE_SYNCH_MUTEX, ace_mon, this->stop_lock_);
stop_flag_ = true;
}
if (tmo_caller_)
{
tmo_caller_->stop();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment