mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Event: No need to be Obj
It's not fully clear to me why Event needs to be an Obj. Not inheriting from Obj avoids needing a vtable and allows to skip the Obj constructor and destructor for a bit of a performance improvement in microbenchmarks. Open-code Ref() and Unref() to keep the HookQueueEvent() API stable for plugins that took charge of the Event (and need to free/unref it).
This commit is contained in:
parent
ebb00d37bc
commit
d163820d79
2 changed files with 14 additions and 19 deletions
18
src/Event.cc
18
src/Event.cc
|
@ -4,7 +4,6 @@
|
|||
|
||||
#include "zeek/Desc.h"
|
||||
#include "zeek/Trigger.h"
|
||||
#include "zeek/Val.h"
|
||||
#include "zeek/iosource/Manager.h"
|
||||
#include "zeek/plugin/Manager.h"
|
||||
|
||||
|
@ -16,7 +15,8 @@ namespace zeek {
|
|||
|
||||
Event::Event(const EventHandlerPtr& arg_handler, zeek::Args arg_args, util::detail::SourceID arg_src,
|
||||
analyzer::ID arg_aid, Obj* arg_obj, double arg_ts)
|
||||
: handler(arg_handler),
|
||||
: ref_cnt(1),
|
||||
handler(arg_handler),
|
||||
args(std::move(arg_args)),
|
||||
src(arg_src),
|
||||
aid(arg_aid),
|
||||
|
@ -27,20 +27,6 @@ Event::Event(const EventHandlerPtr& arg_handler, zeek::Args arg_args, util::deta
|
|||
Ref(obj);
|
||||
}
|
||||
|
||||
void Event::Describe(ODesc* d) const {
|
||||
if ( d->IsReadable() )
|
||||
d->AddSP("event");
|
||||
|
||||
bool s = d->IsShort();
|
||||
d->SetShort(s);
|
||||
|
||||
if ( ! d->IsBinary() )
|
||||
d->Add("(");
|
||||
describe_vals(args, d);
|
||||
if ( ! d->IsBinary() )
|
||||
d->Add("(");
|
||||
}
|
||||
|
||||
void Event::Dispatch(bool no_remote) {
|
||||
if ( src == util::detail::SOURCE_BROKER )
|
||||
no_remote = true;
|
||||
|
|
15
src/Event.h
15
src/Event.h
|
@ -17,8 +17,9 @@ extern double network_time;
|
|||
} // namespace run_state
|
||||
|
||||
class EventMgr;
|
||||
class Event;
|
||||
|
||||
class Event final : public Obj {
|
||||
class Event final {
|
||||
public:
|
||||
Event(const EventHandlerPtr& handler, zeek::Args args, util::detail::SourceID src = util::detail::SOURCE_LOCAL,
|
||||
analyzer::ID aid = 0, Obj* obj = nullptr, double ts = run_state::network_time);
|
||||
|
@ -32,15 +33,16 @@ public:
|
|||
const zeek::Args& Args() const { return args; }
|
||||
double Time() const { return ts; }
|
||||
|
||||
void Describe(ODesc* d) const override;
|
||||
|
||||
private:
|
||||
friend class EventMgr;
|
||||
friend void inline Ref(Event*);
|
||||
friend inline void Unref(Event*);
|
||||
|
||||
// This method is protected to make sure that everybody goes through
|
||||
// EventMgr::Dispatch().
|
||||
void Dispatch(bool no_remote = false);
|
||||
|
||||
int ref_cnt;
|
||||
EventHandlerPtr handler;
|
||||
zeek::Args args;
|
||||
util::detail::SourceID src;
|
||||
|
@ -50,6 +52,13 @@ private:
|
|||
Event* next_event;
|
||||
};
|
||||
|
||||
inline void Unref(Event* e) {
|
||||
if ( e && --e->ref_cnt <= 0 )
|
||||
delete e;
|
||||
}
|
||||
|
||||
inline void Ref(Event* e) { ++(e->ref_cnt); }
|
||||
|
||||
class EventMgr final : public iosource::IOSource {
|
||||
public:
|
||||
~EventMgr() override;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue