event.cc (13299:6bde86615f6f) | event.cc (13303:045f002c325c) |
---|---|
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 --- 29 unchanged lines hidden (view full) --- 38#include "systemc/core/module.hh" 39#include "systemc/core/scheduler.hh" 40#include "systemc/ext/core/sc_main.hh" 41#include "systemc/ext/core/sc_module.hh" 42 43namespace sc_gem5 44{ 45 | 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 --- 29 unchanged lines hidden (view full) --- 38#include "systemc/core/module.hh" 39#include "systemc/core/scheduler.hh" 40#include "systemc/ext/core/sc_main.hh" 41#include "systemc/ext/core/sc_module.hh" 42 43namespace sc_gem5 44{ 45 |
46Event::Event(sc_core::sc_event *_sc_event) : Event(_sc_event, nullptr) {} | 46Event::Event(sc_core::sc_event *_sc_event, bool internal) : 47 Event(_sc_event, nullptr, internal) 48{} |
47 | 49 |
48Event::Event(sc_core::sc_event *_sc_event, const char *_basename_cstr) : | 50Event::Event(sc_core::sc_event *_sc_event, const char *_basename_cstr, 51 bool internal) : |
49 _sc_event(_sc_event), _basename(_basename_cstr ? _basename_cstr : ""), | 52 _sc_event(_sc_event), _basename(_basename_cstr ? _basename_cstr : ""), |
50 delayedNotify([this]() { this->notify(); }), _triggeredStamp(~0ULL) | 53 _inHierarchy(!internal), delayedNotify([this]() { this->notify(); }), 54 _triggeredStamp(~0ULL) |
51{ 52 if (_basename == "" && ::sc_core::sc_is_running()) 53 _basename = ::sc_core::sc_gen_unique_name("event"); 54 | 55{ 56 if (_basename == "" && ::sc_core::sc_is_running()) 57 _basename = ::sc_core::sc_gen_unique_name("event"); 58 |
55 parent = pickParentObj(); | 59 parent = internal ? nullptr : pickParentObj(); |
56 | 60 |
57 std::string original_name = _basename; 58 _basename = pickUniqueName(parent, _basename); 59 60 if (parent) { 61 Object *obj = Object::getFromScObject(parent); 62 obj->addChildEvent(_sc_event); | 61 if (internal) { 62 _basename = globalNameGen.gen(_basename); 63 _name = _basename; |
63 } else { | 64 } else { |
64 topLevelEvents.emplace(topLevelEvents.end(), _sc_event); 65 } | 65 std::string original_name = _basename; 66 _basename = pickUniqueName(parent, _basename); |
66 | 67 |
67 std::string path = parent ? (std::string(parent->name()) + ".") : ""; | 68 if (parent) { 69 Object *obj = Object::getFromScObject(parent); 70 obj->addChildEvent(_sc_event); 71 } else { 72 topLevelEvents.emplace(topLevelEvents.end(), _sc_event); 73 } |
68 | 74 |
69 if (original_name != "" && _basename != original_name) { 70 std::string message = path + original_name + 71 ". Latter declaration will be renamed to " + 72 path + _basename; 73 SC_REPORT_WARNING("(W505) object already exists", message.c_str()); 74 } | 75 std::string path = parent ? (std::string(parent->name()) + ".") : ""; |
75 | 76 |
76 _name = path + _basename; | 77 if (original_name != "" && _basename != original_name) { 78 std::string message = path + original_name + 79 ". Latter declaration will be renamed to " + 80 path + _basename; 81 SC_REPORT_WARNING("(W505) object already exists", message.c_str()); 82 } |
77 | 83 |
84 _name = path + _basename; 85 } 86 |
|
78 allEvents.emplace(allEvents.end(), _sc_event); 79 80 // Determine if we're in the hierarchy (created once initialization starts 81 // means no). 82} 83 84Event::~Event() 85{ 86 if (parent) { 87 Object *obj = Object::getFromScObject(parent); 88 obj->delChildEvent(_sc_event); | 87 allEvents.emplace(allEvents.end(), _sc_event); 88 89 // Determine if we're in the hierarchy (created once initialization starts 90 // means no). 91} 92 93Event::~Event() 94{ 95 if (parent) { 96 Object *obj = Object::getFromScObject(parent); 97 obj->delChildEvent(_sc_event); |
89 } else { | 98 } else if (inHierarchy()) { |
90 EventsIt it = find(topLevelEvents.begin(), topLevelEvents.end(), 91 _sc_event); 92 assert(it != topLevelEvents.end()); 93 std::swap(*it, topLevelEvents.back()); 94 topLevelEvents.pop_back(); 95 } 96 97 EventsIt it = findEvent(_name); --- 14 unchanged lines hidden (view full) --- 112Event::basename() const 113{ 114 return _basename; 115} 116 117bool 118Event::inHierarchy() const 119{ | 99 EventsIt it = find(topLevelEvents.begin(), topLevelEvents.end(), 100 _sc_event); 101 assert(it != topLevelEvents.end()); 102 std::swap(*it, topLevelEvents.back()); 103 topLevelEvents.pop_back(); 104 } 105 106 EventsIt it = findEvent(_name); --- 14 unchanged lines hidden (view full) --- 121Event::basename() const 122{ 123 return _basename; 124} 125 126bool 127Event::inHierarchy() const 128{ |
120 return _name.length() != 0; | 129 return _inHierarchy; |
121} 122 123sc_core::sc_object * 124Event::getParentObject() const 125{ 126 return parent; 127} 128 --- 100 unchanged lines hidden --- | 130} 131 132sc_core::sc_object * 133Event::getParentObject() const 134{ 135 return parent; 136} 137 --- 100 unchanged lines hidden --- |