sc_event.hh revision 13294:c4bdd09fe163
112853Sgabeblack@google.com/*
212853Sgabeblack@google.com * Copyright 2018 Google, Inc.
312853Sgabeblack@google.com *
412853Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without
512853Sgabeblack@google.com * modification, are permitted provided that the following conditions are
612853Sgabeblack@google.com * met: redistributions of source code must retain the above copyright
712853Sgabeblack@google.com * notice, this list of conditions and the following disclaimer;
812853Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright
912853Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the
1012853Sgabeblack@google.com * documentation and/or other materials provided with the distribution;
1112853Sgabeblack@google.com * neither the name of the copyright holders nor the names of its
1212853Sgabeblack@google.com * contributors may be used to endorse or promote products derived from
1312853Sgabeblack@google.com * this software without specific prior written permission.
1412853Sgabeblack@google.com *
1512853Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1612853Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1712853Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1812853Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1912853Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2012853Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2112853Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2212853Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2312853Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2412853Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2512853Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2612853Sgabeblack@google.com *
2712853Sgabeblack@google.com * Authors: Gabe Black
2812853Sgabeblack@google.com */
2912853Sgabeblack@google.com
3012853Sgabeblack@google.com#ifndef __SYSTEMC_EXT_CORE_SC_EVENT_HH__
3112853Sgabeblack@google.com#define __SYSTEMC_EXT_CORE_SC_EVENT_HH__
3212853Sgabeblack@google.com
3312853Sgabeblack@google.com#include <cassert>
3412853Sgabeblack@google.com#include <set>
3512853Sgabeblack@google.com#include <sstream>
3612853Sgabeblack@google.com#include <vector>
3712853Sgabeblack@google.com
3812853Sgabeblack@google.com#include "../utils/sc_report_handler.hh"
3912853Sgabeblack@google.com#include "sc_port.hh"
4012853Sgabeblack@google.com#include "sc_time.hh"
4112853Sgabeblack@google.com
4212853Sgabeblack@google.comnamespace sc_gem5
4312853Sgabeblack@google.com{
4412853Sgabeblack@google.com
4512853Sgabeblack@google.comclass Event;
4612853Sgabeblack@google.comclass DynamicSensitivityEventAndList;
4712853Sgabeblack@google.comclass DynamicSensitivityEventOrList;
4812853Sgabeblack@google.com
4912853Sgabeblack@google.com}
5012853Sgabeblack@google.com
5112853Sgabeblack@google.comnamespace sc_core
5212853Sgabeblack@google.com{
5312853Sgabeblack@google.com
5412853Sgabeblack@google.comclass sc_event;
5512853Sgabeblack@google.comclass sc_event_and_expr;
5612853Sgabeblack@google.comclass sc_event_or_expr;
5713325Sgabeblack@google.comclass sc_interface;
5812853Sgabeblack@google.comclass sc_object;
5912853Sgabeblack@google.comclass sc_port_base;
6012853Sgabeblack@google.com
6112853Sgabeblack@google.comclass sc_event_and_list
6212853Sgabeblack@google.com{
6312853Sgabeblack@google.com  public:
6412853Sgabeblack@google.com    sc_event_and_list();
6512853Sgabeblack@google.com    sc_event_and_list(const sc_event_and_list &);
6612853Sgabeblack@google.com    sc_event_and_list(const sc_event &);
6712853Sgabeblack@google.com    sc_event_and_list &operator = (const sc_event_and_list &);
6812853Sgabeblack@google.com    ~sc_event_and_list();
6912853Sgabeblack@google.com
7012853Sgabeblack@google.com    int size() const;
7112853Sgabeblack@google.com    void swap(sc_event_and_list &);
7212853Sgabeblack@google.com
7312853Sgabeblack@google.com    sc_event_and_list &operator &= (const sc_event &);
7412853Sgabeblack@google.com    sc_event_and_list &operator &= (const sc_event_and_list &);
7512853Sgabeblack@google.com
7612853Sgabeblack@google.com    sc_event_and_expr operator & (const sc_event &) const;
7712853Sgabeblack@google.com    sc_event_and_expr operator & (const sc_event_and_list &);
7812853Sgabeblack@google.com
7912853Sgabeblack@google.com  private:
8012853Sgabeblack@google.com    friend class sc_event_and_expr;
8112853Sgabeblack@google.com    friend class sc_gem5::DynamicSensitivityEventAndList;
8212853Sgabeblack@google.com
8312853Sgabeblack@google.com    explicit sc_event_and_list(bool auto_delete);
8412853Sgabeblack@google.com
8512853Sgabeblack@google.com    void insert(sc_event const &e);
8612853Sgabeblack@google.com    void insert(sc_event_and_list const &eal);
8712853Sgabeblack@google.com
8812853Sgabeblack@google.com    std::set<const sc_event *> events;
8912853Sgabeblack@google.com    bool autoDelete;
9012853Sgabeblack@google.com    mutable unsigned busy;
9112853Sgabeblack@google.com};
9212853Sgabeblack@google.com
9312853Sgabeblack@google.comclass sc_event_or_list
9412853Sgabeblack@google.com{
9512853Sgabeblack@google.com  public:
9612853Sgabeblack@google.com    sc_event_or_list();
9712853Sgabeblack@google.com    sc_event_or_list(const sc_event_or_list &);
9812853Sgabeblack@google.com    sc_event_or_list(const sc_event &);
9912853Sgabeblack@google.com    sc_event_or_list& operator = (const sc_event_or_list &);
10012853Sgabeblack@google.com    ~sc_event_or_list();
10112853Sgabeblack@google.com
10212853Sgabeblack@google.com    int size() const;
10312853Sgabeblack@google.com    void swap(sc_event_or_list &);
10412853Sgabeblack@google.com
10512853Sgabeblack@google.com    sc_event_or_list &operator |= (const sc_event &);
10612853Sgabeblack@google.com    sc_event_or_list &operator |= (const sc_event_or_list &);
10712853Sgabeblack@google.com
10812853Sgabeblack@google.com    sc_event_or_expr operator | (const sc_event &) const;
10912853Sgabeblack@google.com    sc_event_or_expr operator | (const sc_event_or_list &) const;
11012853Sgabeblack@google.com
11112853Sgabeblack@google.com  private:
11212853Sgabeblack@google.com    friend class sc_event_or_expr;
11312853Sgabeblack@google.com    friend class sc_gem5::DynamicSensitivityEventOrList;
11412853Sgabeblack@google.com
11512853Sgabeblack@google.com    explicit sc_event_or_list(bool auto_delete);
11612853Sgabeblack@google.com
11712853Sgabeblack@google.com    void insert(sc_event const &e);
11812853Sgabeblack@google.com    void insert(sc_event_or_list const &eol);
11912853Sgabeblack@google.com
12012853Sgabeblack@google.com    std::set<const sc_event *> events;
12112853Sgabeblack@google.com    bool autoDelete;
12212853Sgabeblack@google.com    mutable unsigned busy;
12312853Sgabeblack@google.com};
12412853Sgabeblack@google.com
12512853Sgabeblack@google.comclass sc_event_and_expr
12612853Sgabeblack@google.com{
12712853Sgabeblack@google.com  public:
12812853Sgabeblack@google.com    sc_event_and_expr(sc_event_and_expr const &e);
12912853Sgabeblack@google.com    operator const sc_event_and_list &() const;
13012853Sgabeblack@google.com
13112853Sgabeblack@google.com    void insert(sc_event const &e) const;
13212853Sgabeblack@google.com    void insert(sc_event_and_list const &eal) const;
13312853Sgabeblack@google.com
13412853Sgabeblack@google.com    ~sc_event_and_expr();
13512853Sgabeblack@google.com
13612853Sgabeblack@google.com  private:
13712853Sgabeblack@google.com    friend class sc_event_and_list;
13812853Sgabeblack@google.com    friend class sc_event;
13912853Sgabeblack@google.com
14012853Sgabeblack@google.com    sc_event_and_expr();
14112853Sgabeblack@google.com    mutable sc_event_and_list *list;
14212853Sgabeblack@google.com};
14312853Sgabeblack@google.com
14412853Sgabeblack@google.comsc_event_and_expr operator & (sc_event_and_expr, sc_event const &);
14512853Sgabeblack@google.comsc_event_and_expr operator & (sc_event_and_expr, sc_event_and_list const &);
14612853Sgabeblack@google.com
14712853Sgabeblack@google.comclass sc_event_or_expr
14812853Sgabeblack@google.com{
14912853Sgabeblack@google.com  public:
15012853Sgabeblack@google.com    sc_event_or_expr(sc_event_or_expr const &e);
15112853Sgabeblack@google.com    operator const sc_event_or_list &() const;
15212853Sgabeblack@google.com
15312853Sgabeblack@google.com    void insert(sc_event const &e) const;
15412853Sgabeblack@google.com    void insert(sc_event_or_list const &eol) const;
15512853Sgabeblack@google.com
15612853Sgabeblack@google.com    ~sc_event_or_expr();
15712853Sgabeblack@google.com
15812853Sgabeblack@google.com  private:
15912853Sgabeblack@google.com    friend class sc_event_or_list;
16012853Sgabeblack@google.com    friend class sc_event;
16112853Sgabeblack@google.com
16212853Sgabeblack@google.com    sc_event_or_expr();
16312853Sgabeblack@google.com    mutable sc_event_or_list *list;
16412853Sgabeblack@google.com};
16512853Sgabeblack@google.com
16612853Sgabeblack@google.comsc_event_or_expr operator | (sc_event_or_expr, sc_event const &);
16712853Sgabeblack@google.comsc_event_or_expr operator | (sc_event_or_expr, sc_event_or_list const &);
16812853Sgabeblack@google.com
16912853Sgabeblack@google.comclass sc_event
17012853Sgabeblack@google.com{
17112853Sgabeblack@google.com  public:
17212853Sgabeblack@google.com    sc_event();
17312853Sgabeblack@google.com    explicit sc_event(const char *);
17412853Sgabeblack@google.com    ~sc_event();
17512853Sgabeblack@google.com
17612853Sgabeblack@google.com    const char *name() const;
17712853Sgabeblack@google.com    const char *basename() const;
17812853Sgabeblack@google.com    bool in_hierarchy() const;
17912853Sgabeblack@google.com    sc_object *get_parent_object() const;
18012853Sgabeblack@google.com
18112853Sgabeblack@google.com    void notify();
18212853Sgabeblack@google.com    void notify(const sc_time &);
18312853Sgabeblack@google.com    void notify(double, sc_time_unit);
18412853Sgabeblack@google.com    void cancel();
18512853Sgabeblack@google.com
18612853Sgabeblack@google.com    // Nonstandard
18712853Sgabeblack@google.com    // Returns whether this event is currently triggered.
18812853Sgabeblack@google.com    bool triggered() const;
18912853Sgabeblack@google.com
19012853Sgabeblack@google.com    // Deprecated
19112853Sgabeblack@google.com    void notify_delayed();
19212853Sgabeblack@google.com    void notify_delayed(const sc_time &);
19312853Sgabeblack@google.com
19412853Sgabeblack@google.com    sc_event_and_expr operator & (const sc_event &) const;
19512853Sgabeblack@google.com    sc_event_and_expr operator & (const sc_event_and_list &) const;
19612853Sgabeblack@google.com    sc_event_or_expr operator | (const sc_event &) const;
19712853Sgabeblack@google.com    sc_event_or_expr operator | (const sc_event_or_list &) const;
19812853Sgabeblack@google.com
19912853Sgabeblack@google.com  private:
20012853Sgabeblack@google.com    // Disabled
20112853Sgabeblack@google.com    sc_event(const sc_event &) {}
20212853Sgabeblack@google.com    sc_event &operator = (const sc_event &) { return *this; }
20312853Sgabeblack@google.com
20412853Sgabeblack@google.com    friend class ::sc_gem5::Event;
20512853Sgabeblack@google.com    ::sc_gem5::Event *_gem5_event;
20612853Sgabeblack@google.com};
20712853Sgabeblack@google.com
20812853Sgabeblack@google.comclass sc_event_finder
20912853Sgabeblack@google.com{
21012853Sgabeblack@google.com  protected:
21112853Sgabeblack@google.com    virtual ~sc_event_finder() {}
21212853Sgabeblack@google.com
21312853Sgabeblack@google.com  public:
21412853Sgabeblack@google.com    // Should be "implementation defined" but used in the tests.
21512853Sgabeblack@google.com    virtual const sc_event &find_event(sc_interface *if_p=NULL) const = 0;
21612853Sgabeblack@google.com    virtual const sc_port_base *port() const = 0;
21712853Sgabeblack@google.com};
21812853Sgabeblack@google.com
21912853Sgabeblack@google.comtemplate <class IF>
22012853Sgabeblack@google.comclass sc_event_finder_t : public sc_event_finder
22112853Sgabeblack@google.com{
22212853Sgabeblack@google.com  public:
22312853Sgabeblack@google.com    sc_event_finder_t(const sc_port_base &p,
22412853Sgabeblack@google.com                      const sc_event & (IF::*_method)() const) :
22512853Sgabeblack@google.com        _method(_method)
22612853Sgabeblack@google.com    {
22712853Sgabeblack@google.com        _port = dynamic_cast<const sc_port_b<IF> *>(&p);
22812853Sgabeblack@google.com        assert(_port);
22912853Sgabeblack@google.com    }
23012853Sgabeblack@google.com
23112853Sgabeblack@google.com    virtual ~sc_event_finder_t() {}
23212853Sgabeblack@google.com
23312853Sgabeblack@google.com    const sc_port_base *port() const { return _port; }
23412853Sgabeblack@google.com
23512853Sgabeblack@google.com    const sc_event &
23612853Sgabeblack@google.com    find_event(sc_interface *if_p=NULL) const override
23712853Sgabeblack@google.com    {
23812853Sgabeblack@google.com        static const sc_event none;
23912853Sgabeblack@google.com        const IF *iface = if_p ? dynamic_cast<const IF *>(if_p) :
24012853Sgabeblack@google.com            dynamic_cast<const IF *>(_port->get_interface());
24112853Sgabeblack@google.com        if (!iface) {
24212853Sgabeblack@google.com            std::ostringstream ss;
24312853Sgabeblack@google.com            ss << "port is not bound: port '" << _port->name() << "' (" <<
24412853Sgabeblack@google.com                _port->kind() << ")";
24512853Sgabeblack@google.com            SC_REPORT_ERROR("(E118) find event failed", ss.str().c_str());
24612853Sgabeblack@google.com            return none;
24712853Sgabeblack@google.com        }
24812853Sgabeblack@google.com        return (const_cast<IF *>(iface)->*_method)();
24912853Sgabeblack@google.com    }
25012853Sgabeblack@google.com
25112853Sgabeblack@google.com  private:
25212853Sgabeblack@google.com    const sc_port_b<IF> *_port;
25312853Sgabeblack@google.com    const sc_event &(IF::*_method)() const;
25412853Sgabeblack@google.com};
25512853Sgabeblack@google.com
25612853Sgabeblack@google.comconst std::vector<sc_event *> &sc_get_top_level_events();
25712853Sgabeblack@google.comsc_event *sc_find_event(const char *);
25812853Sgabeblack@google.com
25912853Sgabeblack@google.com} // namespace sc_core
26012853Sgabeblack@google.com
26112853Sgabeblack@google.com#endif  //__SYSTEMC_EXT_CORE_SC_INTERFACE_HH__
26212853Sgabeblack@google.com