event.cc revision 12955:9c8bf6a5f2e3
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/event.hh"
31
32#include <cstring>
33#include <utility>
34
35#include "systemc/core/module.hh"
36#include "systemc/core/scheduler.hh"
37
38namespace sc_gem5
39{
40
41Event::Event(sc_core::sc_event *_sc_event) : Event(_sc_event, "") {}
42
43Event::Event(sc_core::sc_event *_sc_event, const char *_basename) :
44    _sc_event(_sc_event), _basename(_basename)
45{
46    Module *p = currentModule();
47
48    if (p)
49        parent = p->obj()->sc_obj();
50    else if (scheduler.current())
51        parent = scheduler.current();
52
53    if (parent) {
54        Object *obj = Object::getFromScObject(parent);
55        parentIt = obj->addChildEvent(_sc_event);
56    } else {
57        parentIt = topLevelEvents.emplace(topLevelEvents.end(), _sc_event);
58    }
59
60    if (parent)
61        _name = std::string(parent->name()) + "." + _basename;
62    else
63        _name = _basename;
64
65    allEvents.emplace(allEvents.end(), _sc_event);
66
67    // Determine if we're in the hierarchy (created once initialization starts
68    // means no).
69}
70
71Event::~Event()
72{
73    if (parent) {
74        Object *obj = Object::getFromScObject(parent);
75        obj->delChildEvent(parentIt);
76    } else {
77        std::swap(*parentIt, topLevelEvents.back());
78        topLevelEvents.pop_back();
79    }
80
81    EventsIt it = findEvent(_name);
82    std::swap(*it, allEvents.back());
83    allEvents.pop_back();
84}
85
86const std::string &
87Event::name() const
88{
89    return _name;
90}
91
92const std::string &
93Event::basename() const
94{
95    return _basename;
96}
97
98bool
99Event::inHierarchy() const
100{
101    return _name.length() != 0;
102}
103
104sc_core::sc_object *
105Event::getParentObject() const
106{
107    return parent;
108}
109
110void
111Event::notify()
112{
113}
114
115void
116Event::notify(const sc_core::sc_time &t)
117{
118}
119
120void
121Event::cancel()
122{
123}
124
125bool
126Event::triggered() const
127{
128    return false;
129}
130
131Events topLevelEvents;
132Events allEvents;
133
134EventsIt
135findEvent(const std::string &name)
136{
137    EventsIt it;
138    for (it = allEvents.begin(); it != allEvents.end(); it++)
139        if (!strcmp((*it)->name(), name.c_str()))
140            break;
141
142    return it;
143}
144
145} // namespace sc_gem5
146