sc_event.hh revision 13206
12207SN/A/*
22207SN/A * Copyright 2018 Google, Inc.
32207SN/A *
42207SN/A * Redistribution and use in source and binary forms, with or without
52207SN/A * modification, are permitted provided that the following conditions are
62207SN/A * met: redistributions of source code must retain the above copyright
72207SN/A * notice, this list of conditions and the following disclaimer;
82207SN/A * redistributions in binary form must reproduce the above copyright
92207SN/A * notice, this list of conditions and the following disclaimer in the
102207SN/A * documentation and/or other materials provided with the distribution;
112207SN/A * neither the name of the copyright holders nor the names of its
122207SN/A * contributors may be used to endorse or promote products derived from
132207SN/A * this software without specific prior written permission.
142207SN/A *
152207SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
162207SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
172207SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
182207SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
192207SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
202207SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
212207SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
222207SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
232207SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
242207SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
252207SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
262207SN/A *
272665Ssaidi@eecs.umich.edu * Authors: Gabe Black
282665Ssaidi@eecs.umich.edu */
292665Ssaidi@eecs.umich.edu
302207SN/A#ifndef __SYSTEMC_EXT_CORE_SC_EVENT_HH__
312207SN/A#define __SYSTEMC_EXT_CORE_SC_EVENT_HH__
322207SN/A
332207SN/A#include <cassert>
342207SN/A#include <set>
352454SN/A#include <vector>
362454SN/A
378229Snate@binkert.org#include "sc_port.hh"
385285Sgblack@eecs.umich.edu#include "sc_time.hh"
392474SN/A
402454SN/Anamespace sc_gem5
412454SN/A{
422454SN/A
432207SN/Aclass Event;
442474SN/Aclass DynamicSensitivityEventAndList;
452207SN/Aclass DynamicSensitivityEventOrList;
462474SN/A
472561SN/A}
485285Sgblack@eecs.umich.edu
495285Sgblack@eecs.umich.edunamespace sc_core
507741Sgblack@eecs.umich.edu{
513415Sgblack@eecs.umich.edu
523415Sgblack@eecs.umich.educlass sc_event;
535285Sgblack@eecs.umich.educlass sc_event_and_expr;
545285Sgblack@eecs.umich.educlass sc_event_or_expr;
555285Sgblack@eecs.umich.educlass sc_interface;
567532Ssteve.reinhardt@amd.comclass sc_object;
575285Sgblack@eecs.umich.educlass sc_port_base;
585285Sgblack@eecs.umich.edu
595285Sgblack@eecs.umich.educlass sc_event_finder
602207SN/A{
612474SN/A  protected:
622474SN/A    virtual ~sc_event_finder() {}
637741Sgblack@eecs.umich.edu
644111Sgblack@eecs.umich.edu  public:
652561SN/A    // Should be "implementation defined" but used in the tests.
667741Sgblack@eecs.umich.edu    virtual const sc_event &find_event(sc_interface *if_p=NULL) const = 0;
677741Sgblack@eecs.umich.edu    virtual const sc_port_base *port() const = 0;
683415Sgblack@eecs.umich.edu};
695128Sgblack@eecs.umich.edu
705958Sgblack@eecs.umich.edutemplate <class IF>
712474SN/Aclass sc_event_finder_t : public sc_event_finder
722207SN/A{
734111Sgblack@eecs.umich.edu  public:
744111Sgblack@eecs.umich.edu    sc_event_finder_t(const sc_port_base &p,
754111Sgblack@eecs.umich.edu                      const sc_event & (IF::*_method)() const) :
764111Sgblack@eecs.umich.edu        _method(_method)
775154Sgblack@eecs.umich.edu    {
785285Sgblack@eecs.umich.edu        _port = dynamic_cast<const sc_port_b<IF> *>(&p);
794111Sgblack@eecs.umich.edu        assert(_port);
804111Sgblack@eecs.umich.edu    }
814111Sgblack@eecs.umich.edu
824111Sgblack@eecs.umich.edu    virtual ~sc_event_finder_t() {}
834111Sgblack@eecs.umich.edu
844111Sgblack@eecs.umich.edu    const sc_port_base *port() const { return _port; }
854111Sgblack@eecs.umich.edu
864111Sgblack@eecs.umich.edu    const sc_event &
874111Sgblack@eecs.umich.edu    find_event(sc_interface *if_p=NULL) const override
887532Ssteve.reinhardt@amd.com    {
894111Sgblack@eecs.umich.edu        const IF *iface = if_p ? dynamic_cast<const IF *>(if_p) :
904111Sgblack@eecs.umich.edu            dynamic_cast<const IF *>(_port->get_interface());
914111Sgblack@eecs.umich.edu        return (const_cast<IF *>(iface)->*_method)();
924111Sgblack@eecs.umich.edu    }
934111Sgblack@eecs.umich.edu
945128Sgblack@eecs.umich.edu  private:
955958Sgblack@eecs.umich.edu    const sc_port_b<IF> *_port;
966701Sgblack@eecs.umich.edu    const sc_event &(IF::*_method)() const;
979552Sandreas.hansson@arm.com};
989552Sandreas.hansson@arm.com
999552Sandreas.hansson@arm.comclass sc_event_and_list
1005958Sgblack@eecs.umich.edu{
1014111Sgblack@eecs.umich.edu  public:
1024111Sgblack@eecs.umich.edu    sc_event_and_list();
1034111Sgblack@eecs.umich.edu    sc_event_and_list(const sc_event_and_list &);
1044111Sgblack@eecs.umich.edu    sc_event_and_list(const sc_event &);
1054111Sgblack@eecs.umich.edu    sc_event_and_list &operator = (const sc_event_and_list &);
1064111Sgblack@eecs.umich.edu    ~sc_event_and_list();
1075154Sgblack@eecs.umich.edu
1085285Sgblack@eecs.umich.edu    int size() const;
1094111Sgblack@eecs.umich.edu    void swap(sc_event_and_list &);
1104111Sgblack@eecs.umich.edu
1114111Sgblack@eecs.umich.edu    sc_event_and_list &operator &= (const sc_event &);
1124111Sgblack@eecs.umich.edu    sc_event_and_list &operator &= (const sc_event_and_list &);
1134111Sgblack@eecs.umich.edu
1144111Sgblack@eecs.umich.edu    sc_event_and_expr operator & (const sc_event &) const;
1154111Sgblack@eecs.umich.edu    sc_event_and_expr operator & (const sc_event_and_list &);
1164111Sgblack@eecs.umich.edu
1174111Sgblack@eecs.umich.edu  private:
1184111Sgblack@eecs.umich.edu    friend class sc_event_and_expr;
1197532Ssteve.reinhardt@amd.com    friend class sc_gem5::DynamicSensitivityEventAndList;
1204111Sgblack@eecs.umich.edu
1214111Sgblack@eecs.umich.edu    explicit sc_event_and_list(bool auto_delete);
1224111Sgblack@eecs.umich.edu
1234111Sgblack@eecs.umich.edu    void insert(sc_event const &e);
1244111Sgblack@eecs.umich.edu    void insert(sc_event_and_list const &eal);
1255128Sgblack@eecs.umich.edu
1265958Sgblack@eecs.umich.edu    std::set<const sc_event *> events;
1276701Sgblack@eecs.umich.edu    bool autoDelete;
1289552Sandreas.hansson@arm.com    mutable unsigned busy;
1299552Sandreas.hansson@arm.com};
1309552Sandreas.hansson@arm.com
1315958Sgblack@eecs.umich.educlass sc_event_or_list
1324111Sgblack@eecs.umich.edu{
1334111Sgblack@eecs.umich.edu  public:
1342207SN/A    sc_event_or_list();
135    sc_event_or_list(const sc_event_or_list &);
136    sc_event_or_list(const sc_event &);
137    sc_event_or_list& operator = (const sc_event_or_list &);
138    ~sc_event_or_list();
139
140    int size() const;
141    void swap(sc_event_or_list &);
142
143    sc_event_or_list &operator |= (const sc_event &);
144    sc_event_or_list &operator |= (const sc_event_or_list &);
145
146    sc_event_or_expr operator | (const sc_event &) const;
147    sc_event_or_expr operator | (const sc_event_or_list &) const;
148
149  private:
150    friend class sc_event_or_expr;
151    friend class sc_gem5::DynamicSensitivityEventOrList;
152
153    explicit sc_event_or_list(bool auto_delete);
154
155    void insert(sc_event const &e);
156    void insert(sc_event_or_list const &eol);
157
158    std::set<const sc_event *> events;
159    bool autoDelete;
160    mutable unsigned busy;
161};
162
163class sc_event_and_expr
164{
165  public:
166    sc_event_and_expr(sc_event_and_expr const &e);
167    operator const sc_event_and_list &() const;
168
169    void insert(sc_event const &e) const;
170    void insert(sc_event_and_list const &eal) const;
171
172    ~sc_event_and_expr();
173
174  private:
175    friend class sc_event_and_list;
176    friend class sc_event;
177
178    sc_event_and_expr();
179    mutable sc_event_and_list *list;
180};
181
182sc_event_and_expr operator & (sc_event_and_expr, sc_event const &);
183sc_event_and_expr operator & (sc_event_and_expr, sc_event_and_list const &);
184
185class sc_event_or_expr
186{
187  public:
188    sc_event_or_expr(sc_event_or_expr const &e);
189    operator const sc_event_or_list &() const;
190
191    void insert(sc_event const &e) const;
192    void insert(sc_event_or_list const &eol) const;
193
194    ~sc_event_or_expr();
195
196  private:
197    friend class sc_event_or_list;
198    friend class sc_event;
199
200    sc_event_or_expr();
201    mutable sc_event_or_list *list;
202};
203
204sc_event_or_expr operator | (sc_event_or_expr, sc_event const &);
205sc_event_or_expr operator | (sc_event_or_expr, sc_event_or_list const &);
206
207class sc_event
208{
209  public:
210    sc_event();
211    explicit sc_event(const char *);
212    ~sc_event();
213
214    const char *name() const;
215    const char *basename() const;
216    bool in_hierarchy() const;
217    sc_object *get_parent_object() const;
218
219    void notify();
220    void notify(const sc_time &);
221    void notify(double, sc_time_unit);
222    void cancel();
223
224    // Nonstandard
225    // Returns whether this event is currently triggered.
226    bool triggered() const;
227
228    // Deprecated
229    void notify_delayed();
230    void notify_delayed(const sc_time &);
231
232    sc_event_and_expr operator & (const sc_event &) const;
233    sc_event_and_expr operator & (const sc_event_and_list &) const;
234    sc_event_or_expr operator | (const sc_event &) const;
235    sc_event_or_expr operator | (const sc_event_or_list &) const;
236
237  private:
238    // Disabled
239    sc_event(const sc_event &) {}
240    sc_event &operator = (const sc_event &) { return *this; }
241
242    friend class ::sc_gem5::Event;
243    ::sc_gem5::Event *_gem5_event;
244};
245
246const std::vector<sc_event *> &sc_get_top_level_events();
247sc_event *sc_find_event(const char *);
248
249} // namespace sc_core
250
251#endif  //__SYSTEMC_EXT_CORE_SC_INTERFACE_HH__
252