sensitivity.cc revision 13206:c944ef4abb48
1/* 2 * Copyright 2018 Google, Inc. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: redistributions of source code must retain the above copyright 7 * notice, this list of conditions and the following disclaimer; 8 * redistributions in binary form must reproduce the above copyright 9 * notice, this list of conditions and the following disclaimer in the 10 * documentation and/or other materials provided with the distribution; 11 * neither the name of the copyright holders nor the names of its 12 * contributors may be used to endorse or promote products derived from 13 * this software without specific prior written permission. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * 27 * Authors: Gabe Black 28 */ 29 30#include "systemc/core/sensitivity.hh" 31 32#include "systemc/core/event.hh" 33#include "systemc/core/scheduler.hh" 34#include "systemc/ext/core/sc_export.hh" 35#include "systemc/ext/core/sc_interface.hh" 36#include "systemc/ext/core/sc_port.hh" 37 38namespace sc_gem5 39{ 40 41void 42Sensitivity::satisfy() 43{ 44 process->satisfySensitivity(this); 45} 46 47bool 48Sensitivity::notify(Event *e) 49{ 50 if (process->disabled()) 51 return false; 52 return notifyWork(e); 53} 54 55 56void 57DynamicSensitivity::addToEvent(const ::sc_core::sc_event *e) 58{ 59 Event::getFromScEvent(e)->addSensitivity(this); 60} 61 62void 63DynamicSensitivity::delFromEvent(const ::sc_core::sc_event *e) 64{ 65 Event::getFromScEvent(e)->delSensitivity(this); 66} 67 68void 69StaticSensitivity::addToEvent(const ::sc_core::sc_event *e) 70{ 71 Event::getFromScEvent(e)->addSensitivity(this); 72} 73 74void 75StaticSensitivity::delFromEvent(const ::sc_core::sc_event *e) 76{ 77 Event::getFromScEvent(e)->delSensitivity(this); 78} 79 80void 81StaticSensitivityInterface::finalize() 82{ 83 event = &interface->default_event(); 84 SensitivityEvent::finalize(); 85} 86 87void 88StaticSensitivityPort::finalize() 89{ 90 for (int i = 0; i < port->size(); i++) { 91 const ::sc_core::sc_event *event = 92 &port->_gem5Interface(i)->default_event(); 93 events.insert(event); 94 addToEvent(event); 95 } 96} 97 98void 99StaticSensitivityExport::finalize() 100{ 101 event = &exp->get_interface()->default_event(); 102 SensitivityEvent::finalize(); 103} 104 105void 106StaticSensitivityFinder::finalize() 107{ 108 const ::sc_core::sc_port_base *port = finder->port(); 109 int size = port->size(); 110 for (int i = 0; i < size; i++) { 111 ::sc_core::sc_interface *interface = port->_gem5Interface(i); 112 const ::sc_core::sc_event *event = &finder->find_event(interface); 113 events.insert(event); 114 addToEvent(event); 115 } 116} 117 118bool 119DynamicSensitivityEventOrList::notifyWork(Event *e) 120{ 121 events.erase(e->sc_event()); 122 123 // All the other events need this deleted from their lists since this 124 // sensitivity has been satisfied without them triggering. 125 for (auto le: events) 126 delFromEvent(le); 127 128 satisfy(); 129 return true; 130} 131 132DynamicSensitivityEventOrList::DynamicSensitivityEventOrList( 133 Process *p, const sc_core::sc_event_or_list *eol) : 134 Sensitivity(p), DynamicSensitivity(p), events(eol->events) 135{} 136 137void 138DynamicSensitivityEventOrList::finalize() 139{ 140 for (auto e: events) 141 addToEvent(e); 142} 143 144void 145DynamicSensitivityEventOrList::clear() 146{ 147 for (auto e: events) 148 delFromEvent(e); 149} 150 151bool 152DynamicSensitivityEventAndList::notifyWork(Event *e) 153{ 154 events.erase(e->sc_event()); 155 156 // This sensitivity is satisfied if all events have triggered. 157 if (events.empty()) 158 satisfy(); 159 160 return true; 161} 162 163DynamicSensitivityEventAndList::DynamicSensitivityEventAndList( 164 Process *p, const sc_core::sc_event_and_list *eal) : 165 Sensitivity(p), DynamicSensitivity(p), events(eal->events) 166{} 167 168void 169DynamicSensitivityEventAndList::finalize() 170{ 171 for (auto e: events) 172 addToEvent(e); 173} 174 175void 176DynamicSensitivityEventAndList::clear() 177{ 178 for (auto e: events) 179 delFromEvent(e); 180} 181 182} // namespace sc_gem5 183