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