TimerTable.hh revision 11111
16145SN/A/* 26145SN/A * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 36145SN/A * 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 2910441Snilay@cs.wisc.edu#ifndef __MEM_RUBY_STRUCTURES_TIMERTABLE_HH__ 3010441Snilay@cs.wisc.edu#define __MEM_RUBY_STRUCTURES_TIMERTABLE_HH__ 316145SN/A 327039SN/A#include <cassert> 337055SN/A#include <iostream> 349171SN/A#include <map> 357055SN/A#include <string> 366145SN/A 376154SN/A#include "mem/ruby/common/Address.hh" 389171SN/A#include "mem/ruby/common/Consumer.hh" 396145SN/A 407039SN/Aclass TimerTable 417039SN/A{ 427039SN/A public: 437039SN/A TimerTable(); 446145SN/A 457039SN/A void 467039SN/A setConsumer(Consumer* consumer_ptr) 477039SN/A { 487039SN/A assert(m_consumer_ptr == NULL); 497039SN/A m_consumer_ptr = consumer_ptr; 507039SN/A } 516145SN/A 527039SN/A void 537055SN/A setDescription(const std::string& name) 547039SN/A { 557039SN/A m_name = name; 567039SN/A } 576145SN/A 5811111Snilay@cs.wisc.edu bool isReady(Tick curTime) const; 5911111Snilay@cs.wisc.edu Addr nextAddress() const; 6011025Snilay@cs.wisc.edu bool isSet(Addr address) const { return !!m_map.count(address); } 6111111Snilay@cs.wisc.edu void set(Addr address, Tick ready_time); 6211025Snilay@cs.wisc.edu void unset(Addr address); 637055SN/A void print(std::ostream& out) const; 646145SN/A 657039SN/A private: 667039SN/A void updateNext() const; 676145SN/A 687039SN/A // Private copy constructor and assignment operator 697039SN/A TimerTable(const TimerTable& obj); 707039SN/A TimerTable& operator=(const TimerTable& obj); 716145SN/A 727039SN/A // Data Members (m_prefix) 738943SN/A 748943SN/A // use a std::map for the address map as this container is sorted 758943SN/A // and ensures a well-defined iteration order 7611111Snilay@cs.wisc.edu typedef std::map<Addr, Tick> AddressMap; 777455SN/A AddressMap m_map; 787039SN/A mutable bool m_next_valid; 7911111Snilay@cs.wisc.edu mutable Tick m_next_time; // Only valid if m_next_valid is true 8011025Snilay@cs.wisc.edu mutable Addr m_next_address; // Only valid if m_next_valid is true 819465SN/A 829465SN/A //! Consumer to signal a wakeup() 839465SN/A Consumer* m_consumer_ptr; 849465SN/A 857055SN/A std::string m_name; 866145SN/A}; 876145SN/A 887055SN/Ainline std::ostream& 897055SN/Aoperator<<(std::ostream& out, const TimerTable& obj) 906145SN/A{ 917039SN/A obj.print(out); 927055SN/A out << std::flush; 937039SN/A return out; 946145SN/A} 957039SN/A 9610441Snilay@cs.wisc.edu#endif // __MEM_RUBY_STRUCTURES_TIMERTABLE_HH__ 97