Threading changes for the new loop architecture

- threading::Manager is no longer an IOSource.
- threading::MsgThread is now an IOSource. This allows threads themselves to signal when they have data to process instead of continually checking each of the threads on every loop pass.
- Make the thread heartbeat timer an actual timer and let it fire as necessary instead of checking to see if it should fire
This commit is contained in:
Tim Wojtulewicz 2019-11-26 12:54:51 -07:00
parent a159d075cf
commit 8b9160fb7e
6 changed files with 141 additions and 66 deletions

View file

@ -3,13 +3,25 @@
#include <list>
#include "iosource/IOSource.h"
#include "BasicThread.h"
#include "MsgThread.h"
#include "Timer.h"
namespace threading {
class HeartbeatTimer : public Timer {
public:
HeartbeatTimer(double t) : Timer(t, TIMER_THREAD_HEARTBEAT) {}
virtual ~HeartbeatTimer() {}
void Dispatch(double t, int is_expire);
protected:
void Init();
int do_expire;
};
/**
* The thread manager coordinates all child threads. Once a BasicThread is
* instantitated, it gets addedd to the manager, which will delete it later
@ -20,7 +32,7 @@ namespace threading {
* their outgoing message queue on a regular basis and feeds data sent into
* the rest of Bro. It also triggers the regular heartbeats.
*/
class Manager : public iosource::IOSource
class Manager
{
public:
/**
@ -30,9 +42,9 @@ public:
Manager();
/**
* Destructir.
* Destructor.
*/
~Manager() override;
~Manager();
/**
* Terminates the manager's processor. The method signals all threads
@ -80,6 +92,7 @@ public:
protected:
friend class BasicThread;
friend class MsgThread;
friend class HeartbeatTimer;
/**
* Registers a new basic thread with the manager. This is
@ -99,26 +112,17 @@ protected:
*/
void AddMsgThread(MsgThread* thread);
/**
* Part of the IOSource interface.
*/
void GetFds(iosource::FD_Set* read, iosource::FD_Set* write,
iosource::FD_Set* except) override;
void Flush();
/**
* Part of the IOSource interface.
* Sends heartbeat messages to all active message threads.
*/
double NextTimestamp(double* network_time) override;
void SendHeartbeats();
/**
* Part of the IOSource interface.
* Sets up a timer to periodically send heartbeat messages to all threads.
*/
void Process() override;
/**
* Part of the IOSource interface.
*/
const char* Tag() override { return "threading::Manager"; }
void StartHeartbeatTimer();
private:
typedef std::list<BasicThread*> all_thread_list;
@ -132,6 +136,8 @@ private:
bool terminating; // True if we are in Terminate().
msg_stats_list stats;
HeartbeatTimer* heartbeat_timer = nullptr;
};
}