Consumer.hh revision 9465
16145SN/A/* 28683SN/A * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 310973Sdavid.hashe@amd.com * All rights reserved. 46145SN/A * 56145SN/A * Redistribution and use in source and binary forms, with or without 66145SN/A * modification, are permitted provided that the following conditions are 76145SN/A * met: redistributions of source code must retain the above copyright 86145SN/A * notice, this list of conditions and the following disclaimer; 96145SN/A * redistributions in binary form must reproduce the above copyright 106145SN/A * notice, this list of conditions and the following disclaimer in the 116145SN/A * documentation and/or other materials provided with the distribution; 126145SN/A * neither the name of the copyright holders nor the names of its 136145SN/A * contributors may be used to endorse or promote products derived from 146145SN/A * this software without specific prior written permission. 156145SN/A * 166145SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 176145SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 186145SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 196145SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 206145SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 216145SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 226145SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 236145SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 246145SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 256145SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 266145SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 276145SN/A */ 286145SN/A 296145SN/A/* 3010441Snilay@cs.wisc.edu * This is the virtual base class of all classes that can be the 3110441Snilay@cs.wisc.edu * targets of wakeup events. There is only two methods, wakeup() and 326145SN/A * print() and no data members. 337055SN/A */ 346145SN/A 356145SN/A#ifndef __MEM_RUBY_COMMON_CONSUMER_HH__ 367039SN/A#define __MEM_RUBY_COMMON_CONSUMER_HH__ 379104SN/A 3810301Snilay@cs.wisc.edu#include <iostream> 399105SN/A#include <set> 408174SN/A 417039SN/A#include "mem/ruby/common/TypeDefines.hh" 427039SN/A#include "sim/clocked_object.hh" 437039SN/A 4410970Sdavid.hashe@amd.comclass Consumer 4510301Snilay@cs.wisc.edu{ 4610301Snilay@cs.wisc.edu public: 477039SN/A Consumer(ClockedObject *_em) 487039SN/A : m_last_scheduled_wakeup(0), m_last_wakeup(0), em(_em) 496145SN/A { 507039SN/A } 517039SN/A 527039SN/A virtual 536876SN/A ~Consumer() 547039SN/A { } 557039SN/A 566145SN/A virtual void wakeup() = 0; 577039SN/A virtual void print(std::ostream& out) const = 0; 586145SN/A virtual void storeEventInfo(int info) {} 597039SN/A 607039SN/A const Tick& 618165SN/A getLastScheduledWakeup() const 627039SN/A { 636145SN/A return m_last_scheduled_wakeup; 647039SN/A } 658165SN/A 667039SN/A void 676145SN/A setLastScheduledWakeup(const Tick& time) 687039SN/A { 697039SN/A m_last_scheduled_wakeup = time; 706145SN/A } 717039SN/A 727039SN/A bool 737039SN/A alreadyScheduled(Tick time) 747039SN/A { 756145SN/A return m_scheduled_wakeups.find(time) != m_scheduled_wakeups.end(); 767039SN/A } 7710974Sdavid.hashe@amd.com 7810974Sdavid.hashe@amd.com void 7910974Sdavid.hashe@amd.com insertScheduledWakeupTime(Tick time) 8010974Sdavid.hashe@amd.com { 8110974Sdavid.hashe@amd.com m_scheduled_wakeups.insert(time); 8210974Sdavid.hashe@amd.com } 8310974Sdavid.hashe@amd.com 848193SN/A void 858193SN/A removeScheduledWakeupTime(Tick time) 8610974Sdavid.hashe@amd.com { 878193SN/A assert(alreadyScheduled(time)); 886145SN/A m_scheduled_wakeups.erase(time); 897039SN/A } 907039SN/A 916145SN/A void scheduleEvent(Time timeDelta); 927039SN/A void scheduleEventAbsolute(Time timeAbs); 937039SN/A 946145SN/A private: 957039SN/A Tick m_last_scheduled_wakeup; 967839SN/A std::set<Tick> m_scheduled_wakeups; 977839SN/A Tick m_last_wakeup; 986145SN/A ClockedObject *em; 999499SN/A 10010969Sdavid.hashe@amd.com class ConsumerEvent : public Event 10110969Sdavid.hashe@amd.com { 10210969Sdavid.hashe@amd.com public: 1036285SN/A ConsumerEvent(Consumer* _consumer) 1047039SN/A : Event(Default_Pri, AutoDelete), m_consumer_ptr(_consumer) 1058683SN/A { 1066145SN/A } 1077039SN/A 1087039SN/A void process() 1096145SN/A { 1107039SN/A m_consumer_ptr->wakeup(); 1117039SN/A m_consumer_ptr->removeScheduledWakeupTime(when()); 1127039SN/A } 1139692SN/A 1147039SN/A private: 1157055SN/A Consumer* m_consumer_ptr; 1167055SN/A }; 1176145SN/A}; 1189692SN/A 1199692SN/Ainline std::ostream& 1209692SN/Aoperator<<(std::ostream& out, const Consumer& obj) 1216374SN/A{ 1229692SN/A obj.print(out); 1239692SN/A out << std::flush; 1249692SN/A return out; 1259692SN/A} 1269692SN/A 1279692SN/A#endif // __MEM_RUBY_COMMON_CONSUMER_HH__ 1289692SN/A