event.hh revision 13299
14776Sgblack@eecs.umich.edu/* 24776Sgblack@eecs.umich.edu * Copyright 2018 Google, Inc. 34776Sgblack@eecs.umich.edu * 44776Sgblack@eecs.umich.edu * Redistribution and use in source and binary forms, with or without 54776Sgblack@eecs.umich.edu * modification, are permitted provided that the following conditions are 64776Sgblack@eecs.umich.edu * met: redistributions of source code must retain the above copyright 74776Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer; 84776Sgblack@eecs.umich.edu * redistributions in binary form must reproduce the above copyright 94776Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the 104776Sgblack@eecs.umich.edu * documentation and/or other materials provided with the distribution; 114776Sgblack@eecs.umich.edu * neither the name of the copyright holders nor the names of its 124776Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived from 134776Sgblack@eecs.umich.edu * this software without specific prior written permission. 144776Sgblack@eecs.umich.edu * 154776Sgblack@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 164776Sgblack@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 174776Sgblack@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 184776Sgblack@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 194776Sgblack@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 204776Sgblack@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 214776Sgblack@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 224776Sgblack@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 234776Sgblack@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 244776Sgblack@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 254776Sgblack@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 264776Sgblack@eecs.umich.edu * 274776Sgblack@eecs.umich.edu * Authors: Gabe Black 284776Sgblack@eecs.umich.edu */ 294776Sgblack@eecs.umich.edu 304776Sgblack@eecs.umich.edu#ifndef __SYSTEMC_CORE_EVENT_HH__ 314776Sgblack@eecs.umich.edu#define __SYSTEMC_CORE_EVENT_HH__ 324776Sgblack@eecs.umich.edu 334776Sgblack@eecs.umich.edu#include <list> 344776Sgblack@eecs.umich.edu#include <string> 354776Sgblack@eecs.umich.edu#include <vector> 366658Snate@binkert.org 374776Sgblack@eecs.umich.edu#include "sim/eventq.hh" 384776Sgblack@eecs.umich.edu#include "systemc/core/list.hh" 394776Sgblack@eecs.umich.edu#include "systemc/core/object.hh" 404776Sgblack@eecs.umich.edu#include "systemc/core/process.hh" 414776Sgblack@eecs.umich.edu#include "systemc/core/sched_event.hh" 424776Sgblack@eecs.umich.edu#include "systemc/core/sensitivity.hh" 434776Sgblack@eecs.umich.edu#include "systemc/ext/core/sc_prim.hh" 444776Sgblack@eecs.umich.edu#include "systemc/ext/core/sc_time.hh" 454776Sgblack@eecs.umich.edu 464776Sgblack@eecs.umich.edunamespace sc_core 474776Sgblack@eecs.umich.edu{ 484776Sgblack@eecs.umich.edu 494776Sgblack@eecs.umich.educlass sc_event; 504776Sgblack@eecs.umich.edu 517720Sgblack@eecs.umich.edu} // namespace sc_core 524776Sgblack@eecs.umich.edu 534776Sgblack@eecs.umich.edunamespace sc_gem5 544776Sgblack@eecs.umich.edu{ 554776Sgblack@eecs.umich.edu 564776Sgblack@eecs.umich.edutypedef std::vector<sc_core::sc_event *> Events; 574776Sgblack@eecs.umich.edu 584776Sgblack@eecs.umich.educlass Sensitivity; 594776Sgblack@eecs.umich.edu 607811Ssteve.reinhardt@amd.comclass Event 614776Sgblack@eecs.umich.edu{ 624776Sgblack@eecs.umich.edu public: 634776Sgblack@eecs.umich.edu Event(sc_core::sc_event *_sc_event); 644776Sgblack@eecs.umich.edu Event(sc_core::sc_event *_sc_event, const char *_basename); 654776Sgblack@eecs.umich.edu 664776Sgblack@eecs.umich.edu ~Event(); 674776Sgblack@eecs.umich.edu 684776Sgblack@eecs.umich.edu sc_core::sc_event *sc_event() { return _sc_event; } 695034Smilesck@eecs.umich.edu 708902Sandreas.hansson@arm.com const std::string &name() const; 71 const std::string &basename() const; 72 bool inHierarchy() const; 73 sc_core::sc_object *getParentObject() const; 74 75 void notify(StaticSensitivities &senses); 76 void notify(DynamicSensitivities &senses); 77 78 void notify(); 79 void notify(const sc_core::sc_time &t); 80 void 81 notify(double d, sc_core::sc_time_unit &u) 82 { 83 notify(sc_core::sc_time(d, u)); 84 } 85 void notifyDelayed(const sc_core::sc_time &t); 86 void cancel(); 87 88 bool triggered() const; 89 uint64_t triggeredStamp() const { return _triggeredStamp; } 90 91 static Event * 92 getFromScEvent(sc_core::sc_event *e) 93 { 94 return e->_gem5_event; 95 } 96 97 static const Event * 98 getFromScEvent(const sc_core::sc_event *e) 99 { 100 return e->_gem5_event; 101 } 102 103 void 104 addSensitivity(StaticSensitivity *s) const 105 { 106 // Insert static sensitivities in reverse order to match Accellera's 107 // implementation. 108 auto &senses = s->ofMethod() ? staticSenseMethod : staticSenseThread; 109 senses.insert(senses.begin(), s); 110 } 111 void 112 delSensitivity(StaticSensitivity *s) const 113 { 114 auto &senses = s->ofMethod() ? staticSenseMethod : staticSenseThread; 115 for (auto &t: senses) { 116 if (t == s) { 117 t = senses.back(); 118 senses.pop_back(); 119 break; 120 } 121 } 122 } 123 void 124 addSensitivity(DynamicSensitivity *s) const 125 { 126 auto &senses = s->ofMethod() ? dynamicSenseMethod : dynamicSenseThread; 127 senses.push_back(s); 128 } 129 void 130 delSensitivity(DynamicSensitivity *s) const 131 { 132 auto &senses = s->ofMethod() ? dynamicSenseMethod : dynamicSenseThread; 133 for (auto &t: senses) { 134 if (t == s) { 135 t = senses.back(); 136 senses.pop_back(); 137 break; 138 } 139 } 140 } 141 142 void clearParent(); 143 144 private: 145 sc_core::sc_event *_sc_event; 146 147 std::string _basename; 148 std::string _name; 149 bool _inHierarchy; 150 151 sc_core::sc_object *parent; 152 153 ScEvent delayedNotify; 154 mutable uint64_t _triggeredStamp; 155 156 mutable StaticSensitivities staticSenseMethod; 157 mutable StaticSensitivities staticSenseThread; 158 mutable DynamicSensitivities dynamicSenseMethod; 159 mutable DynamicSensitivities dynamicSenseThread; 160}; 161 162extern Events topLevelEvents; 163extern Events allEvents; 164 165EventsIt findEvent(const std::string &name); 166 167} // namespace sc_gem5 168 169#endif //__SYSTEMC_CORE_EVENT_HH__ 170