event.hh revision 13063
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 <set>
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/sched_event.hh"
41#include "systemc/ext/core/sc_prim.hh"
42#include "systemc/ext/core/sc_time.hh"
43
44namespace sc_core
45{
46
47class sc_event;
48
49} // namespace sc_core
50
51namespace sc_gem5
52{
53
54typedef std::vector<sc_core::sc_event *> Events;
55
56class Sensitivity;
57
58class Event
59{
60  public:
61    Event(sc_core::sc_event *_sc_event);
62    Event(sc_core::sc_event *_sc_event, const char *_basename);
63
64    ~Event();
65
66    sc_core::sc_event *sc_event() { return _sc_event; }
67
68    const std::string &name() const;
69    const std::string &basename() const;
70    bool inHierarchy() const;
71    sc_core::sc_object *getParentObject() const;
72
73    void notify();
74    void notify(const sc_core::sc_time &t);
75    void
76    notify(double d, sc_core::sc_time_unit &u)
77    {
78        notify(sc_core::sc_time(d, u));
79    }
80    void cancel();
81
82    bool triggered() const;
83
84    static Event *
85    getFromScEvent(sc_core::sc_event *e)
86    {
87        return e->_gem5_event;
88    }
89
90    static const Event *
91    getFromScEvent(const sc_core::sc_event *e)
92    {
93        return e->_gem5_event;
94    }
95
96    void addSensitivity(Sensitivity *s) const { sensitivities.insert(s); }
97    void delSensitivity(Sensitivity *s) const { sensitivities.erase(s); }
98
99  private:
100    sc_core::sc_event *_sc_event;
101
102    std::string _basename;
103    std::string _name;
104    bool _inHierarchy;
105
106    sc_core::sc_object *parent;
107
108    ScEvent delayedNotify;
109
110    mutable std::set<Sensitivity *> sensitivities;
111};
112
113extern Events topLevelEvents;
114extern Events allEvents;
115
116EventsIt findEvent(const std::string &name);
117
118} // namespace sc_gem5
119
120#endif  //__SYSTEMC_CORE_EVENT_HH__
121