event.py revision 5696
14167Sbinkertn@umich.edu# Copyright (c) 2006 The Regents of The University of Michigan
24167Sbinkertn@umich.edu# All rights reserved.
34167Sbinkertn@umich.edu#
44167Sbinkertn@umich.edu# Redistribution and use in source and binary forms, with or without
54167Sbinkertn@umich.edu# modification, are permitted provided that the following conditions are
64167Sbinkertn@umich.edu# met: redistributions of source code must retain the above copyright
74167Sbinkertn@umich.edu# notice, this list of conditions and the following disclaimer;
84167Sbinkertn@umich.edu# redistributions in binary form must reproduce the above copyright
94167Sbinkertn@umich.edu# notice, this list of conditions and the following disclaimer in the
104167Sbinkertn@umich.edu# documentation and/or other materials provided with the distribution;
114167Sbinkertn@umich.edu# neither the name of the copyright holders nor the names of its
124167Sbinkertn@umich.edu# contributors may be used to endorse or promote products derived from
134167Sbinkertn@umich.edu# this software without specific prior written permission.
144167Sbinkertn@umich.edu#
154167Sbinkertn@umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
164167Sbinkertn@umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
174167Sbinkertn@umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
184167Sbinkertn@umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
194167Sbinkertn@umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
204167Sbinkertn@umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
214167Sbinkertn@umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
224167Sbinkertn@umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
234167Sbinkertn@umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
244167Sbinkertn@umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
254167Sbinkertn@umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
264167Sbinkertn@umich.edu#
274167Sbinkertn@umich.edu# Authors: Nathan Binkert
284167Sbinkertn@umich.edu
295696Snate@binkert.orgimport m5
305605Snate@binkert.orgimport internal.event
314167Sbinkertn@umich.edu
325605Snate@binkert.orgfrom internal.event import PythonEvent, SimLoopExitEvent as SimExit
335605Snate@binkert.org
345605Snate@binkert.orgmainq = internal.event.cvar.mainEventQueue
355605Snate@binkert.org
365605Snate@binkert.orgdef create(obj, priority=None):
375605Snate@binkert.org    if priority is None:
385605Snate@binkert.org        priority = internal.event.Event.Default_Pri
395605Snate@binkert.org    return internal.event.PythonEvent(obj, priority)
405605Snate@binkert.org
415605Snate@binkert.orgclass Event(PythonEvent):
425605Snate@binkert.org    def __init__(self, priority=None):
435605Snate@binkert.org        if priority is None:
445605Snate@binkert.org            priority = internal.event.Event.Default_Pri
455696Snate@binkert.org        super(Event, self).__init__(self, priority)
465605Snate@binkert.org
475605Snate@binkert.orgclass ProgressEvent(Event):
485605Snate@binkert.org    def __init__(self, eventq, period):
495605Snate@binkert.org        super(ProgressEvent, self).__init__()
504167Sbinkertn@umich.edu        self.period = int(period)
515605Snate@binkert.org        self.eventq = eventq
525605Snate@binkert.org        self.eventq.schedule(self, m5.curTick() + self.period)
534167Sbinkertn@umich.edu
544167Sbinkertn@umich.edu    def __call__(self):
554167Sbinkertn@umich.edu        print "Progress! Time now %fs" % (m5.curTick()/1e12)
565605Snate@binkert.org        self.eventq.schedule(self, m5.curTick() + self.period)
575605Snate@binkert.org
585605Snate@binkert.org__all__ = [ 'create', 'Event', 'ProgressEvent', 'SimExit', 'mainq' ]
59