mirror of
https://github.com/zeek/zeek.git
synced 2025-10-12 03:28:19 +00:00
Checkpoint - all src/ except src/input
This commit is contained in:
commit
61ce9b5412
91 changed files with 8917 additions and 16 deletions
|
@ -1,5 +1,6 @@
|
|||
|
||||
#include "Manager.h"
|
||||
#include "NetVar.h"
|
||||
|
||||
using namespace threading;
|
||||
|
||||
|
@ -11,6 +12,9 @@ Manager::Manager()
|
|||
next_beat = 0;
|
||||
terminating = false;
|
||||
idle = true;
|
||||
|
||||
heart_beat_interval = double(BifConst::Threading::heart_beat_interval);
|
||||
DBG_LOG(DBG_THREADING, "Heart beat interval set to %f", heart_beat_interval);
|
||||
}
|
||||
|
||||
Manager::~Manager()
|
||||
|
@ -57,6 +61,12 @@ void Manager::KillThreads()
|
|||
|
||||
void Manager::AddThread(BasicThread* thread)
|
||||
{
|
||||
if ( heart_beat_interval == 0 ) {
|
||||
// Sometimes initialization does not seem to work from constructor.
|
||||
heart_beat_interval = double(BifConst::Threading::heart_beat_interval);
|
||||
DBG_LOG(DBG_THREADING, "Heart beat interval set to %f", heart_beat_interval);
|
||||
}
|
||||
|
||||
DBG_LOG(DBG_THREADING, "Adding thread %s ...", thread->Name().c_str());
|
||||
all_threads.push_back(thread);
|
||||
idle = false;
|
||||
|
@ -81,6 +91,12 @@ double Manager::NextTimestamp(double* network_time)
|
|||
// 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;
|
||||
}
|
||||
|
||||
|
@ -91,7 +107,7 @@ void Manager::Process()
|
|||
if ( network_time && (network_time > next_beat || ! next_beat) )
|
||||
{
|
||||
do_beat = true;
|
||||
next_beat = ::network_time + HEART_BEAT_INTERVAL;
|
||||
next_beat = ::network_time + heart_beat_interval;
|
||||
}
|
||||
|
||||
did_process = false;
|
||||
|
|
|
@ -44,7 +44,7 @@ public:
|
|||
void Terminate();
|
||||
|
||||
/**
|
||||
* Returns True if we are currently in Terminate() waiting for
|
||||
* Returns True if we are currently in Terminate() waiting for
|
||||
* threads to exit.
|
||||
*/
|
||||
bool Terminating() const { return terminating; }
|
||||
|
@ -99,7 +99,7 @@ protected:
|
|||
* Registers a new message thread with the manager. This is
|
||||
* automatically called by the thread's constructor. This must be
|
||||
* called \a in \a addition to AddThread(BasicThread* thread). The
|
||||
* MsgThread constructor makes sure to do so.
|
||||
* MsgThread constructor makes sure to do so.
|
||||
*
|
||||
* @param thread The thread.
|
||||
*/
|
||||
|
@ -126,7 +126,7 @@ protected:
|
|||
virtual const char* Tag() { return "threading::Manager"; }
|
||||
|
||||
private:
|
||||
static const int HEART_BEAT_INTERVAL = 1;
|
||||
int heart_beat_interval;
|
||||
|
||||
typedef std::list<BasicThread*> all_thread_list;
|
||||
all_thread_list all_threads;
|
||||
|
|
|
@ -301,7 +301,7 @@ void MsgThread::Run()
|
|||
|
||||
if ( ! result )
|
||||
{
|
||||
string s = msg->Name() + " failed, terminating thread";
|
||||
string s = msg->Name() + " failed, terminating thread (MsgThread)";
|
||||
Error(s.c_str());
|
||||
Stop();
|
||||
break;
|
||||
|
|
|
@ -273,6 +273,13 @@ private:
|
|||
*/
|
||||
bool HasOut() { return queue_out.Ready(); }
|
||||
|
||||
/**
|
||||
* Returns true if there might be at least one message pending for
|
||||
* the main thread. This function may occasionally return a value not
|
||||
* indicating the actual state, but won't do so very often.
|
||||
*/
|
||||
bool MightHaveOut() { return queue_out.MaybeReady(); }
|
||||
|
||||
Queue<BasicInputMessage *> queue_in;
|
||||
Queue<BasicOutputMessage *> queue_out;
|
||||
|
||||
|
|
|
@ -53,6 +53,13 @@ public:
|
|||
*/
|
||||
bool Ready();
|
||||
|
||||
/**
|
||||
* Returns true if the next Get() operation might succeed.
|
||||
* This function may occasionally return a value not
|
||||
* indicating the actual state, but won't do so very often.
|
||||
*/
|
||||
bool MaybeReady() { return ( ( read_ptr - write_ptr) != 0 ); }
|
||||
|
||||
/**
|
||||
* Returns the number of queued items not yet retrieved.
|
||||
*/
|
||||
|
|
|
@ -12,7 +12,12 @@ bool Field::Read(SerializationFormat* fmt)
|
|||
int t;
|
||||
int st;
|
||||
|
||||
bool success = (fmt->Read(&name, "name") && fmt->Read(&t, "type") && fmt->Read(&st, "subtype") );
|
||||
bool success = (fmt->Read(&name, "name")
|
||||
&& fmt->Read(&secondary_name, "secondary_name")
|
||||
&& fmt->Read(&t, "type")
|
||||
&& fmt->Read(&st, "subtype")
|
||||
&& fmt->Read(&optional, "optional"));
|
||||
|
||||
type = (TypeTag) t;
|
||||
subtype = (TypeTag) st;
|
||||
|
||||
|
@ -21,7 +26,11 @@ bool Field::Read(SerializationFormat* fmt)
|
|||
|
||||
bool Field::Write(SerializationFormat* fmt) const
|
||||
{
|
||||
return (fmt->Write(name, "name") && fmt->Write((int)type, "type") && fmt->Write((int)subtype, "subtype"));
|
||||
return (fmt->Write(name, "name")
|
||||
&& fmt->Write(secondary_name, "secondary_name")
|
||||
&& fmt->Write((int)type, "type")
|
||||
&& fmt->Write((int)subtype, "subtype"),
|
||||
fmt->Write(optional, "optional"));
|
||||
}
|
||||
|
||||
string Field::TypeName() const
|
||||
|
@ -186,7 +195,7 @@ bool Value::Read(SerializationFormat* fmt)
|
|||
char length;
|
||||
char family;
|
||||
|
||||
if ( ! (fmt->Read(&length, "subnet-len") && fmt->Read(&family, "subnet-family")) )
|
||||
if ( ! (fmt->Read(&length, "subnet-len") && fmt->Read(&family, "subnet-family")) )
|
||||
return false;
|
||||
|
||||
switch ( family ) {
|
||||
|
|
|
@ -20,19 +20,23 @@ namespace threading {
|
|||
*/
|
||||
struct Field {
|
||||
string name; //! Name of the field.
|
||||
//! Needed by input framework. Port fields have two names (one for the
|
||||
//! port, one for the type), and this specifies the secondary name.
|
||||
string secondary_name;
|
||||
TypeTag type; //! Type of the field.
|
||||
TypeTag subtype; //! Inner type for sets.
|
||||
bool optional; //! True if field is optional.
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
Field() { subtype = TYPE_VOID; }
|
||||
Field() { subtype = TYPE_VOID; optional = false; }
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
*/
|
||||
Field(const Field& other)
|
||||
: name(other.name), type(other.type), subtype(other.subtype) { }
|
||||
: name(other.name), type(other.type), subtype(other.subtype), optional(other.optional) { }
|
||||
|
||||
/**
|
||||
* Unserializes a field.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue