Consumer.hh revision 7039:bc0b6ea676b5
11060SN/A/* 22702SN/A * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 31060SN/A * All rights reserved. 41060SN/A * 51060SN/A * Redistribution and use in source and binary forms, with or without 61060SN/A * modification, are permitted provided that the following conditions are 71060SN/A * met: redistributions of source code must retain the above copyright 81060SN/A * notice, this list of conditions and the following disclaimer; 91060SN/A * redistributions in binary form must reproduce the above copyright 101060SN/A * notice, this list of conditions and the following disclaimer in the 111060SN/A * documentation and/or other materials provided with the distribution; 121060SN/A * neither the name of the copyright holders nor the names of its 131060SN/A * contributors may be used to endorse or promote products derived from 141060SN/A * this software without specific prior written permission. 151060SN/A * 161060SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 171060SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 181060SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 191060SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 201060SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 211060SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 221060SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 231060SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 241060SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 251060SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 261060SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665SN/A */ 282665SN/A 291060SN/A/* 301060SN/A * This is the virtual base class of all classes that can be the 311060SN/A * targets of wakeup events. There is only two methods, wakeup() and 322292SN/A * print() and no data members. 331060SN/A */ 341060SN/A 351060SN/A#ifndef __MEM_RUBY_COMMON_CONSUMER_HH__ 361060SN/A#define __MEM_RUBY_COMMON_CONSUMER_HH__ 371061SN/A 386658Snate@binkert.org#include <iostream> 396658Snate@binkert.org#include <set> 401060SN/A 412669SN/A#include "mem/ruby/common/Global.hh" 426658Snate@binkert.org#include "mem/ruby/eventqueue/RubyEventQueue.hh" 431060SN/A 441060SN/Aclass MessageBuffer; 451060SN/A 461060SN/Aclass Consumer 471060SN/A{ 481060SN/A public: 491060SN/A Consumer() 501060SN/A : m_last_scheduled_wakeup(0), m_last_wakeup(0) 512292SN/A { 522292SN/A } 531060SN/A 542292SN/A virtual 551060SN/A ~Consumer() 561060SN/A { } 572292SN/A 582292SN/A void 592292SN/A triggerWakeup(RubyEventQueue *eventQueue) 601060SN/A { 611060SN/A Time time = eventQueue->getTime(); 621060SN/A if (m_last_wakeup != time) { 631061SN/A wakeup(); 644636Sgblack@eecs.umich.edu m_last_wakeup = time; 653801Sgblack@eecs.umich.edu } 664636Sgblack@eecs.umich.edu } 673794Sgblack@eecs.umich.edu 684636Sgblack@eecs.umich.edu virtual void wakeup() = 0; 693794Sgblack@eecs.umich.edu virtual void print(std::ostream& out) const = 0; 704636Sgblack@eecs.umich.edu 711060SN/A const Time& 721464SN/A getLastScheduledWakeup() const 731061SN/A { 744636Sgblack@eecs.umich.edu return m_last_scheduled_wakeup; 754654Sgblack@eecs.umich.edu } 764636Sgblack@eecs.umich.edu 771464SN/A void 784636Sgblack@eecs.umich.edu setLastScheduledWakeup(const Time& time) 794636Sgblack@eecs.umich.edu { 804636Sgblack@eecs.umich.edu m_last_scheduled_wakeup = time; 814636Sgblack@eecs.umich.edu } 824636Sgblack@eecs.umich.edu 834636Sgblack@eecs.umich.edu bool 844636Sgblack@eecs.umich.edu alreadyScheduled(Time time) 854636Sgblack@eecs.umich.edu { 864636Sgblack@eecs.umich.edu return m_scheduled_wakeups.find(time) != m_scheduled_wakeups.end(); 874636Sgblack@eecs.umich.edu } 881464SN/A 893794Sgblack@eecs.umich.edu void 904636Sgblack@eecs.umich.edu insertScheduledWakeupTime(Time time) 914636Sgblack@eecs.umich.edu { 924636Sgblack@eecs.umich.edu m_scheduled_wakeups.insert(time); 934636Sgblack@eecs.umich.edu } 944636Sgblack@eecs.umich.edu 954636Sgblack@eecs.umich.edu void 964636Sgblack@eecs.umich.edu removeScheduledWakeupTime(Time time) 974636Sgblack@eecs.umich.edu { 984636Sgblack@eecs.umich.edu assert(alreadyScheduled(time)); 994636Sgblack@eecs.umich.edu m_scheduled_wakeups.erase(time); 1004636Sgblack@eecs.umich.edu } 1014636Sgblack@eecs.umich.edu 1024636Sgblack@eecs.umich.edu private: 1034654Sgblack@eecs.umich.edu Time m_last_scheduled_wakeup; 1044636Sgblack@eecs.umich.edu std::set<Time> m_scheduled_wakeups; 1054636Sgblack@eecs.umich.edu Time m_last_wakeup; 1064636Sgblack@eecs.umich.edu}; 1074636Sgblack@eecs.umich.edu 1084654Sgblack@eecs.umich.eduinline std::ostream& 1094636Sgblack@eecs.umich.eduoperator<<(std::ostream& out, const Consumer& obj) 1104636Sgblack@eecs.umich.edu{ 1114636Sgblack@eecs.umich.edu obj.print(out); 1124636Sgblack@eecs.umich.edu out << std::flush; 1134636Sgblack@eecs.umich.edu return out; 1144636Sgblack@eecs.umich.edu} 1154636Sgblack@eecs.umich.edu 1164636Sgblack@eecs.umich.edu#endif // __MEM_RUBY_COMMON_CONSUMER_HH__ 1174636Sgblack@eecs.umich.edu