Consumer.hh revision 9557
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) 479557Sandreas.hansson@arm.com : m_last_scheduled_wakeup(0), 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 599171Snilay@cs.wisc.edu const Tick& 607039Snate@binkert.org getLastScheduledWakeup() const 617039Snate@binkert.org { 627039Snate@binkert.org return m_last_scheduled_wakeup; 637039Snate@binkert.org } 647039Snate@binkert.org 657039Snate@binkert.org void 669171Snilay@cs.wisc.edu setLastScheduledWakeup(const Tick& time) 677039Snate@binkert.org { 687039Snate@binkert.org m_last_scheduled_wakeup = time; 697039Snate@binkert.org } 707039Snate@binkert.org 717039Snate@binkert.org bool 729171Snilay@cs.wisc.edu alreadyScheduled(Tick time) 737039Snate@binkert.org { 747039Snate@binkert.org return m_scheduled_wakeups.find(time) != m_scheduled_wakeups.end(); 757039Snate@binkert.org } 767039Snate@binkert.org 777039Snate@binkert.org void 789171Snilay@cs.wisc.edu insertScheduledWakeupTime(Tick time) 797039Snate@binkert.org { 807039Snate@binkert.org m_scheduled_wakeups.insert(time); 817039Snate@binkert.org } 827039Snate@binkert.org 837039Snate@binkert.org void 849171Snilay@cs.wisc.edu removeScheduledWakeupTime(Tick time) 857039Snate@binkert.org { 867039Snate@binkert.org assert(alreadyScheduled(time)); 877039Snate@binkert.org m_scheduled_wakeups.erase(time); 887039Snate@binkert.org } 897039Snate@binkert.org 909499Snilay@cs.wisc.edu void scheduleEvent(Cycles timeDelta); 919499Snilay@cs.wisc.edu void scheduleEventAbsolute(Cycles timeAbs); 929171Snilay@cs.wisc.edu 937039Snate@binkert.org private: 949171Snilay@cs.wisc.edu Tick m_last_scheduled_wakeup; 959171Snilay@cs.wisc.edu std::set<Tick> m_scheduled_wakeups; 969465Snilay@cs.wisc.edu ClockedObject *em; 979171Snilay@cs.wisc.edu 989171Snilay@cs.wisc.edu class ConsumerEvent : public Event 999171Snilay@cs.wisc.edu { 1009171Snilay@cs.wisc.edu public: 1019171Snilay@cs.wisc.edu ConsumerEvent(Consumer* _consumer) 1029171Snilay@cs.wisc.edu : Event(Default_Pri, AutoDelete), m_consumer_ptr(_consumer) 1039171Snilay@cs.wisc.edu { 1049171Snilay@cs.wisc.edu } 1059171Snilay@cs.wisc.edu 1069171Snilay@cs.wisc.edu void process() 1079171Snilay@cs.wisc.edu { 1089171Snilay@cs.wisc.edu m_consumer_ptr->wakeup(); 1099171Snilay@cs.wisc.edu m_consumer_ptr->removeScheduledWakeupTime(when()); 1109171Snilay@cs.wisc.edu } 1119171Snilay@cs.wisc.edu 1129171Snilay@cs.wisc.edu private: 1139171Snilay@cs.wisc.edu Consumer* m_consumer_ptr; 1149171Snilay@cs.wisc.edu }; 1156145Snate@binkert.org}; 1166145Snate@binkert.org 1177039Snate@binkert.orginline std::ostream& 1187039Snate@binkert.orgoperator<<(std::ostream& out, const Consumer& obj) 1196145Snate@binkert.org{ 1207039Snate@binkert.org obj.print(out); 1217039Snate@binkert.org out << std::flush; 1227039Snate@binkert.org return out; 1236145Snate@binkert.org} 1246145Snate@binkert.org 1257039Snate@binkert.org#endif // __MEM_RUBY_COMMON_CONSUMER_HH__ 126