sc_event.hh 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#ifndef __SYSTEMC_EXT_CORE_SC_EVENT_HH__
31#define __SYSTEMC_EXT_CORE_SC_EVENT_HH__
32
33#include <set>
34#include <vector>
35
36#include "sc_time.hh"
37
38namespace sc_gem5
39{
40
41class Event;
42
43}
44
45namespace sc_core
46{
47
48class sc_event;
49class sc_event_and_expr;
50class sc_event_or_expr;
51class sc_interface;
52class sc_object;
53class sc_port_base;
54
55class sc_event_finder
56{
57  protected:
58    void warn_unimpl(const char *func) const;
59
60  public:
61    // Should be "implementation defined" but used in the tests.
62    virtual const sc_event &find_event(sc_interface *if_p=NULL) const = 0;
63};
64
65template <class IF>
66class sc_event_finder_t : public sc_event_finder
67{
68  public:
69    sc_event_finder_t(const sc_port_base &,
70                      const sc_event & (IF::*event_method)() const)
71    {
72        warn_unimpl(__PRETTY_FUNCTION__);
73    }
74
75    const sc_event &
76    find_event(sc_interface *if_p=NULL) const override
77    {
78        warn_unimpl(__PRETTY_FUNCTION__);
79        return *(const sc_event *)nullptr;
80    }
81};
82
83class sc_event_and_list
84{
85  public:
86    sc_event_and_list();
87    sc_event_and_list(const sc_event_and_list &);
88    sc_event_and_list(const sc_event &);
89    sc_event_and_list &operator = (const sc_event_and_list &);
90    ~sc_event_and_list();
91
92    int size() const;
93    void swap(sc_event_and_list &);
94
95    sc_event_and_list &operator &= (const sc_event &);
96    sc_event_and_list &operator &= (const sc_event_and_list &);
97
98    sc_event_and_expr operator & (const sc_event &) const;
99    sc_event_and_expr operator & (const sc_event_and_list &);
100
101  private:
102    friend class sc_event_and_expr;
103
104    explicit sc_event_and_list(bool auto_delete);
105
106    void insert(sc_event const &e);
107    void insert(sc_event_and_list const &eal);
108
109    std::set<const sc_event *> events;
110    bool autoDelete;
111    mutable unsigned busy;
112};
113
114class sc_event_or_list
115{
116  public:
117    sc_event_or_list();
118    sc_event_or_list(const sc_event_or_list &);
119    sc_event_or_list(const sc_event &);
120    sc_event_or_list& operator = (const sc_event_or_list &);
121    ~sc_event_or_list();
122
123    int size() const;
124    void swap(sc_event_or_list &);
125
126    sc_event_or_list &operator |= (const sc_event &);
127    sc_event_or_list &operator |= (const sc_event_or_list &);
128
129    sc_event_or_expr operator | (const sc_event &) const;
130    sc_event_or_expr operator | (const sc_event_or_list &) const;
131
132  private:
133    friend class sc_event_or_expr;
134
135    explicit sc_event_or_list(bool auto_delete);
136
137    void insert(sc_event const &e);
138    void insert(sc_event_or_list const &eol);
139
140    std::set<const sc_event *> events;
141    bool autoDelete;
142    mutable unsigned busy;
143};
144
145class sc_event_and_expr
146{
147  public:
148    sc_event_and_expr(sc_event_and_expr const &e);
149    operator const sc_event_and_list &() const;
150
151    void insert(sc_event const &e) const;
152    void insert(sc_event_and_list const &eal) const;
153
154    ~sc_event_and_expr();
155
156  private:
157    friend class sc_event_and_list;
158    friend class sc_event;
159
160    sc_event_and_expr();
161    mutable sc_event_and_list *list;
162};
163
164sc_event_and_expr operator & (sc_event_and_expr, sc_event const &);
165sc_event_and_expr operator & (sc_event_and_expr, sc_event_and_list const &);
166
167class sc_event_or_expr
168{
169  public:
170    sc_event_or_expr(sc_event_or_expr const &e);
171    operator const sc_event_or_list &() const;
172
173    void insert(sc_event const &e) const;
174    void insert(sc_event_or_list const &eol) const;
175
176    ~sc_event_or_expr();
177
178  private:
179    friend class sc_event_or_list;
180    friend class sc_event;
181
182    sc_event_or_expr();
183    mutable sc_event_or_list *list;
184};
185
186sc_event_or_expr operator | (sc_event_or_expr, sc_event const &);
187sc_event_or_expr operator | (sc_event_or_expr, sc_event_or_list const &);
188
189class sc_event
190{
191  public:
192    sc_event();
193    explicit sc_event(const char *);
194    ~sc_event();
195
196    const char *name() const;
197    const char *basename() const;
198    bool in_hierarchy() const;
199    sc_object *get_parent_object() const;
200
201    void notify();
202    void notify(const sc_time &);
203    void notify(double, sc_time_unit);
204    void cancel();
205
206    // Nonstandard
207    // Returns whether this event is currently triggered.
208    bool triggered() const;
209
210    // Deprecated
211    void notify_delayed();
212    void notify_delayed(const sc_time &);
213
214    sc_event_and_expr operator & (const sc_event &) const;
215    sc_event_and_expr operator & (const sc_event_and_list &) const;
216    sc_event_or_expr operator | (const sc_event &) const;
217    sc_event_or_expr operator | (const sc_event_or_list &) const;
218
219  private:
220    // Disabled
221    sc_event(const sc_event &) {}
222    sc_event &operator = (const sc_event &) { return *this; }
223
224    friend class ::sc_gem5::Event;
225    ::sc_gem5::Event *_gem5_event;
226};
227
228const std::vector<sc_event *> &sc_get_top_level_events();
229sc_event *sc_find_event(const char *);
230
231} // namespace sc_core
232
233#endif  //__SYSTEMC_EXT_CORE_SC_INTERFACE_HH__
234