event.cc revision 13086
112027Sjungma@eit.uni-kl.de/* 212027Sjungma@eit.uni-kl.de * Copyright 2018 Google, Inc. 312027Sjungma@eit.uni-kl.de * 412027Sjungma@eit.uni-kl.de * Redistribution and use in source and binary forms, with or without 512027Sjungma@eit.uni-kl.de * modification, are permitted provided that the following conditions are 612027Sjungma@eit.uni-kl.de * met: redistributions of source code must retain the above copyright 712027Sjungma@eit.uni-kl.de * notice, this list of conditions and the following disclaimer; 812027Sjungma@eit.uni-kl.de * redistributions in binary form must reproduce the above copyright 912027Sjungma@eit.uni-kl.de * notice, this list of conditions and the following disclaimer in the 1012027Sjungma@eit.uni-kl.de * documentation and/or other materials provided with the distribution; 1112027Sjungma@eit.uni-kl.de * neither the name of the copyright holders nor the names of its 1212027Sjungma@eit.uni-kl.de * contributors may be used to endorse or promote products derived from 1312027Sjungma@eit.uni-kl.de * this software without specific prior written permission. 1412027Sjungma@eit.uni-kl.de * 1512027Sjungma@eit.uni-kl.de * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1612027Sjungma@eit.uni-kl.de * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1712027Sjungma@eit.uni-kl.de * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1812027Sjungma@eit.uni-kl.de * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1912027Sjungma@eit.uni-kl.de * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2012027Sjungma@eit.uni-kl.de * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2112027Sjungma@eit.uni-kl.de * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2212027Sjungma@eit.uni-kl.de * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2312027Sjungma@eit.uni-kl.de * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2412027Sjungma@eit.uni-kl.de * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2512027Sjungma@eit.uni-kl.de * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2612027Sjungma@eit.uni-kl.de * 2712027Sjungma@eit.uni-kl.de * Authors: Gabe Black 2812027Sjungma@eit.uni-kl.de */ 2912027Sjungma@eit.uni-kl.de 3012027Sjungma@eit.uni-kl.de#include "systemc/core/event.hh" 3112027Sjungma@eit.uni-kl.de 3212027Sjungma@eit.uni-kl.de#include <algorithm> 3312027Sjungma@eit.uni-kl.de#include <cstring> 3412027Sjungma@eit.uni-kl.de#include <utility> 3512027Sjungma@eit.uni-kl.de 3612027Sjungma@eit.uni-kl.de#include "base/logging.hh" 3712027Sjungma@eit.uni-kl.de#include "sim/core.hh" 3812027Sjungma@eit.uni-kl.de#include "systemc/core/module.hh" 3912027Sjungma@eit.uni-kl.de#include "systemc/core/scheduler.hh" 4012027Sjungma@eit.uni-kl.de#include "systemc/ext/core/sc_main.hh" 4112027Sjungma@eit.uni-kl.de#include "systemc/ext/core/sc_module.hh" 4212027Sjungma@eit.uni-kl.de 4312027Sjungma@eit.uni-kl.denamespace sc_gem5 4412027Sjungma@eit.uni-kl.de{ 4512027Sjungma@eit.uni-kl.de 4612027Sjungma@eit.uni-kl.deEvent::Event(sc_core::sc_event *_sc_event) : Event(_sc_event, nullptr) {} 4712027Sjungma@eit.uni-kl.de 4812027Sjungma@eit.uni-kl.deEvent::Event(sc_core::sc_event *_sc_event, const char *_basename_cstr) : 4912027Sjungma@eit.uni-kl.de _sc_event(_sc_event), _basename(_basename_cstr ? _basename_cstr : ""), 5012027Sjungma@eit.uni-kl.de delayedNotify([this]() { this->notify(); }) 5112027Sjungma@eit.uni-kl.de{ 5212027Sjungma@eit.uni-kl.de Module *p = currentModule(); 5312027Sjungma@eit.uni-kl.de 5412027Sjungma@eit.uni-kl.de if (_basename == "" && ::sc_core::sc_is_running()) 5512027Sjungma@eit.uni-kl.de _basename = ::sc_core::sc_gen_unique_name("event"); 5612027Sjungma@eit.uni-kl.de 5712027Sjungma@eit.uni-kl.de if (p) 5812027Sjungma@eit.uni-kl.de parent = p->obj()->sc_obj(); 5912027Sjungma@eit.uni-kl.de else if (scheduler.current()) 6012027Sjungma@eit.uni-kl.de parent = scheduler.current(); 6112027Sjungma@eit.uni-kl.de else 6212027Sjungma@eit.uni-kl.de parent = nullptr; 6312027Sjungma@eit.uni-kl.de 6412027Sjungma@eit.uni-kl.de if (parent) { 6512027Sjungma@eit.uni-kl.de Object *obj = Object::getFromScObject(parent); 6612027Sjungma@eit.uni-kl.de obj->addChildEvent(_sc_event); 6712027Sjungma@eit.uni-kl.de } else { 6812027Sjungma@eit.uni-kl.de topLevelEvents.emplace(topLevelEvents.end(), _sc_event); 6912027Sjungma@eit.uni-kl.de } 7012027Sjungma@eit.uni-kl.de 7112027Sjungma@eit.uni-kl.de if (parent) 7212027Sjungma@eit.uni-kl.de _name = std::string(parent->name()) + "." + _basename; 7312027Sjungma@eit.uni-kl.de else 7412027Sjungma@eit.uni-kl.de _name = _basename; 7512027Sjungma@eit.uni-kl.de 7612027Sjungma@eit.uni-kl.de allEvents.emplace(allEvents.end(), _sc_event); 7712027Sjungma@eit.uni-kl.de 7812027Sjungma@eit.uni-kl.de // Determine if we're in the hierarchy (created once initialization starts 7912027Sjungma@eit.uni-kl.de // means no). 8012027Sjungma@eit.uni-kl.de} 8112027Sjungma@eit.uni-kl.de 8212027Sjungma@eit.uni-kl.deEvent::~Event() 8312027Sjungma@eit.uni-kl.de{ 8412027Sjungma@eit.uni-kl.de if (parent) { 8512027Sjungma@eit.uni-kl.de Object *obj = Object::getFromScObject(parent); 8612027Sjungma@eit.uni-kl.de obj->delChildEvent(_sc_event); 8712027Sjungma@eit.uni-kl.de } else { 8812027Sjungma@eit.uni-kl.de EventsIt it = find(topLevelEvents.begin(), topLevelEvents.end(), 8912027Sjungma@eit.uni-kl.de _sc_event); 9012027Sjungma@eit.uni-kl.de assert(it != topLevelEvents.end()); 9112027Sjungma@eit.uni-kl.de std::swap(*it, topLevelEvents.back()); 9212027Sjungma@eit.uni-kl.de topLevelEvents.pop_back(); 9312027Sjungma@eit.uni-kl.de } 9412027Sjungma@eit.uni-kl.de 9512027Sjungma@eit.uni-kl.de EventsIt it = findEvent(_name); 9612027Sjungma@eit.uni-kl.de std::swap(*it, allEvents.back()); 9712027Sjungma@eit.uni-kl.de allEvents.pop_back(); 9812027Sjungma@eit.uni-kl.de 9912027Sjungma@eit.uni-kl.de if (delayedNotify.scheduled()) 10012027Sjungma@eit.uni-kl.de scheduler.deschedule(&delayedNotify); 10112027Sjungma@eit.uni-kl.de} 10212027Sjungma@eit.uni-kl.de 10312027Sjungma@eit.uni-kl.deconst std::string & 10412027Sjungma@eit.uni-kl.deEvent::name() const 10512027Sjungma@eit.uni-kl.de{ 10612027Sjungma@eit.uni-kl.de return _name; 10712027Sjungma@eit.uni-kl.de} 10812027Sjungma@eit.uni-kl.de 10912027Sjungma@eit.uni-kl.deconst std::string & 11012027Sjungma@eit.uni-kl.deEvent::basename() const 11112027Sjungma@eit.uni-kl.de{ 11212027Sjungma@eit.uni-kl.de return _basename; 11312027Sjungma@eit.uni-kl.de} 11412027Sjungma@eit.uni-kl.de 11512027Sjungma@eit.uni-kl.debool 11612027Sjungma@eit.uni-kl.deEvent::inHierarchy() const 11712027Sjungma@eit.uni-kl.de{ 11812027Sjungma@eit.uni-kl.de return _name.length() != 0; 11912027Sjungma@eit.uni-kl.de} 12012027Sjungma@eit.uni-kl.de 12112027Sjungma@eit.uni-kl.desc_core::sc_object * 12212027Sjungma@eit.uni-kl.deEvent::getParentObject() const 12312027Sjungma@eit.uni-kl.de{ 12412027Sjungma@eit.uni-kl.de return parent; 12512027Sjungma@eit.uni-kl.de} 12612027Sjungma@eit.uni-kl.de 12712027Sjungma@eit.uni-kl.devoid 12812027Sjungma@eit.uni-kl.deEvent::notify() 12912027Sjungma@eit.uni-kl.de{ 13012027Sjungma@eit.uni-kl.de // An immediate notification overrides any pending delayed notification. 13112027Sjungma@eit.uni-kl.de if (delayedNotify.scheduled()) 13212027Sjungma@eit.uni-kl.de scheduler.deschedule(&delayedNotify); 13312027Sjungma@eit.uni-kl.de 13412027Sjungma@eit.uni-kl.de auto local_sensitivities = sensitivities; 13512027Sjungma@eit.uni-kl.de for (auto s: local_sensitivities) 13612027Sjungma@eit.uni-kl.de s->notify(this); 13712027Sjungma@eit.uni-kl.de} 13812027Sjungma@eit.uni-kl.de 13912027Sjungma@eit.uni-kl.devoid 14012027Sjungma@eit.uni-kl.deEvent::notify(const sc_core::sc_time &t) 14112027Sjungma@eit.uni-kl.de{ 14212027Sjungma@eit.uni-kl.de if (delayedNotify.scheduled()) { 14312027Sjungma@eit.uni-kl.de if (scheduler.delayed(t) >= delayedNotify.when()) 14412027Sjungma@eit.uni-kl.de return; 14512027Sjungma@eit.uni-kl.de 14612027Sjungma@eit.uni-kl.de scheduler.deschedule(&delayedNotify); 14712027Sjungma@eit.uni-kl.de } 14812027Sjungma@eit.uni-kl.de scheduler.schedule(&delayedNotify, t); 14912027Sjungma@eit.uni-kl.de} 15012027Sjungma@eit.uni-kl.de 15112027Sjungma@eit.uni-kl.devoid 15212027Sjungma@eit.uni-kl.deEvent::cancel() 15312027Sjungma@eit.uni-kl.de{ 15412027Sjungma@eit.uni-kl.de if (delayedNotify.scheduled()) 15512027Sjungma@eit.uni-kl.de scheduler.deschedule(&delayedNotify); 15612027Sjungma@eit.uni-kl.de} 15712027Sjungma@eit.uni-kl.de 15812027Sjungma@eit.uni-kl.debool 15912027Sjungma@eit.uni-kl.deEvent::triggered() const 16012027Sjungma@eit.uni-kl.de{ 16112027Sjungma@eit.uni-kl.de return false; 16212027Sjungma@eit.uni-kl.de} 16312027Sjungma@eit.uni-kl.de 16412027Sjungma@eit.uni-kl.deEvents topLevelEvents; 16512027Sjungma@eit.uni-kl.deEvents allEvents; 16612027Sjungma@eit.uni-kl.de 16712027Sjungma@eit.uni-kl.deEventsIt 16812027Sjungma@eit.uni-kl.defindEvent(const std::string &name) 16912027Sjungma@eit.uni-kl.de{ 17012027Sjungma@eit.uni-kl.de EventsIt it; 17112027Sjungma@eit.uni-kl.de for (it = allEvents.begin(); it != allEvents.end(); it++) 17212027Sjungma@eit.uni-kl.de if (!strcmp((*it)->name(), name.c_str())) 17312027Sjungma@eit.uni-kl.de break; 17412027Sjungma@eit.uni-kl.de 17512027Sjungma@eit.uni-kl.de return it; 17612027Sjungma@eit.uni-kl.de} 17712027Sjungma@eit.uni-kl.de 17812027Sjungma@eit.uni-kl.de} // namespace sc_gem5 17912027Sjungma@eit.uni-kl.de