From e34924b50fd3362dc51a67c51c6d7f2b2015cf30 Mon Sep 17 00:00:00 2001 From: Sean Wilson Date: Tue, 6 Jun 2017 16:05:48 -0500 Subject: [PATCH] sim: Add generic EventFunctionWrapper Add EventFunctionWrapper, an event wrapper which takes any callable object to use as its callback. (This includes c++ lambdas, function pointers, bound functions, and std::functions.) Change-Id: Iab140df47bd0f7e4b3fe3b568f9dd122a43cee1c Signed-off-by: Sean Wilson Reviewed-on: https://gem5-review.googlesource.com/3743 Reviewed-by: Anthony Gutierrez Reviewed-by: Jason Lowe-Power Maintainer: Anthony Gutierrez --- src/sim/eventq.hh | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/sim/eventq.hh b/src/sim/eventq.hh index 9d3c5c36a..6d68b4e3a 100644 --- a/src/sim/eventq.hh +++ b/src/sim/eventq.hh @@ -800,4 +800,32 @@ class EventWrapper : public Event const char *description() const { return "EventWrapped"; } }; +class EventFunctionWrapper : public Event +{ + private: + std::function callback; + std::string _name; + + public: + EventFunctionWrapper(const std::function &callback, + const std::string &name, + bool del = false, + Priority p = Default_Pri) + : Event(p), callback(callback), _name(name) + { + if (del) + setFlags(AutoDelete); + } + + void process() { callback(); } + + const std::string + name() const + { + return _name + ".wrapped_function_event"; + } + + const char *description() const { return "EventFunctionWrapped"; } +}; + #endif // __SIM_EVENTQ_HH__ -- 2.30.2