16145Snate@binkert.org/*
26145Snate@binkert.org * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
36145Snate@binkert.org * All rights reserved.
46145Snate@binkert.org *
56145Snate@binkert.org * Redistribution and use in source and binary forms, with or without
66145Snate@binkert.org * modification, are permitted provided that the following conditions are
76145Snate@binkert.org * met: redistributions of source code must retain the above copyright
86145Snate@binkert.org * notice, this list of conditions and the following disclaimer;
96145Snate@binkert.org * redistributions in binary form must reproduce the above copyright
106145Snate@binkert.org * notice, this list of conditions and the following disclaimer in the
116145Snate@binkert.org * documentation and/or other materials provided with the distribution;
126145Snate@binkert.org * neither the name of the copyright holders nor the names of its
136145Snate@binkert.org * contributors may be used to endorse or promote products derived from
146145Snate@binkert.org * this software without specific prior written permission.
156145Snate@binkert.org *
166145Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
176145Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
186145Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
196145Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
206145Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
216145Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
226145Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
236145Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
246145Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
256145Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
266145Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
276145Snate@binkert.org */
286145Snate@binkert.org
296145Snate@binkert.org/*
307039Snate@binkert.org * This is the virtual base class of all classes that can be the
317039Snate@binkert.org * targets of wakeup events.  There is only two methods, wakeup() and
327039Snate@binkert.org * print() and no data members.
336145Snate@binkert.org */
346145Snate@binkert.org
357039Snate@binkert.org#ifndef __MEM_RUBY_COMMON_CONSUMER_HH__
367039Snate@binkert.org#define __MEM_RUBY_COMMON_CONSUMER_HH__
376145Snate@binkert.org
387002Snate@binkert.org#include <iostream>
397021Stushar@csail.mit.edu#include <set>
407002Snate@binkert.org
419465Snilay@cs.wisc.edu#include "sim/clocked_object.hh"
426145Snate@binkert.org
437039Snate@binkert.orgclass Consumer
447039Snate@binkert.org{
457039Snate@binkert.org  public:
469465Snilay@cs.wisc.edu    Consumer(ClockedObject *_em)
4710123Snilay@cs.wisc.edu        : em(_em)
487039Snate@binkert.org    {
497039Snate@binkert.org    }
506145Snate@binkert.org
517039Snate@binkert.org    virtual
527039Snate@binkert.org    ~Consumer()
537039Snate@binkert.org    { }
546145Snate@binkert.org
557039Snate@binkert.org    virtual void wakeup() = 0;
567039Snate@binkert.org    virtual void print(std::ostream& out) const = 0;
577973Snilay@cs.wisc.edu    virtual void storeEventInfo(int info) {}
586145Snate@binkert.org
597039Snate@binkert.org    bool
609171Snilay@cs.wisc.edu    alreadyScheduled(Tick time)
617039Snate@binkert.org    {
627039Snate@binkert.org        return m_scheduled_wakeups.find(time) != m_scheduled_wakeups.end();
637039Snate@binkert.org    }
647039Snate@binkert.org
657039Snate@binkert.org    void
669171Snilay@cs.wisc.edu    insertScheduledWakeupTime(Tick time)
677039Snate@binkert.org    {
687039Snate@binkert.org        m_scheduled_wakeups.insert(time);
697039Snate@binkert.org    }
707039Snate@binkert.org
719600Snilay@cs.wisc.edu    void scheduleEventAbsolute(Tick timeAbs);
729600Snilay@cs.wisc.edu
739600Snilay@cs.wisc.edu  protected:
749499Snilay@cs.wisc.edu    void scheduleEvent(Cycles timeDelta);
759171Snilay@cs.wisc.edu
767039Snate@binkert.org  private:
779171Snilay@cs.wisc.edu    std::set<Tick> m_scheduled_wakeups;
789465Snilay@cs.wisc.edu    ClockedObject *em;
796145Snate@binkert.org};
806145Snate@binkert.org
817039Snate@binkert.orginline std::ostream&
827039Snate@binkert.orgoperator<<(std::ostream& out, const Consumer& obj)
836145Snate@binkert.org{
847039Snate@binkert.org    obj.print(out);
857039Snate@binkert.org    out << std::flush;
867039Snate@binkert.org    return out;
876145Snate@binkert.org}
886145Snate@binkert.org
897039Snate@binkert.org#endif // __MEM_RUBY_COMMON_CONSUMER_HH__
90