event.py revision 5605
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
295605Snate@binkert.orgimport internal.event
304167Sbinkertn@umich.edu
315605Snate@binkert.orgfrom internal.event import PythonEvent, SimLoopExitEvent as SimExit
325605Snate@binkert.org
335605Snate@binkert.orgmainq = internal.event.cvar.mainEventQueue
345605Snate@binkert.org
355605Snate@binkert.orgdef create(obj, priority=None):
365605Snate@binkert.org    if priority is None:
375605Snate@binkert.org        priority = internal.event.Event.Default_Pri
385605Snate@binkert.org    return internal.event.PythonEvent(obj, priority)
395605Snate@binkert.org
405605Snate@binkert.orgclass Event(PythonEvent):
415605Snate@binkert.org    def __init__(self, priority=None):
425605Snate@binkert.org        if priority is None:
435605Snate@binkert.org            priority = internal.event.Event.Default_Pri
445605Snate@binkert.org        super(PythonEvent, self).__init__(self, priority)
455605Snate@binkert.org
465605Snate@binkert.orgclass ProgressEvent(Event):
475605Snate@binkert.org    def __init__(self, eventq, period):
485605Snate@binkert.org        super(ProgressEvent, self).__init__()
494167Sbinkertn@umich.edu        self.period = int(period)
505605Snate@binkert.org        self.eventq = eventq
515605Snate@binkert.org        self.eventq.schedule(self, m5.curTick() + self.period)
524167Sbinkertn@umich.edu
534167Sbinkertn@umich.edu    def __call__(self):
544167Sbinkertn@umich.edu        print "Progress! Time now %fs" % (m5.curTick()/1e12)
555605Snate@binkert.org        self.eventq.schedule(self, m5.curTick() + self.period)
565605Snate@binkert.org
575605Snate@binkert.org__all__ = [ 'create', 'Event', 'ProgressEvent', 'SimExit', 'mainq' ]
58