mirror of
https://github.com/zeek/zeek.git
synced 2025-10-11 19:18:19 +00:00
Further reworking the thread API.
This commit is contained in:
parent
f7a6407ab1
commit
f6b883bafc
7 changed files with 36 additions and 13 deletions
|
@ -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)
|
||||
|
|
|
@ -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().
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue