event.hh revision 13260:4d18f1d20093
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#ifndef __SYSTEMC_CORE_EVENT_HH__
31#define __SYSTEMC_CORE_EVENT_HH__
32
33#include <list>
34#include <string>
35#include <vector>
36
37#include "sim/eventq.hh"
38#include "systemc/core/list.hh"
39#include "systemc/core/object.hh"
40#include "systemc/core/process.hh"
41#include "systemc/core/sched_event.hh"
42#include "systemc/core/sensitivity.hh"
43#include "systemc/ext/core/sc_prim.hh"
44#include "systemc/ext/core/sc_time.hh"
45
46namespace sc_core
47{
48
49class sc_event;
50
51} // namespace sc_core
52
53namespace sc_gem5
54{
55
56typedef std::vector<sc_core::sc_event *> Events;
57
58class Sensitivity;
59
60class Event
61{
62  public:
63    Event(sc_core::sc_event *_sc_event);
64    Event(sc_core::sc_event *_sc_event, const char *_basename);
65
66    ~Event();
67
68    sc_core::sc_event *sc_event() { return _sc_event; }
69
70    const std::string &name() const;
71    const std::string &basename() const;
72    bool inHierarchy() const;
73    sc_core::sc_object *getParentObject() const;
74
75    void notify(StaticSensitivities &senses);
76    void notify(DynamicSensitivities &senses);
77    void notify(ResetSensitivities &senses);
78
79    void notify();
80    void notify(const sc_core::sc_time &t);
81    void
82    notify(double d, sc_core::sc_time_unit &u)
83    {
84        notify(sc_core::sc_time(d, u));
85    }
86    void cancel();
87
88    bool triggered() const;
89    uint64_t triggeredStamp() const { return _triggeredStamp; }
90
91    static Event *
92    getFromScEvent(sc_core::sc_event *e)
93    {
94        return e->_gem5_event;
95    }
96
97    static const Event *
98    getFromScEvent(const sc_core::sc_event *e)
99    {
100        return e->_gem5_event;
101    }
102
103    void
104    addSensitivity(StaticSensitivity *s) const
105    {
106        // Insert static sensitivities in reverse order to match Accellera's
107        // implementation.
108        auto &senses = s->ofMethod() ? staticSenseMethod : staticSenseThread;
109        senses.insert(senses.begin(), s);
110    }
111    void
112    delSensitivity(StaticSensitivity *s) const
113    {
114        auto &senses = s->ofMethod() ? staticSenseMethod : staticSenseThread;
115        for (auto &t: senses) {
116            if (t == s) {
117                t = senses.back();
118                senses.pop_back();
119                break;
120            }
121        }
122    }
123    void
124    addSensitivity(DynamicSensitivity *s) const
125    {
126        auto &senses = s->ofMethod() ? dynamicSenseMethod : dynamicSenseThread;
127        senses.push_back(s);
128    }
129    void
130    delSensitivity(DynamicSensitivity *s) const
131    {
132        auto &senses = s->ofMethod() ? dynamicSenseMethod : dynamicSenseThread;
133        for (auto &t: senses) {
134            if (t == s) {
135                t = senses.back();
136                senses.pop_back();
137                break;
138            }
139        }
140    }
141    void
142    addSensitivity(ResetSensitivity *s) const
143    {
144        resetSense.push_back(s);
145    }
146    void
147    delSensitivity(ResetSensitivity *s) const
148    {
149        for (auto &t: resetSense) {
150            if (t == s) {
151                t = resetSense.back();
152                resetSense.pop_back();
153                break;
154            }
155        }
156    }
157
158  private:
159    sc_core::sc_event *_sc_event;
160
161    std::string _basename;
162    std::string _name;
163    bool _inHierarchy;
164
165    sc_core::sc_object *parent;
166
167    ScEvent delayedNotify;
168    mutable uint64_t _triggeredStamp;
169
170    mutable StaticSensitivities staticSenseMethod;
171    mutable StaticSensitivities staticSenseThread;
172    mutable DynamicSensitivities dynamicSenseMethod;
173    mutable DynamicSensitivities dynamicSenseThread;
174    mutable ResetSensitivities resetSense;
175};
176
177extern Events topLevelEvents;
178extern Events allEvents;
179
180EventsIt findEvent(const std::string &name);
181
182} // namespace sc_gem5
183
184#endif  //__SYSTEMC_CORE_EVENT_HH__
185