event.py (11988:665cd5f8b52b) | event.py (12024:4ae7a812176a) |
---|---|
1# Copyright (c) 2017 ARM Limited 2# All rights reserved. 3# 4# The license below extends only to copyright in the software and shall 5# not be construed as granting a license to any other intellectual 6# property including but not limited to intellectual property relating 7# to a hardware implementation of the functionality of the software 8# licensed hereunder. You may use the software subject to the license --- 34 unchanged lines hidden (view full) --- 43import m5 44import _m5.event 45 46from _m5.event import GlobalSimLoopExitEvent as SimExit 47from _m5.event import Event, getEventQueue, setEventQueue 48 49mainq = None 50 | 1# Copyright (c) 2017 ARM Limited 2# All rights reserved. 3# 4# The license below extends only to copyright in the software and shall 5# not be construed as granting a license to any other intellectual 6# property including but not limited to intellectual property relating 7# to a hardware implementation of the functionality of the software 8# licensed hereunder. You may use the software subject to the license --- 34 unchanged lines hidden (view full) --- 43import m5 44import _m5.event 45 46from _m5.event import GlobalSimLoopExitEvent as SimExit 47from _m5.event import Event, getEventQueue, setEventQueue 48 49mainq = None 50 |
51class EventWrapper(Event): 52 """Helper class to wrap callable objects in an Event base class""" 53 54 def __init__(self, func, **kwargs): 55 super(EventWrapper, self).__init__(**kwargs) 56 57 if not callable(func): 58 raise RuntimeError("Can't wrap '%s', object is not callable" % \ 59 str(func)) 60 61 self._func = func 62 63 def __call__(self): 64 self._func() 65 66 def __str__(self): 67 return "EventWrapper(%s)" % (str(self._func), ) 68 69 |
|
51class ProgressEvent(Event): 52 def __init__(self, eventq, period): 53 super(ProgressEvent, self).__init__() 54 self.period = int(period) 55 self.eventq = eventq 56 self.eventq.schedule(self, m5.curTick() + self.period) 57 58 def __call__(self): 59 print "Progress! Time now %fs" % (m5.curTick()/1e12) 60 self.eventq.schedule(self, m5.curTick() + self.period) 61 | 70class ProgressEvent(Event): 71 def __init__(self, eventq, period): 72 super(ProgressEvent, self).__init__() 73 self.period = int(period) 74 self.eventq = eventq 75 self.eventq.schedule(self, m5.curTick() + self.period) 76 77 def __call__(self): 78 print "Progress! Time now %fs" % (m5.curTick()/1e12) 79 self.eventq.schedule(self, m5.curTick() + self.period) 80 |
62__all__ = [ 'Event', 'ProgressEvent', 'SimExit', 'mainq' ] | 81 82def create(func, priority=Event.Default_Pri): 83 """Create an Event from a function""" 84 85 return EventWrapper(func, priority=priority) 86 87__all__ = [ 'Event', 'EventWrapper', 'ProgressEvent', 'SimExit', 88 'mainq', 'create' ] |