mirror of
https://github.com/zeek/zeek.git
synced 2025-10-04 07:38:19 +00:00
cluster/ThreadedBackend: Switch to OnLoopProcess
This commit is contained in:
parent
5dee77e6f2
commit
23405194a0
2 changed files with 36 additions and 71 deletions
|
@ -5,17 +5,14 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <optional>
|
||||
#include <string_view>
|
||||
#include <variant>
|
||||
|
||||
#include "zeek/EventHandler.h"
|
||||
#include "zeek/Flare.h"
|
||||
#include "zeek/IntrusivePtr.h"
|
||||
#include "zeek/Span.h"
|
||||
#include "zeek/cluster/Serializer.h"
|
||||
#include "zeek/iosource/IOSource.h"
|
||||
#include "zeek/logging/Types.h"
|
||||
|
||||
namespace zeek {
|
||||
|
@ -28,6 +25,11 @@ class Val;
|
|||
using ValPtr = IntrusivePtr<Val>;
|
||||
using ArgsSpan = Span<const ValPtr>;
|
||||
|
||||
namespace detail {
|
||||
template<class Proc, class Work>
|
||||
class OnLoopProcess;
|
||||
}
|
||||
|
||||
namespace cluster {
|
||||
|
||||
namespace detail {
|
||||
|
@ -465,11 +467,14 @@ using QueueMessages = std::vector<QueueMessage>;
|
|||
* Support for backends that use background threads or invoke
|
||||
* callbacks on non-main threads.
|
||||
*/
|
||||
class ThreadedBackend : public Backend, public zeek::iosource::IOSource {
|
||||
public:
|
||||
using Backend::Backend;
|
||||
|
||||
class ThreadedBackend : public Backend {
|
||||
protected:
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
ThreadedBackend(std::unique_ptr<EventSerializer> es, std::unique_ptr<LogSerializer> ls,
|
||||
std::unique_ptr<detail::EventHandlingStrategy> ehs);
|
||||
|
||||
/**
|
||||
* To be used by implementations to enqueue messages for processing on the IO loop.
|
||||
*
|
||||
|
@ -479,20 +484,11 @@ protected:
|
|||
*/
|
||||
void QueueForProcessing(QueueMessages&& messages);
|
||||
|
||||
void Process() override;
|
||||
|
||||
double GetNextTimeout() override { return -1; }
|
||||
|
||||
/**
|
||||
* The DoInitPostScript() implementation of ThreadedBackend
|
||||
* registers itself as a non-counting IO source.
|
||||
*
|
||||
* Classes deriving from ThreadedBackend and providing their
|
||||
* own DoInitPostScript() method should invoke the ThreadedBackend's
|
||||
* implementation to register themselves as a non-counting
|
||||
* IO source with the IO loop.
|
||||
* Delegate to onloop->Process() to trigger processing
|
||||
* of outstanding queued messages explicitly, if any.
|
||||
*/
|
||||
void DoInitPostScript() override;
|
||||
void Process();
|
||||
|
||||
/**
|
||||
* The default DoInit() implementation of ThreadedBackend
|
||||
|
@ -518,10 +514,16 @@ private:
|
|||
*/
|
||||
virtual bool DoProcessBackendMessage(int tag, detail::byte_buffer_span payload) { return false; };
|
||||
|
||||
/**
|
||||
* Hook method for OnLooProcess.
|
||||
*/
|
||||
void Process(QueueMessages&& messages);
|
||||
|
||||
// Allow access to Process(QueueMessages)
|
||||
friend class zeek::detail::OnLoopProcess<ThreadedBackend, QueueMessages>;
|
||||
|
||||
// Members used for communication with the main thread.
|
||||
std::mutex messages_mtx;
|
||||
std::vector<QueueMessage> messages;
|
||||
zeek::detail::Flare messages_flare;
|
||||
zeek::detail::OnLoopProcess<ThreadedBackend, QueueMessages>* onloop;
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue