Sean Wilson has uploaded this change for review. ( https://gem5-review.googlesource.com/3743

Change subject: sim: Add generic EventFunctionWrapper
......................................................................

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 <spwils...@wisc.edu>
---
M src/sim/eventq.hh
1 file changed, 28 insertions(+), 0 deletions(-)



diff --git a/src/sim/eventq.hh b/src/sim/eventq.hh
index 9d3c5c3..6d68b4e 100644
--- a/src/sim/eventq.hh
+++ b/src/sim/eventq.hh
@@ -800,4 +800,32 @@
     const char *description() const { return "EventWrapped"; }
 };

+class EventFunctionWrapper : public Event
+{
+  private:
+      std::function<void(void)> callback;
+      std::string _name;
+
+  public:
+    EventFunctionWrapper(const std::function<void(void)> &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__

--
To view, visit https://gem5-review.googlesource.com/3743
To unsubscribe, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iab140df47bd0f7e4b3fe3b568f9dd122a43cee1c
Gerrit-Change-Number: 3743
Gerrit-PatchSet: 1
Gerrit-Owner: Sean Wilson <spwils...@wisc.edu>
_______________________________________________
gem5-dev mailing list
gem5-dev@gem5.org
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to