Commit 02863490 authored by Alejandro Homs Puron's avatar Alejandro Homs Puron Committed by operator for beamline
Browse files

Fix race condition in Camera::AcqThread::ExceptionCleanup:

* When stopAcq is called, getEffectiveState can dead-lock
parent 68199fae
......@@ -215,14 +215,16 @@ private:
"Camera::AcqThread::ExceptionCleanUp",
"SlsDetector");
public:
ExceptionCleanUp(AcqThread& thread);
ExceptionCleanUp(AcqThread& thread, AutoMutex& l);
virtual ~ExceptionCleanUp();
private:
AutoMutex& m_lock;
};
Status newFrameReady(FrameType frame);
void startAcq();
void stopAcq();
void cleanUp();
void cleanUp(AutoMutex& l);
Camera *m_cam;
Cond& m_cond;
......
......@@ -89,8 +89,9 @@ Camera::Beb::Beb(const std::string& host_name)
{
}
Camera::AcqThread::ExceptionCleanUp::ExceptionCleanUp(AcqThread& thread)
: Thread::ExceptionCleanUp(thread)
Camera::AcqThread::ExceptionCleanUp::ExceptionCleanUp(AcqThread& thread,
AutoMutex& l)
: Thread::ExceptionCleanUp(thread), m_lock(l)
{
DEB_CONSTRUCTOR();
}
......@@ -99,7 +100,7 @@ Camera::AcqThread::ExceptionCleanUp::~ExceptionCleanUp()
{
DEB_DESTRUCTOR();
AcqThread *thread = static_cast<AcqThread *>(&m_thread);
thread->cleanUp();
thread->cleanUp(m_lock);
}
Camera::AcqThread::AcqThread(Camera *cam)
......@@ -138,10 +139,12 @@ void Camera::AcqThread::threadFunction()
{
DEB_MEMBER_FUNCT();
ExceptionCleanUp cleanup(*this);
AutoMutex l = m_cam->lock();
// cleanup is executed with lock, once state goes to Stopped
// thread will be deleted in getEffectiveState without releasing lock
ExceptionCleanUp cleanup(*this, l);
GlobalCPUAffinityMgr& affinity_mgr = m_cam->m_global_cpu_affinity_mgr;
{
AutoMutexUnlock u(l);
......@@ -238,12 +241,10 @@ void Camera::AcqThread::queueFinishedFrame(FrameType frame)
m_cond.broadcast();
}
void Camera::AcqThread::cleanUp()
void Camera::AcqThread::cleanUp(AutoMutex& l)
{
DEB_MEMBER_FUNCT();
AutoMutex l = m_cam->lock();
if ((m_state == Stopped) || (m_state == Idle))
return;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment