sc_event.hh revision 13380:6e390b3db40e
16145Snate@binkert.org/*
26145Snate@binkert.org * Copyright 2018 Google, Inc.
36145Snate@binkert.org *
46145Snate@binkert.org * Redistribution and use in source and binary forms, with or without
56145Snate@binkert.org * modification, are permitted provided that the following conditions are
66145Snate@binkert.org * met: redistributions of source code must retain the above copyright
76145Snate@binkert.org * notice, this list of conditions and the following disclaimer;
86145Snate@binkert.org * redistributions in binary form must reproduce the above copyright
96145Snate@binkert.org * notice, this list of conditions and the following disclaimer in the
106145Snate@binkert.org * documentation and/or other materials provided with the distribution;
116145Snate@binkert.org * neither the name of the copyright holders nor the names of its
126145Snate@binkert.org * contributors may be used to endorse or promote products derived from
136145Snate@binkert.org * this software without specific prior written permission.
146145Snate@binkert.org *
156145Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
166145Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
176145Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
186145Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
196145Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
206145Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
216145Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
226145Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
236145Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
246145Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
256145Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
266145Snate@binkert.org *
276145Snate@binkert.org * Authors: Gabe Black
286145Snate@binkert.org */
297832Snate@binkert.org
307547SBrad.Beckmann@amd.com#ifndef __SYSTEMC_EXT_CORE_SC_EVENT_HH__
317547SBrad.Beckmann@amd.com#define __SYSTEMC_EXT_CORE_SC_EVENT_HH__
328645Snilay@cs.wisc.edu
337454Snate@binkert.org#include <cassert>
347054Snate@binkert.org#include <set>
3510301Snilay@cs.wisc.edu#include <sstream>
368258SBrad.Beckmann@amd.com#include <vector>
376154Snate@binkert.org
387054Snate@binkert.org#include "../channel/messages.hh"
397547SBrad.Beckmann@amd.com#include "../utils/sc_report_handler.hh"
406154Snate@binkert.org#include "sc_port.hh"
416154Snate@binkert.org#include "sc_time.hh"
426145Snate@binkert.org
437055Snate@binkert.orgnamespace sc_gem5
447454Snate@binkert.org{
457055Snate@binkert.org
466876Ssteve.reinhardt@amd.comclass Event;
476876Ssteve.reinhardt@amd.comclass DynamicSensitivityEventAndList;
486285Snate@binkert.orgclass DynamicSensitivityEventOrList;
498259SBrad.Beckmann@amd.comclass InternalScEvent;
508259SBrad.Beckmann@amd.com
518259SBrad.Beckmann@amd.com}
528259SBrad.Beckmann@amd.com
537054Snate@binkert.orgnamespace sc_core
547054Snate@binkert.org{
557054Snate@binkert.org
567454Snate@binkert.orgclass sc_event;
576285Snate@binkert.orgclass sc_event_and_expr;
589274Snilay@cs.wisc.educlass sc_event_or_expr;
599593Snilay@cs.wisc.educlass sc_interface;
609593Snilay@cs.wisc.educlass sc_object;
619274Snilay@cs.wisc.educlass sc_port_base;
629858Snilay@cs.wisc.edu
639274Snilay@cs.wisc.educlass sc_event_and_list
649274Snilay@cs.wisc.edu{
6511021Sjthestness@gmail.com  public:
6611021Sjthestness@gmail.com    sc_event_and_list();
6711021Sjthestness@gmail.com    sc_event_and_list(const sc_event_and_list &);
686881SBrad.Beckmann@amd.com    sc_event_and_list(const sc_event &);
696285Snate@binkert.org    sc_event_and_list &operator = (const sc_event_and_list &);
707054Snate@binkert.org    ~sc_event_and_list();
717054Snate@binkert.org
726881SBrad.Beckmann@amd.com    int size() const;
737054Snate@binkert.org    void swap(sc_event_and_list &);
746881SBrad.Beckmann@amd.com
757054Snate@binkert.org    sc_event_and_list &operator &= (const sc_event &);
767054Snate@binkert.org    sc_event_and_list &operator &= (const sc_event_and_list &);
777054Snate@binkert.org
789799Snilay@cs.wisc.edu    sc_event_and_expr operator & (const sc_event &) const;
796285Snate@binkert.org    sc_event_and_expr operator & (const sc_event_and_list &);
806145Snate@binkert.org
816145Snate@binkert.org  private:
826145Snate@binkert.org    friend class sc_event_and_expr;
839858Snilay@cs.wisc.edu    friend class sc_gem5::DynamicSensitivityEventAndList;
8411021Sjthestness@gmail.com
856145Snate@binkert.org    explicit sc_event_and_list(bool auto_delete);
866145Snate@binkert.org
876145Snate@binkert.org    void insert(sc_event const &e);
887054Snate@binkert.org    void insert(sc_event_and_list const &eal);
8910917Sbrandon.potter@amd.com
9010917Sbrandon.potter@amd.com    std::set<const sc_event *> events;
919799Snilay@cs.wisc.edu    bool autoDelete;
926145Snate@binkert.org    mutable unsigned busy;
937054Snate@binkert.org};
949858Snilay@cs.wisc.edu
959858Snilay@cs.wisc.educlass sc_event_or_list
967054Snate@binkert.org{
978258SBrad.Beckmann@amd.com  public:
988258SBrad.Beckmann@amd.com    sc_event_or_list();
9910311Snilay@cs.wisc.edu    sc_event_or_list(const sc_event_or_list &);
10010311Snilay@cs.wisc.edu    sc_event_or_list(const sc_event &);
10110311Snilay@cs.wisc.edu    sc_event_or_list& operator = (const sc_event_or_list &);
1028257SBrad.Beckmann@amd.com    ~sc_event_or_list();
1039858Snilay@cs.wisc.edu
1046145Snate@binkert.org    int size() const;
1056145Snate@binkert.org    void swap(sc_event_or_list &);
1066145Snate@binkert.org
1077054Snate@binkert.org    sc_event_or_list &operator |= (const sc_event &);
10810917Sbrandon.potter@amd.com    sc_event_or_list &operator |= (const sc_event_or_list &);
10910917Sbrandon.potter@amd.com
1109799Snilay@cs.wisc.edu    sc_event_or_expr operator | (const sc_event &) const;
1116145Snate@binkert.org    sc_event_or_expr operator | (const sc_event_or_list &) const;
1127054Snate@binkert.org
1139858Snilay@cs.wisc.edu  private:
1146145Snate@binkert.org    friend class sc_event_or_expr;
1156145Snate@binkert.org    friend class sc_gem5::DynamicSensitivityEventOrList;
1166145Snate@binkert.org
1177054Snate@binkert.org    explicit sc_event_or_list(bool auto_delete);
11810917Sbrandon.potter@amd.com
11910917Sbrandon.potter@amd.com    void insert(sc_event const &e);
1209799Snilay@cs.wisc.edu    void insert(sc_event_or_list const &eol);
1216145Snate@binkert.org
1226145Snate@binkert.org    std::set<const sc_event *> events;
12310370Snilay@cs.wisc.edu    bool autoDelete;
12410370Snilay@cs.wisc.edu    mutable unsigned busy;
1256145Snate@binkert.org};
1267054Snate@binkert.org
12711021Sjthestness@gmail.comclass sc_event_and_expr
12811021Sjthestness@gmail.com{
12911021Sjthestness@gmail.com  public:
13010311Snilay@cs.wisc.edu    sc_event_and_expr(sc_event_and_expr const &e);
1317054Snate@binkert.org    operator const sc_event_and_list &() const;
13210311Snilay@cs.wisc.edu
1337054Snate@binkert.org    void insert(sc_event const &e) const;
1348258SBrad.Beckmann@amd.com    void insert(sc_event_and_list const &eal) const;
1358258SBrad.Beckmann@amd.com
1369858Snilay@cs.wisc.edu    ~sc_event_and_expr();
1379858Snilay@cs.wisc.edu
13810311Snilay@cs.wisc.edu  private:
13910311Snilay@cs.wisc.edu    friend class sc_event_and_list;
1407054Snate@binkert.org    friend class sc_event;
1417054Snate@binkert.org
1427054Snate@binkert.org    sc_event_and_expr();
1437054Snate@binkert.org    mutable sc_event_and_list *list;
1447054Snate@binkert.org};
1457832Snate@binkert.org
1467832Snate@binkert.orgsc_event_and_expr operator & (sc_event_and_expr, sc_event const &);
1477054Snate@binkert.orgsc_event_and_expr operator & (sc_event_and_expr, sc_event_and_list const &);
1487054Snate@binkert.org
1497054Snate@binkert.orgclass sc_event_or_expr
1507054Snate@binkert.org{
1517054Snate@binkert.org  public:
1527054Snate@binkert.org    sc_event_or_expr(sc_event_or_expr const &e);
1537054Snate@binkert.org    operator const sc_event_or_list &() const;
15410311Snilay@cs.wisc.edu
15510311Snilay@cs.wisc.edu    void insert(sc_event const &e) const;
15610311Snilay@cs.wisc.edu    void insert(sc_event_or_list const &eol) const;
1577054Snate@binkert.org
1587054Snate@binkert.org    ~sc_event_or_expr();
15910370Snilay@cs.wisc.edu
16010370Snilay@cs.wisc.edu  private:
16110370Snilay@cs.wisc.edu    friend class sc_event_or_list;
16210311Snilay@cs.wisc.edu    friend class sc_event;
1637054Snate@binkert.org
1647054Snate@binkert.org    sc_event_or_expr();
16510311Snilay@cs.wisc.edu    mutable sc_event_or_list *list;
16610311Snilay@cs.wisc.edu};
16710311Snilay@cs.wisc.edu
1687054Snate@binkert.orgsc_event_or_expr operator | (sc_event_or_expr, sc_event const &);
1697054Snate@binkert.orgsc_event_or_expr operator | (sc_event_or_expr, sc_event_or_list const &);
17010370Snilay@cs.wisc.edu
17110370Snilay@cs.wisc.educlass sc_event
17210370Snilay@cs.wisc.edu{
17310311Snilay@cs.wisc.edu  public:
1747054Snate@binkert.org    sc_event();
1757054Snate@binkert.org    explicit sc_event(const char *);
1767054Snate@binkert.org    ~sc_event();
1779863Snilay@cs.wisc.edu
1787054Snate@binkert.org    const char *name() const;
1799863Snilay@cs.wisc.edu    const char *basename() const;
1809863Snilay@cs.wisc.edu    bool in_hierarchy() const;
1819863Snilay@cs.wisc.edu    sc_object *get_parent_object() const;
1829863Snilay@cs.wisc.edu
1839863Snilay@cs.wisc.edu    void notify();
1849863Snilay@cs.wisc.edu    void notify(const sc_time &);
1859863Snilay@cs.wisc.edu    void notify(double, sc_time_unit);
1869863Snilay@cs.wisc.edu    void cancel();
1879863Snilay@cs.wisc.edu
1889863Snilay@cs.wisc.edu    // Nonstandard
1897547SBrad.Beckmann@amd.com    // Returns whether this event is currently triggered.
1909863Snilay@cs.wisc.edu    bool triggered() const;
1919863Snilay@cs.wisc.edu
1929863Snilay@cs.wisc.edu    // Deprecated
1939863Snilay@cs.wisc.edu    void notify_delayed();
1947547SBrad.Beckmann@amd.com    void notify_delayed(const sc_time &);
1959863Snilay@cs.wisc.edu
1969863Snilay@cs.wisc.edu    sc_event_and_expr operator & (const sc_event &) const;
1979863Snilay@cs.wisc.edu    sc_event_and_expr operator & (const sc_event_and_list &) const;
1989863Snilay@cs.wisc.edu    sc_event_or_expr operator | (const sc_event &) const;
1997054Snate@binkert.org    sc_event_or_expr operator | (const sc_event_or_list &) const;
2007054Snate@binkert.org
2017054Snate@binkert.org  protected:
2027054Snate@binkert.org    explicit sc_event(bool);
2039863Snilay@cs.wisc.edu    explicit sc_event(bool, const char *);
2047054Snate@binkert.org
2059858Snilay@cs.wisc.edu  private:
2069863Snilay@cs.wisc.edu    // Disabled
2077054Snate@binkert.org    sc_event(const sc_event &) {}
2087054Snate@binkert.org    sc_event &operator = (const sc_event &) { return *this; }
2097054Snate@binkert.org
2107054Snate@binkert.org    friend class ::sc_gem5::Event;
2117054Snate@binkert.org    ::sc_gem5::Event *_gem5_event;
2126145Snate@binkert.org};
2137054Snate@binkert.org
2146145Snate@binkert.orgclass sc_event_finder
2156876Ssteve.reinhardt@amd.com{
2166876Ssteve.reinhardt@amd.com  protected:
2176876Ssteve.reinhardt@amd.com    virtual ~sc_event_finder() {}
2186876Ssteve.reinhardt@amd.com
2196876Ssteve.reinhardt@amd.com  public:
2206876Ssteve.reinhardt@amd.com    // Should be "implementation defined" but used in the tests.
2219302Snilay@cs.wisc.edu    virtual const sc_event &find_event(sc_interface *if_p=NULL) const = 0;
2229302Snilay@cs.wisc.edu    virtual const sc_port_base *port() const = 0;
2239302Snilay@cs.wisc.edu};
2249302Snilay@cs.wisc.edu
2259302Snilay@cs.wisc.edutemplate <class IF>
2269302Snilay@cs.wisc.educlass sc_event_finder_t : public sc_event_finder
2279302Snilay@cs.wisc.edu{
2289302Snilay@cs.wisc.edu  public:
2299302Snilay@cs.wisc.edu    sc_event_finder_t(const sc_port_base &p,
2309858Snilay@cs.wisc.edu                      const sc_event & (IF::*_method)() const) :
2319858Snilay@cs.wisc.edu        _method(_method)
2329302Snilay@cs.wisc.edu    {
2339302Snilay@cs.wisc.edu        _port = dynamic_cast<const sc_port_b<IF> *>(&p);
2349302Snilay@cs.wisc.edu        assert(_port);
2359302Snilay@cs.wisc.edu    }
23611021Sjthestness@gmail.com
23711021Sjthestness@gmail.com    virtual ~sc_event_finder_t() {}
2389302Snilay@cs.wisc.edu
2399302Snilay@cs.wisc.edu    const sc_port_base *port() const override { return _port; }
2409302Snilay@cs.wisc.edu
2419302Snilay@cs.wisc.edu    const sc_event &find_event(sc_interface *if_p=NULL) const override;
2429302Snilay@cs.wisc.edu
2439302Snilay@cs.wisc.edu  private:
2449302Snilay@cs.wisc.edu    const sc_port_b<IF> *_port;
2459302Snilay@cs.wisc.edu    const sc_event &(IF::*_method)() const;
2469302Snilay@cs.wisc.edu};
2479302Snilay@cs.wisc.edu
2489302Snilay@cs.wisc.educonst std::vector<sc_event *> &sc_get_top_level_events();
2499302Snilay@cs.wisc.edusc_event *sc_find_event(const char *);
2509858Snilay@cs.wisc.edu
2519858Snilay@cs.wisc.edu} // namespace sc_core
2529302Snilay@cs.wisc.edu
2539302Snilay@cs.wisc.edunamespace sc_gem5
25411021Sjthestness@gmail.com{
25511021Sjthestness@gmail.com
2569302Snilay@cs.wisc.educlass InternalScEvent : public ::sc_core::sc_event
2579302Snilay@cs.wisc.edu{
2589302Snilay@cs.wisc.edu  public:
259    InternalScEvent();
260    InternalScEvent(const char *);
261};
262
263} // namespace sc_gem5
264
265namespace sc_core
266{
267
268template <class IF>
269const sc_event &
270sc_event_finder_t<IF>::find_event(sc_interface *if_p) const
271{
272    static const sc_gem5::InternalScEvent none;
273    const IF *iface = if_p ? dynamic_cast<const IF *>(if_p) :
274        dynamic_cast<const IF *>(_port->get_interface());
275    if (!iface) {
276        std::ostringstream ss;
277        ss << "port is not bound: port '" << _port->name() << "' (" <<
278            _port->kind() << ")";
279        SC_REPORT_ERROR(SC_ID_FIND_EVENT_, ss.str().c_str());
280        return none;
281    }
282    return (const_cast<IF *>(iface)->*_method)();
283}
284
285} // namespace sc_core
286
287#endif  //__SYSTEMC_EXT_CORE_SC_INTERFACE_HH__
288