Sean Wilson has submitted this change and it was merged. ( 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>
Reviewed-on: https://gem5-review.googlesource.com/3743
Reviewed-by: Anthony Gutierrez <anthony.gutier...@amd.com>
Reviewed-by: Jason Lowe-Power <ja...@lowepower.com>
Maintainer: Anthony Gutierrez <anthony.gutier...@amd.com>
---
M src/sim/eventq.hh
1 file changed, 28 insertions(+), 0 deletions(-)

Approvals:
  Jason Lowe-Power: Looks good to me, approved
  Anthony Gutierrez: Looks good to me, approved; Looks good to me, approved



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: merged
Gerrit-Change-Id: Iab140df47bd0f7e4b3fe3b568f9dd122a43cee1c
Gerrit-Change-Number: 3743
Gerrit-PatchSet: 3
Gerrit-Owner: Sean Wilson <spwils...@wisc.edu>
Gerrit-Reviewer: Anthony Gutierrez <anthony.gutier...@amd.com>
Gerrit-Reviewer: Jason Lowe-Power <ja...@lowepower.com>
Gerrit-Reviewer: Sean Wilson <spwils...@wisc.edu>
_______________________________________________
gem5-dev mailing list
gem5-dev@gem5.org
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to