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

Improve Eiger::Thread state machine, add Stopping state

parent 908a668d
......@@ -323,7 +323,7 @@ class Eiger : public Model
DEB_CLASS_NAMESPC(DebModCamera, "Eiger::Thread", "SlsDetector");
public:
enum State {
Init, Ready, Running, Stop, End,
Init, Ready, Running, Stopping, Quitting, End,
};
Thread(Eiger *eiger, int idx);
......@@ -336,7 +336,12 @@ class Eiger : public Model
void startAcq()
{ setState(Running); }
void stopAcq()
{ setState(Ready); }
{
setState(Stopping);
AutoMutex l = lock();
while (m_state != Ready)
wait();
}
protected:
virtual void threadFunction();
......@@ -549,20 +554,12 @@ class Eiger : public Model
bool allFramesAcquired()
{ return m_next_frame == m_nb_frames; }
bool checkForRecvState(Thread& t)
{
while ((t.m_state == Thread::Ready) ||
((t.m_state == Thread::Running) && allFramesAcquired()))
wait();
return (t.m_state == Thread::Running);
}
int getNbRecvs();
int getNbProcessingThreads();
void setNbProcessingThreads(int nb_proc_threads);
void processOneFrame(Thread& t, AutoMutex& l);
void processOneFrame(AutoMutex& l);
CorrBase *createBadRecvFrameCorr();
CorrBase *createChipBorderCorr(ImageType image_type);
......
......@@ -664,7 +664,7 @@ Eiger::Thread::~Thread()
DEB_DESTRUCTOR();
AutoMutex l = lock();
m_state = Stop;
m_state = Quitting;
broadcast();
while (m_state != End)
wait();
......@@ -674,14 +674,26 @@ void Eiger::Thread::threadFunction()
{
DEB_MEMBER_FUNCT();
State& s = m_state;
AutoMutex l = lock();
m_state = Ready;
s = Ready;
broadcast();
while (m_state != Stop)
m_eiger->processOneFrame(*this, l);
while (s != Quitting) {
while ((s == Ready) || (s == Stopping)
|| ((s == Running) && m_eiger->allFramesAcquired())) {
if (s == Stopping) {
s = Ready;
broadcast();
}
wait();
}
if (s == Running)
m_eiger->processOneFrame(l);
}
m_state = End;
s = End;
broadcast();
}
......@@ -1299,19 +1311,12 @@ void Eiger::stopAcq()
ThreadList::iterator it, end = m_thread_list.end();
for (it = m_thread_list.begin(); it != end; ++it)
(*it)->stopAcq();
AutoMutex l = lock();
while (!m_in_process.empty())
wait();
}
void Eiger::processOneFrame(Thread& t, AutoMutex& l)
void Eiger::processOneFrame(AutoMutex& l)
{
DEB_MEMBER_FUNCT();
if (!checkForRecvState(t))
return;
FrameType frame = m_next_frame++;
class Sync
......
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