Consumer.hh revision 7039
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 416154Snate@binkert.org#include "mem/ruby/common/Global.hh" 426154Snate@binkert.org#include "mem/ruby/eventqueue/RubyEventQueue.hh" 436145Snate@binkert.org 446145Snate@binkert.orgclass MessageBuffer; 456145Snate@binkert.org 467039Snate@binkert.orgclass Consumer 477039Snate@binkert.org{ 487039Snate@binkert.org public: 497039Snate@binkert.org Consumer() 507039Snate@binkert.org : m_last_scheduled_wakeup(0), m_last_wakeup(0) 517039Snate@binkert.org { 527039Snate@binkert.org } 536145Snate@binkert.org 547039Snate@binkert.org virtual 557039Snate@binkert.org ~Consumer() 567039Snate@binkert.org { } 576145Snate@binkert.org 587039Snate@binkert.org void 597039Snate@binkert.org triggerWakeup(RubyEventQueue *eventQueue) 607039Snate@binkert.org { 617039Snate@binkert.org Time time = eventQueue->getTime(); 627039Snate@binkert.org if (m_last_wakeup != time) { 637039Snate@binkert.org wakeup(); 647039Snate@binkert.org m_last_wakeup = time; 657039Snate@binkert.org } 667039Snate@binkert.org } 676145Snate@binkert.org 687039Snate@binkert.org virtual void wakeup() = 0; 697039Snate@binkert.org virtual void print(std::ostream& out) const = 0; 706145Snate@binkert.org 717039Snate@binkert.org const Time& 727039Snate@binkert.org getLastScheduledWakeup() const 737039Snate@binkert.org { 747039Snate@binkert.org return m_last_scheduled_wakeup; 757039Snate@binkert.org } 767039Snate@binkert.org 777039Snate@binkert.org void 787039Snate@binkert.org setLastScheduledWakeup(const Time& time) 797039Snate@binkert.org { 807039Snate@binkert.org m_last_scheduled_wakeup = time; 817039Snate@binkert.org } 827039Snate@binkert.org 837039Snate@binkert.org bool 847039Snate@binkert.org alreadyScheduled(Time time) 857039Snate@binkert.org { 867039Snate@binkert.org return m_scheduled_wakeups.find(time) != m_scheduled_wakeups.end(); 877039Snate@binkert.org } 887039Snate@binkert.org 897039Snate@binkert.org void 907039Snate@binkert.org insertScheduledWakeupTime(Time time) 917039Snate@binkert.org { 927039Snate@binkert.org m_scheduled_wakeups.insert(time); 937039Snate@binkert.org } 947039Snate@binkert.org 957039Snate@binkert.org void 967039Snate@binkert.org removeScheduledWakeupTime(Time time) 977039Snate@binkert.org { 987039Snate@binkert.org assert(alreadyScheduled(time)); 997039Snate@binkert.org m_scheduled_wakeups.erase(time); 1007039Snate@binkert.org } 1017039Snate@binkert.org 1027039Snate@binkert.org private: 1037039Snate@binkert.org Time m_last_scheduled_wakeup; 1047039Snate@binkert.org std::set<Time> m_scheduled_wakeups; 1057039Snate@binkert.org Time m_last_wakeup; 1066145Snate@binkert.org}; 1076145Snate@binkert.org 1087039Snate@binkert.orginline std::ostream& 1097039Snate@binkert.orgoperator<<(std::ostream& out, const Consumer& obj) 1106145Snate@binkert.org{ 1117039Snate@binkert.org obj.print(out); 1127039Snate@binkert.org out << std::flush; 1137039Snate@binkert.org return out; 1146145Snate@binkert.org} 1156145Snate@binkert.org 1167039Snate@binkert.org#endif // __MEM_RUBY_COMMON_CONSUMER_HH__ 117