Hello Curtis Dunham,
I'd like you to do a code review. Please visit
https://gem5-review.googlesource.com/3220
to review the following change.
Change subject: python: Add a helper function to create Python events
......................................................................
python: Add a helper function to create Python events
Add a helper function, m5.event.create(), to create events from
Python. This function takes a callable Python object (e.g., a
function) as an argument and optionally a priority as a keyword
argument. This function was accidentally dropped from the public API
when switching to PyBind.
Change-Id: Icbd0e392d9506934ec2c9f541199aa35c1c2df8c
Signed-off-by: Andreas Sandberg <[email protected]>
Reviewed-by: Curtis Dunham <[email protected]>
---
M src/python/m5/event.py
1 file changed, 27 insertions(+), 1 deletion(-)
diff --git a/src/python/m5/event.py b/src/python/m5/event.py
index d1aff9e..20f81b9 100644
--- a/src/python/m5/event.py
+++ b/src/python/m5/event.py
@@ -48,6 +48,25 @@
mainq = None
+class EventWrapper(Event):
+ """Helper class to wrap callable objects in an Event base class"""
+
+ def __init__(self, func, **kwargs):
+ super(EventWrapper, self).__init__(**kwargs)
+
+ if not callable(func):
+ raise RuntimeError("Can't wrap '%s', object is not callable" %
\
+ str(func))
+
+ self._func = func
+
+ def __call__(self):
+ self._func()
+
+ def __str__(self):
+ return "EventWrapper(%s)" % (str(self._func), )
+
+
class ProgressEvent(Event):
def __init__(self, eventq, period):
super(ProgressEvent, self).__init__()
@@ -59,4 +78,11 @@
print "Progress! Time now %fs" % (m5.curTick()/1e12)
self.eventq.schedule(self, m5.curTick() + self.period)
-__all__ = [ 'Event', 'ProgressEvent', 'SimExit', 'mainq' ]
+
+def create(func, priority=Event.Default_Pri):
+ """Create an Event from a function"""
+
+ return EventWrapper(func, priority=priority)
+
+__all__ = [ 'Event', 'EventWrapper', 'ProgressEvent', 'SimExit',
+ 'mainq', 'create' ]
--
To view, visit https://gem5-review.googlesource.com/3220
To unsubscribe, visit https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: Icbd0e392d9506934ec2c9f541199aa35c1c2df8c
Gerrit-Change-Number: 3220
Gerrit-PatchSet: 1
Gerrit-Owner: Andreas Sandberg <[email protected]>
Gerrit-Reviewer: Curtis Dunham <[email protected]>
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev