mirror of
https://github.com/zeek/zeek.git
synced 2025-10-09 18:18:19 +00:00

* topic/robin/input-threads-merge: (130 commits) And now it even compiles after my earlier changes. A set of input framework refactoring, cleanup, and polishing. another small memory leak in ascii reader: and another small memory leak when using streaming reads. fix another memory lead (when updating tables). Input framework merge in progress. filters have been called streams for eternity. And I always was too lazy to change it everywhere... reactivate network_time check in threading manager. previously this line made all input framework tests fail - it works now. Some of the other recent changes of the threading manager must have fixed that problem. fix up the executeraw test - now it works for the first time and does not always fail baselines for the autostart removal. remove last remnants of autostart, which has been removed for quite a while. make input framework source (hopefully) adhere to the usual indentation style. No functional changes. fix two memory leaks which occured when one used filters. update description to current interface. rename a couple of structures and make the names in manager fit the api more. fix memory leak in tables and vectors that are read into tables fix missing get call for heart beat in benchmark reader. fix heart_beat_interval -- initialization in constructor does not work anymore (probably due to change in init ordering?) fix memory leak for tables... nearly completely. fix a couple more leaks. But - still leaking quite a lot with tables. ...
154 lines
3.2 KiB
C++
154 lines
3.2 KiB
C++
|
|
#include "Manager.h"
|
|
#include "NetVar.h"
|
|
|
|
using namespace threading;
|
|
|
|
Manager::Manager()
|
|
{
|
|
DBG_LOG(DBG_THREADING, "Creating thread manager ...");
|
|
|
|
did_process = true;
|
|
next_beat = 0;
|
|
terminating = false;
|
|
idle = true;
|
|
}
|
|
|
|
Manager::~Manager()
|
|
{
|
|
if ( all_threads.size() )
|
|
Terminate();
|
|
}
|
|
|
|
void Manager::Terminate()
|
|
{
|
|
DBG_LOG(DBG_THREADING, "Terminating thread manager ...");
|
|
|
|
terminating = true;
|
|
|
|
// First process remaining thread output for the message threads.
|
|
do Process(); while ( did_process );
|
|
|
|
// Signal all to stop.
|
|
for ( all_thread_list::iterator i = all_threads.begin(); i != all_threads.end(); i++ )
|
|
(*i)->Stop();
|
|
|
|
// Then join them all.
|
|
for ( all_thread_list::iterator i = all_threads.begin(); i != all_threads.end(); i++ )
|
|
{
|
|
(*i)->Join();
|
|
delete *i;
|
|
}
|
|
|
|
all_threads.clear();
|
|
msg_threads.clear();
|
|
|
|
idle = true;
|
|
closed = true;
|
|
terminating = false;
|
|
}
|
|
|
|
void Manager::KillThreads()
|
|
{
|
|
DBG_LOG(DBG_THREADING, "Killing threads ...");
|
|
|
|
for ( all_thread_list::iterator i = all_threads.begin(); i != all_threads.end(); i++ )
|
|
(*i)->Kill();
|
|
}
|
|
|
|
void Manager::AddThread(BasicThread* thread)
|
|
{
|
|
DBG_LOG(DBG_THREADING, "Adding thread %s ...", thread->Name().c_str());
|
|
all_threads.push_back(thread);
|
|
idle = false;
|
|
}
|
|
|
|
void Manager::AddMsgThread(MsgThread* thread)
|
|
{
|
|
DBG_LOG(DBG_THREADING, "%s is a MsgThread ...", thread->Name().c_str());
|
|
msg_threads.push_back(thread);
|
|
}
|
|
|
|
void Manager::GetFds(int* read, int* write, int* except)
|
|
{
|
|
}
|
|
|
|
double Manager::NextTimestamp(double* network_time)
|
|
{
|
|
// fprintf(stderr, "N %.6f %.6f did_process=%d next_next=%.6f\n", ::network_time, timer_mgr->Time(), (int)did_process, next_beat);
|
|
|
|
if ( ::network_time && (did_process || ::network_time > next_beat || ! next_beat) )
|
|
// If we had something to process last time (or out heartbeat
|
|
// is due or not set yet), we want to check for more asap.
|
|
return timer_mgr->Time();
|
|
|
|
for ( msg_thread_list::iterator i = msg_threads.begin(); i != msg_threads.end(); i++ )
|
|
{
|
|
if ( (*i)->MightHaveOut() )
|
|
return timer_mgr->Time();
|
|
}
|
|
|
|
return -1.0;
|
|
}
|
|
|
|
void Manager::Process()
|
|
{
|
|
bool do_beat = false;
|
|
|
|
if ( network_time && (network_time > next_beat || ! next_beat) )
|
|
{
|
|
do_beat = true;
|
|
next_beat = ::network_time + BifConst::Threading::heartbeat_interval;
|
|
}
|
|
|
|
did_process = false;
|
|
|
|
for ( msg_thread_list::iterator i = msg_threads.begin(); i != msg_threads.end(); i++ )
|
|
{
|
|
MsgThread* t = *i;
|
|
|
|
if ( do_beat )
|
|
t->Heartbeat();
|
|
|
|
while ( t->HasOut() )
|
|
{
|
|
Message* msg = t->RetrieveOut();
|
|
|
|
if ( msg->Process() )
|
|
{
|
|
if ( network_time )
|
|
did_process = true;
|
|
}
|
|
|
|
else
|
|
{
|
|
string s = msg->Name() + " failed, terminating thread";
|
|
reporter->Error("%s", s.c_str());
|
|
t->Stop();
|
|
}
|
|
|
|
delete msg;
|
|
}
|
|
}
|
|
|
|
// fprintf(stderr, "P %.6f %.6f do_beat=%d did_process=%d next_next=%.6f\n", network_time, timer_mgr->Time(), do_beat, (int)did_process, next_beat);
|
|
}
|
|
|
|
const threading::Manager::msg_stats_list& threading::Manager::GetMsgThreadStats()
|
|
{
|
|
stats.clear();
|
|
|
|
for ( msg_thread_list::iterator i = msg_threads.begin(); i != msg_threads.end(); i++ )
|
|
{
|
|
MsgThread* t = *i;
|
|
|
|
MsgThread::Stats s;
|
|
t->GetStats(&s);
|
|
|
|
stats.push_back(std::make_pair(t->Name(),s));
|
|
}
|
|
|
|
return stats;
|
|
}
|
|
|
|
|