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

@ -5,6 +5,8 @@
#include "BasicThread.h"
#include "Queue.h"
#include "iosource/IOSource.h"
#include "Flare.h"
namespace threading {
@ -23,7 +25,7 @@ class HeartbeatMessage;
* that happens, the thread stops accepting any new messages, finishes
* processes all remaining ones still in the queue, and then exits.
*/
class MsgThread : public BasicThread
class MsgThread : public BasicThread, public iosource::IOSource
{
public:
/**
@ -34,6 +36,11 @@ public:
*/
MsgThread();
/**
* Destructor.
*/
virtual ~MsgThread();
/**
* Sends a message to the child thread. The message will be proceesed
* once the thread has retrieved it from its incoming queue.
@ -175,6 +182,13 @@ public:
*/
void GetStats(Stats* stats);
/**
* Overridden from iosource::IOSource.
*/
void Process() override;
const char* Tag() override { return Name(); }
double GetNextTimeout() override { return -1; }
protected:
friend class Manager;
friend class HeartbeatMessage;
@ -229,7 +243,6 @@ protected:
/**
* Overriden from BasicThread.
*
*/
void Run() override;
void OnWaitForStop() override;
@ -308,6 +321,8 @@ private:
bool child_finished; // Child thread is finished.
bool child_sent_finish; // Child thread asked to be finished.
bool failed; // Set to true when a command failed.
bro::Flare flare;
};
/**