event.cc revision 12955
112955Sgabeblack@google.com/* 212955Sgabeblack@google.com * Copyright 2018 Google, Inc. 312955Sgabeblack@google.com * 412955Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 512955Sgabeblack@google.com * modification, are permitted provided that the following conditions are 612955Sgabeblack@google.com * met: redistributions of source code must retain the above copyright 712955Sgabeblack@google.com * notice, this list of conditions and the following disclaimer; 812955Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright 912955Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 1012955Sgabeblack@google.com * documentation and/or other materials provided with the distribution; 1112955Sgabeblack@google.com * neither the name of the copyright holders nor the names of its 1212955Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 1312955Sgabeblack@google.com * this software without specific prior written permission. 1412955Sgabeblack@google.com * 1512955Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1612955Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1712955Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1812955Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1912955Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2012955Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2112955Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2212955Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2312955Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2412955Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2512955Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2612955Sgabeblack@google.com * 2712955Sgabeblack@google.com * Authors: Gabe Black 2812955Sgabeblack@google.com */ 2912955Sgabeblack@google.com 3012955Sgabeblack@google.com#include "systemc/core/event.hh" 3112955Sgabeblack@google.com 3212955Sgabeblack@google.com#include <cstring> 3312955Sgabeblack@google.com#include <utility> 3412955Sgabeblack@google.com 3512955Sgabeblack@google.com#include "systemc/core/module.hh" 3612955Sgabeblack@google.com#include "systemc/core/scheduler.hh" 3712955Sgabeblack@google.com 3812955Sgabeblack@google.comnamespace sc_gem5 3912955Sgabeblack@google.com{ 4012955Sgabeblack@google.com 4112955Sgabeblack@google.comEvent::Event(sc_core::sc_event *_sc_event) : Event(_sc_event, "") {} 4212955Sgabeblack@google.com 4312955Sgabeblack@google.comEvent::Event(sc_core::sc_event *_sc_event, const char *_basename) : 4412955Sgabeblack@google.com _sc_event(_sc_event), _basename(_basename) 4512955Sgabeblack@google.com{ 4612955Sgabeblack@google.com Module *p = currentModule(); 4712955Sgabeblack@google.com 4812955Sgabeblack@google.com if (p) 4912955Sgabeblack@google.com parent = p->obj()->sc_obj(); 5012955Sgabeblack@google.com else if (scheduler.current()) 5112955Sgabeblack@google.com parent = scheduler.current(); 5212955Sgabeblack@google.com 5312955Sgabeblack@google.com if (parent) { 5412955Sgabeblack@google.com Object *obj = Object::getFromScObject(parent); 5512955Sgabeblack@google.com parentIt = obj->addChildEvent(_sc_event); 5612955Sgabeblack@google.com } else { 5712955Sgabeblack@google.com parentIt = topLevelEvents.emplace(topLevelEvents.end(), _sc_event); 5812955Sgabeblack@google.com } 5912955Sgabeblack@google.com 6012955Sgabeblack@google.com if (parent) 6112955Sgabeblack@google.com _name = std::string(parent->name()) + "." + _basename; 6212955Sgabeblack@google.com else 6312955Sgabeblack@google.com _name = _basename; 6412955Sgabeblack@google.com 6512955Sgabeblack@google.com allEvents.emplace(allEvents.end(), _sc_event); 6612955Sgabeblack@google.com 6712955Sgabeblack@google.com // Determine if we're in the hierarchy (created once initialization starts 6812955Sgabeblack@google.com // means no). 6912955Sgabeblack@google.com} 7012955Sgabeblack@google.com 7112955Sgabeblack@google.comEvent::~Event() 7212955Sgabeblack@google.com{ 7312955Sgabeblack@google.com if (parent) { 7412955Sgabeblack@google.com Object *obj = Object::getFromScObject(parent); 7512955Sgabeblack@google.com obj->delChildEvent(parentIt); 7612955Sgabeblack@google.com } else { 7712955Sgabeblack@google.com std::swap(*parentIt, topLevelEvents.back()); 7812955Sgabeblack@google.com topLevelEvents.pop_back(); 7912955Sgabeblack@google.com } 8012955Sgabeblack@google.com 8112955Sgabeblack@google.com EventsIt it = findEvent(_name); 8212955Sgabeblack@google.com std::swap(*it, allEvents.back()); 8312955Sgabeblack@google.com allEvents.pop_back(); 8412955Sgabeblack@google.com} 8512955Sgabeblack@google.com 8612955Sgabeblack@google.comconst std::string & 8712955Sgabeblack@google.comEvent::name() const 8812955Sgabeblack@google.com{ 8912955Sgabeblack@google.com return _name; 9012955Sgabeblack@google.com} 9112955Sgabeblack@google.com 9212955Sgabeblack@google.comconst std::string & 9312955Sgabeblack@google.comEvent::basename() const 9412955Sgabeblack@google.com{ 9512955Sgabeblack@google.com return _basename; 9612955Sgabeblack@google.com} 9712955Sgabeblack@google.com 9812955Sgabeblack@google.combool 9912955Sgabeblack@google.comEvent::inHierarchy() const 10012955Sgabeblack@google.com{ 10112955Sgabeblack@google.com return _name.length() != 0; 10212955Sgabeblack@google.com} 10312955Sgabeblack@google.com 10412955Sgabeblack@google.comsc_core::sc_object * 10512955Sgabeblack@google.comEvent::getParentObject() const 10612955Sgabeblack@google.com{ 10712955Sgabeblack@google.com return parent; 10812955Sgabeblack@google.com} 10912955Sgabeblack@google.com 11012955Sgabeblack@google.comvoid 11112955Sgabeblack@google.comEvent::notify() 11212955Sgabeblack@google.com{ 11312955Sgabeblack@google.com} 11412955Sgabeblack@google.com 11512955Sgabeblack@google.comvoid 11612955Sgabeblack@google.comEvent::notify(const sc_core::sc_time &t) 11712955Sgabeblack@google.com{ 11812955Sgabeblack@google.com} 11912955Sgabeblack@google.com 12012955Sgabeblack@google.comvoid 12112955Sgabeblack@google.comEvent::cancel() 12212955Sgabeblack@google.com{ 12312955Sgabeblack@google.com} 12412955Sgabeblack@google.com 12512955Sgabeblack@google.combool 12612955Sgabeblack@google.comEvent::triggered() const 12712955Sgabeblack@google.com{ 12812955Sgabeblack@google.com return false; 12912955Sgabeblack@google.com} 13012955Sgabeblack@google.com 13112955Sgabeblack@google.comEvents topLevelEvents; 13212955Sgabeblack@google.comEvents allEvents; 13312955Sgabeblack@google.com 13412955Sgabeblack@google.comEventsIt 13512955Sgabeblack@google.comfindEvent(const std::string &name) 13612955Sgabeblack@google.com{ 13712955Sgabeblack@google.com EventsIt it; 13812955Sgabeblack@google.com for (it = allEvents.begin(); it != allEvents.end(); it++) 13912955Sgabeblack@google.com if (!strcmp((*it)->name(), name.c_str())) 14012955Sgabeblack@google.com break; 14112955Sgabeblack@google.com 14212955Sgabeblack@google.com return it; 14312955Sgabeblack@google.com} 14412955Sgabeblack@google.com 14512955Sgabeblack@google.com} // namespace sc_gem5 146