Further reworking the thread API.

This commit is contained in:
Robin Sommer 2012-07-17 17:09:49 -07:00
parent f7a6407ab1
commit f6b883bafc
7 changed files with 36 additions and 13 deletions

View file

@ -152,12 +152,13 @@ MsgThread::MsgThread() : BasicThread()
{
cnt_sent_in = cnt_sent_out = 0;
finished = false;
stopped = false;
thread_mgr->AddMsgThread(this);
}
void MsgThread::OnStop()
{
if ( finished )
if ( stopped )
return;
// Signal thread to terminate and wait until it has acknowledged.
@ -303,13 +304,8 @@ BasicInputMessage* MsgThread::RetrieveIn()
void MsgThread::Run()
{
while ( true )
while ( ! finished )
{
// When requested to terminate, we only do so when
// all input has been processed.
if ( Terminating() && ! queue_in.Ready() )
break;
BasicInputMessage* msg = RetrieveIn();
bool result = msg->Process();
@ -318,12 +314,13 @@ void MsgThread::Run()
{
string s = msg->Name() + " failed, terminating thread (MsgThread)";
Error(s.c_str());
Stop();
break;
}
delete msg;
}
Finished();
}
void MsgThread::GetStats(Stats* stats)

View file

@ -293,6 +293,7 @@ private:
uint64_t cnt_sent_out; // Counts message sent by child.
bool finished; // Set to true by Finished message.
bool stopped; // Set to true by OnStop().
};
/**