sc_event.hh revision 13051
112837Sgabeblack@google.com/*
212837Sgabeblack@google.com * Copyright 2018 Google, Inc.
312837Sgabeblack@google.com *
412837Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without
512837Sgabeblack@google.com * modification, are permitted provided that the following conditions are
612837Sgabeblack@google.com * met: redistributions of source code must retain the above copyright
712837Sgabeblack@google.com * notice, this list of conditions and the following disclaimer;
812837Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright
912837Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the
1012837Sgabeblack@google.com * documentation and/or other materials provided with the distribution;
1112837Sgabeblack@google.com * neither the name of the copyright holders nor the names of its
1212837Sgabeblack@google.com * contributors may be used to endorse or promote products derived from
1312837Sgabeblack@google.com * this software without specific prior written permission.
1412837Sgabeblack@google.com *
1512837Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1612837Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1712837Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1812837Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1912837Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2012837Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2112837Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2212837Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2312837Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2412837Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2512837Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2612837Sgabeblack@google.com *
2712837Sgabeblack@google.com * Authors: Gabe Black
2812837Sgabeblack@google.com */
2912837Sgabeblack@google.com
3012837Sgabeblack@google.com#ifndef __SYSTEMC_EXT_CORE_SC_EVENT_HH__
3112837Sgabeblack@google.com#define __SYSTEMC_EXT_CORE_SC_EVENT_HH__
3212837Sgabeblack@google.com
3313051Sgabeblack@google.com#include <cassert>
3412955Sgabeblack@google.com#include <set>
3512837Sgabeblack@google.com#include <vector>
3612837Sgabeblack@google.com
3713051Sgabeblack@google.com#include "sc_port.hh"
3812837Sgabeblack@google.com#include "sc_time.hh"
3912837Sgabeblack@google.com
4012955Sgabeblack@google.comnamespace sc_gem5
4112955Sgabeblack@google.com{
4212955Sgabeblack@google.com
4312955Sgabeblack@google.comclass Event;
4412957Sgabeblack@google.comclass SensitivityEventAndList;
4512957Sgabeblack@google.comclass SensitivityEventOrList;
4612955Sgabeblack@google.com
4712955Sgabeblack@google.com}
4812955Sgabeblack@google.com
4912837Sgabeblack@google.comnamespace sc_core
5012837Sgabeblack@google.com{
5112837Sgabeblack@google.com
5212837Sgabeblack@google.comclass sc_event;
5312837Sgabeblack@google.comclass sc_event_and_expr;
5412837Sgabeblack@google.comclass sc_event_or_expr;
5512924Sgabeblack@google.comclass sc_interface;
5612837Sgabeblack@google.comclass sc_object;
5712837Sgabeblack@google.comclass sc_port_base;
5812837Sgabeblack@google.com
5912837Sgabeblack@google.comclass sc_event_finder
6012837Sgabeblack@google.com{
6112837Sgabeblack@google.com  protected:
6212837Sgabeblack@google.com    void warn_unimpl(const char *func) const;
6313051Sgabeblack@google.com    virtual ~sc_event_finder() {}
6412924Sgabeblack@google.com
6512924Sgabeblack@google.com  public:
6612924Sgabeblack@google.com    // Should be "implementation defined" but used in the tests.
6712924Sgabeblack@google.com    virtual const sc_event &find_event(sc_interface *if_p=NULL) const = 0;
6812837Sgabeblack@google.com};
6912837Sgabeblack@google.com
7012837Sgabeblack@google.comtemplate <class IF>
7112837Sgabeblack@google.comclass sc_event_finder_t : public sc_event_finder
7212837Sgabeblack@google.com{
7312837Sgabeblack@google.com  public:
7413051Sgabeblack@google.com    sc_event_finder_t(const sc_port_base &p,
7513051Sgabeblack@google.com                      const sc_event & (IF::*_method)() const) :
7613051Sgabeblack@google.com        _method(_method)
7712837Sgabeblack@google.com    {
7813051Sgabeblack@google.com        _port = dynamic_cast<const sc_port_b<IF> *>(&p);
7913051Sgabeblack@google.com        assert(_port);
8012837Sgabeblack@google.com    }
8112924Sgabeblack@google.com
8213051Sgabeblack@google.com    virtual ~sc_event_finder_t() {}
8313051Sgabeblack@google.com
8412924Sgabeblack@google.com    const sc_event &
8512924Sgabeblack@google.com    find_event(sc_interface *if_p=NULL) const override
8612924Sgabeblack@google.com    {
8713051Sgabeblack@google.com        const IF *iface = if_p ? dynamic_cast<const IF *>(if_p) :
8813051Sgabeblack@google.com            dynamic_cast<const IF *>(_port->get_interface());
8913051Sgabeblack@google.com        return (const_cast<IF *>(iface)->*_method)();
9012924Sgabeblack@google.com    }
9113051Sgabeblack@google.com
9213051Sgabeblack@google.com  private:
9313051Sgabeblack@google.com    const sc_port_b<IF> *_port;
9413051Sgabeblack@google.com    const sc_event &(IF::*_method)() const;
9512837Sgabeblack@google.com};
9612837Sgabeblack@google.com
9712837Sgabeblack@google.comclass sc_event_and_list
9812837Sgabeblack@google.com{
9912837Sgabeblack@google.com  public:
10012837Sgabeblack@google.com    sc_event_and_list();
10112837Sgabeblack@google.com    sc_event_and_list(const sc_event_and_list &);
10212837Sgabeblack@google.com    sc_event_and_list(const sc_event &);
10312837Sgabeblack@google.com    sc_event_and_list &operator = (const sc_event_and_list &);
10412955Sgabeblack@google.com    ~sc_event_and_list();
10512837Sgabeblack@google.com
10612837Sgabeblack@google.com    int size() const;
10712837Sgabeblack@google.com    void swap(sc_event_and_list &);
10812837Sgabeblack@google.com
10912837Sgabeblack@google.com    sc_event_and_list &operator &= (const sc_event &);
11012837Sgabeblack@google.com    sc_event_and_list &operator &= (const sc_event_and_list &);
11112837Sgabeblack@google.com
11212837Sgabeblack@google.com    sc_event_and_expr operator & (const sc_event &) const;
11312837Sgabeblack@google.com    sc_event_and_expr operator & (const sc_event_and_list &);
11412955Sgabeblack@google.com
11512955Sgabeblack@google.com  private:
11612955Sgabeblack@google.com    friend class sc_event_and_expr;
11712957Sgabeblack@google.com    friend class sc_gem5::SensitivityEventAndList;
11812955Sgabeblack@google.com
11912955Sgabeblack@google.com    explicit sc_event_and_list(bool auto_delete);
12012955Sgabeblack@google.com
12112955Sgabeblack@google.com    void insert(sc_event const &e);
12212955Sgabeblack@google.com    void insert(sc_event_and_list const &eal);
12312955Sgabeblack@google.com
12412955Sgabeblack@google.com    std::set<const sc_event *> events;
12512955Sgabeblack@google.com    bool autoDelete;
12612955Sgabeblack@google.com    mutable unsigned busy;
12712837Sgabeblack@google.com};
12812837Sgabeblack@google.com
12912837Sgabeblack@google.comclass sc_event_or_list
13012837Sgabeblack@google.com{
13112837Sgabeblack@google.com  public:
13212837Sgabeblack@google.com    sc_event_or_list();
13312837Sgabeblack@google.com    sc_event_or_list(const sc_event_or_list &);
13412837Sgabeblack@google.com    sc_event_or_list(const sc_event &);
13512837Sgabeblack@google.com    sc_event_or_list& operator = (const sc_event_or_list &);
13612837Sgabeblack@google.com    ~sc_event_or_list();
13712837Sgabeblack@google.com
13812837Sgabeblack@google.com    int size() const;
13912837Sgabeblack@google.com    void swap(sc_event_or_list &);
14012837Sgabeblack@google.com
14112837Sgabeblack@google.com    sc_event_or_list &operator |= (const sc_event &);
14212837Sgabeblack@google.com    sc_event_or_list &operator |= (const sc_event_or_list &);
14312837Sgabeblack@google.com
14412837Sgabeblack@google.com    sc_event_or_expr operator | (const sc_event &) const;
14512837Sgabeblack@google.com    sc_event_or_expr operator | (const sc_event_or_list &) const;
14612955Sgabeblack@google.com
14712955Sgabeblack@google.com  private:
14812955Sgabeblack@google.com    friend class sc_event_or_expr;
14912957Sgabeblack@google.com    friend class sc_gem5::SensitivityEventOrList;
15012955Sgabeblack@google.com
15112955Sgabeblack@google.com    explicit sc_event_or_list(bool auto_delete);
15212955Sgabeblack@google.com
15312955Sgabeblack@google.com    void insert(sc_event const &e);
15412955Sgabeblack@google.com    void insert(sc_event_or_list const &eol);
15512955Sgabeblack@google.com
15612955Sgabeblack@google.com    std::set<const sc_event *> events;
15712955Sgabeblack@google.com    bool autoDelete;
15812955Sgabeblack@google.com    mutable unsigned busy;
15912837Sgabeblack@google.com};
16012837Sgabeblack@google.com
16112837Sgabeblack@google.comclass sc_event_and_expr
16212837Sgabeblack@google.com{
16312837Sgabeblack@google.com  public:
16412955Sgabeblack@google.com    sc_event_and_expr(sc_event_and_expr const &e);
16512837Sgabeblack@google.com    operator const sc_event_and_list &() const;
16612955Sgabeblack@google.com
16712955Sgabeblack@google.com    void insert(sc_event const &e) const;
16812955Sgabeblack@google.com    void insert(sc_event_and_list const &eal) const;
16912955Sgabeblack@google.com
17012955Sgabeblack@google.com    ~sc_event_and_expr();
17112955Sgabeblack@google.com
17212955Sgabeblack@google.com  private:
17312955Sgabeblack@google.com    friend class sc_event_and_list;
17412955Sgabeblack@google.com    friend class sc_event;
17512955Sgabeblack@google.com
17612955Sgabeblack@google.com    sc_event_and_expr();
17712955Sgabeblack@google.com    mutable sc_event_and_list *list;
17812837Sgabeblack@google.com};
17912837Sgabeblack@google.com
18012837Sgabeblack@google.comsc_event_and_expr operator & (sc_event_and_expr, sc_event const &);
18112837Sgabeblack@google.comsc_event_and_expr operator & (sc_event_and_expr, sc_event_and_list const &);
18212837Sgabeblack@google.com
18312837Sgabeblack@google.comclass sc_event_or_expr
18412837Sgabeblack@google.com{
18512837Sgabeblack@google.com  public:
18612955Sgabeblack@google.com    sc_event_or_expr(sc_event_or_expr const &e);
18712837Sgabeblack@google.com    operator const sc_event_or_list &() const;
18812955Sgabeblack@google.com
18912955Sgabeblack@google.com    void insert(sc_event const &e) const;
19012955Sgabeblack@google.com    void insert(sc_event_or_list const &eol) const;
19112955Sgabeblack@google.com
19212955Sgabeblack@google.com    ~sc_event_or_expr();
19312955Sgabeblack@google.com
19412955Sgabeblack@google.com  private:
19512955Sgabeblack@google.com    friend class sc_event_or_list;
19612955Sgabeblack@google.com    friend class sc_event;
19712955Sgabeblack@google.com
19812955Sgabeblack@google.com    sc_event_or_expr();
19912955Sgabeblack@google.com    mutable sc_event_or_list *list;
20012837Sgabeblack@google.com};
20112837Sgabeblack@google.com
20212837Sgabeblack@google.comsc_event_or_expr operator | (sc_event_or_expr, sc_event const &);
20312837Sgabeblack@google.comsc_event_or_expr operator | (sc_event_or_expr, sc_event_or_list const &);
20412837Sgabeblack@google.com
20512837Sgabeblack@google.comclass sc_event
20612837Sgabeblack@google.com{
20712837Sgabeblack@google.com  public:
20812837Sgabeblack@google.com    sc_event();
20912837Sgabeblack@google.com    explicit sc_event(const char *);
21012837Sgabeblack@google.com    ~sc_event();
21112837Sgabeblack@google.com
21212837Sgabeblack@google.com    const char *name() const;
21312837Sgabeblack@google.com    const char *basename() const;
21412837Sgabeblack@google.com    bool in_hierarchy() const;
21512837Sgabeblack@google.com    sc_object *get_parent_object() const;
21612837Sgabeblack@google.com
21712837Sgabeblack@google.com    void notify();
21812837Sgabeblack@google.com    void notify(const sc_time &);
21912837Sgabeblack@google.com    void notify(double, sc_time_unit);
22012837Sgabeblack@google.com    void cancel();
22112837Sgabeblack@google.com
22212900Sgabeblack@google.com    // Nonstandard
22312900Sgabeblack@google.com    // Returns whether this event is currently triggered.
22412900Sgabeblack@google.com    bool triggered() const;
22512900Sgabeblack@google.com
22612915Sgabeblack@google.com    // Deprecated
22712915Sgabeblack@google.com    void notify_delayed();
22812915Sgabeblack@google.com    void notify_delayed(const sc_time &);
22912915Sgabeblack@google.com
23012837Sgabeblack@google.com    sc_event_and_expr operator & (const sc_event &) const;
23112837Sgabeblack@google.com    sc_event_and_expr operator & (const sc_event_and_list &) const;
23212837Sgabeblack@google.com    sc_event_or_expr operator | (const sc_event &) const;
23312837Sgabeblack@google.com    sc_event_or_expr operator | (const sc_event_or_list &) const;
23412837Sgabeblack@google.com
23512837Sgabeblack@google.com  private:
23612837Sgabeblack@google.com    // Disabled
23712837Sgabeblack@google.com    sc_event(const sc_event &) {}
23812837Sgabeblack@google.com    sc_event &operator = (const sc_event &) { return *this; }
23912955Sgabeblack@google.com
24012955Sgabeblack@google.com    friend class ::sc_gem5::Event;
24112955Sgabeblack@google.com    ::sc_gem5::Event *_gem5_event;
24212837Sgabeblack@google.com};
24312837Sgabeblack@google.com
24412837Sgabeblack@google.comconst std::vector<sc_event *> &sc_get_top_level_events();
24512837Sgabeblack@google.comsc_event *sc_find_event(const char *);
24612837Sgabeblack@google.com
24712837Sgabeblack@google.com} // namespace sc_core
24812837Sgabeblack@google.com
24912837Sgabeblack@google.com#endif  //__SYSTEMC_EXT_CORE_SC_INTERFACE_HH__
250