sc_event.hh revision 13294
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> 3513294Sgabeblack@google.com#include <sstream> 3612837Sgabeblack@google.com#include <vector> 3712837Sgabeblack@google.com 3813294Sgabeblack@google.com#include "../utils/sc_report_handler.hh" 3913051Sgabeblack@google.com#include "sc_port.hh" 4012837Sgabeblack@google.com#include "sc_time.hh" 4112837Sgabeblack@google.com 4212955Sgabeblack@google.comnamespace sc_gem5 4312955Sgabeblack@google.com{ 4412955Sgabeblack@google.com 4512955Sgabeblack@google.comclass Event; 4613206Sgabeblack@google.comclass DynamicSensitivityEventAndList; 4713206Sgabeblack@google.comclass DynamicSensitivityEventOrList; 4812955Sgabeblack@google.com 4912955Sgabeblack@google.com} 5012955Sgabeblack@google.com 5112837Sgabeblack@google.comnamespace sc_core 5212837Sgabeblack@google.com{ 5312837Sgabeblack@google.com 5412837Sgabeblack@google.comclass sc_event; 5512837Sgabeblack@google.comclass sc_event_and_expr; 5612837Sgabeblack@google.comclass sc_event_or_expr; 5712924Sgabeblack@google.comclass sc_interface; 5812837Sgabeblack@google.comclass sc_object; 5912837Sgabeblack@google.comclass sc_port_base; 6012837Sgabeblack@google.com 6112837Sgabeblack@google.comclass sc_event_and_list 6212837Sgabeblack@google.com{ 6312837Sgabeblack@google.com public: 6412837Sgabeblack@google.com sc_event_and_list(); 6512837Sgabeblack@google.com sc_event_and_list(const sc_event_and_list &); 6612837Sgabeblack@google.com sc_event_and_list(const sc_event &); 6712837Sgabeblack@google.com sc_event_and_list &operator = (const sc_event_and_list &); 6812955Sgabeblack@google.com ~sc_event_and_list(); 6912837Sgabeblack@google.com 7012837Sgabeblack@google.com int size() const; 7112837Sgabeblack@google.com void swap(sc_event_and_list &); 7212837Sgabeblack@google.com 7312837Sgabeblack@google.com sc_event_and_list &operator &= (const sc_event &); 7412837Sgabeblack@google.com sc_event_and_list &operator &= (const sc_event_and_list &); 7512837Sgabeblack@google.com 7612837Sgabeblack@google.com sc_event_and_expr operator & (const sc_event &) const; 7712837Sgabeblack@google.com sc_event_and_expr operator & (const sc_event_and_list &); 7812955Sgabeblack@google.com 7912955Sgabeblack@google.com private: 8012955Sgabeblack@google.com friend class sc_event_and_expr; 8113206Sgabeblack@google.com friend class sc_gem5::DynamicSensitivityEventAndList; 8212955Sgabeblack@google.com 8312955Sgabeblack@google.com explicit sc_event_and_list(bool auto_delete); 8412955Sgabeblack@google.com 8512955Sgabeblack@google.com void insert(sc_event const &e); 8612955Sgabeblack@google.com void insert(sc_event_and_list const &eal); 8712955Sgabeblack@google.com 8812955Sgabeblack@google.com std::set<const sc_event *> events; 8912955Sgabeblack@google.com bool autoDelete; 9012955Sgabeblack@google.com mutable unsigned busy; 9112837Sgabeblack@google.com}; 9212837Sgabeblack@google.com 9312837Sgabeblack@google.comclass sc_event_or_list 9412837Sgabeblack@google.com{ 9512837Sgabeblack@google.com public: 9612837Sgabeblack@google.com sc_event_or_list(); 9712837Sgabeblack@google.com sc_event_or_list(const sc_event_or_list &); 9812837Sgabeblack@google.com sc_event_or_list(const sc_event &); 9912837Sgabeblack@google.com sc_event_or_list& operator = (const sc_event_or_list &); 10012837Sgabeblack@google.com ~sc_event_or_list(); 10112837Sgabeblack@google.com 10212837Sgabeblack@google.com int size() const; 10312837Sgabeblack@google.com void swap(sc_event_or_list &); 10412837Sgabeblack@google.com 10512837Sgabeblack@google.com sc_event_or_list &operator |= (const sc_event &); 10612837Sgabeblack@google.com sc_event_or_list &operator |= (const sc_event_or_list &); 10712837Sgabeblack@google.com 10812837Sgabeblack@google.com sc_event_or_expr operator | (const sc_event &) const; 10912837Sgabeblack@google.com sc_event_or_expr operator | (const sc_event_or_list &) const; 11012955Sgabeblack@google.com 11112955Sgabeblack@google.com private: 11212955Sgabeblack@google.com friend class sc_event_or_expr; 11313206Sgabeblack@google.com friend class sc_gem5::DynamicSensitivityEventOrList; 11412955Sgabeblack@google.com 11512955Sgabeblack@google.com explicit sc_event_or_list(bool auto_delete); 11612955Sgabeblack@google.com 11712955Sgabeblack@google.com void insert(sc_event const &e); 11812955Sgabeblack@google.com void insert(sc_event_or_list const &eol); 11912955Sgabeblack@google.com 12012955Sgabeblack@google.com std::set<const sc_event *> events; 12112955Sgabeblack@google.com bool autoDelete; 12212955Sgabeblack@google.com mutable unsigned busy; 12312837Sgabeblack@google.com}; 12412837Sgabeblack@google.com 12512837Sgabeblack@google.comclass sc_event_and_expr 12612837Sgabeblack@google.com{ 12712837Sgabeblack@google.com public: 12812955Sgabeblack@google.com sc_event_and_expr(sc_event_and_expr const &e); 12912837Sgabeblack@google.com operator const sc_event_and_list &() const; 13012955Sgabeblack@google.com 13112955Sgabeblack@google.com void insert(sc_event const &e) const; 13212955Sgabeblack@google.com void insert(sc_event_and_list const &eal) const; 13312955Sgabeblack@google.com 13412955Sgabeblack@google.com ~sc_event_and_expr(); 13512955Sgabeblack@google.com 13612955Sgabeblack@google.com private: 13712955Sgabeblack@google.com friend class sc_event_and_list; 13812955Sgabeblack@google.com friend class sc_event; 13912955Sgabeblack@google.com 14012955Sgabeblack@google.com sc_event_and_expr(); 14112955Sgabeblack@google.com mutable sc_event_and_list *list; 14212837Sgabeblack@google.com}; 14312837Sgabeblack@google.com 14412837Sgabeblack@google.comsc_event_and_expr operator & (sc_event_and_expr, sc_event const &); 14512837Sgabeblack@google.comsc_event_and_expr operator & (sc_event_and_expr, sc_event_and_list const &); 14612837Sgabeblack@google.com 14712837Sgabeblack@google.comclass sc_event_or_expr 14812837Sgabeblack@google.com{ 14912837Sgabeblack@google.com public: 15012955Sgabeblack@google.com sc_event_or_expr(sc_event_or_expr const &e); 15112837Sgabeblack@google.com operator const sc_event_or_list &() const; 15212955Sgabeblack@google.com 15312955Sgabeblack@google.com void insert(sc_event const &e) const; 15412955Sgabeblack@google.com void insert(sc_event_or_list const &eol) const; 15512955Sgabeblack@google.com 15612955Sgabeblack@google.com ~sc_event_or_expr(); 15712955Sgabeblack@google.com 15812955Sgabeblack@google.com private: 15912955Sgabeblack@google.com friend class sc_event_or_list; 16012955Sgabeblack@google.com friend class sc_event; 16112955Sgabeblack@google.com 16212955Sgabeblack@google.com sc_event_or_expr(); 16312955Sgabeblack@google.com mutable sc_event_or_list *list; 16412837Sgabeblack@google.com}; 16512837Sgabeblack@google.com 16612837Sgabeblack@google.comsc_event_or_expr operator | (sc_event_or_expr, sc_event const &); 16712837Sgabeblack@google.comsc_event_or_expr operator | (sc_event_or_expr, sc_event_or_list const &); 16812837Sgabeblack@google.com 16912837Sgabeblack@google.comclass sc_event 17012837Sgabeblack@google.com{ 17112837Sgabeblack@google.com public: 17212837Sgabeblack@google.com sc_event(); 17312837Sgabeblack@google.com explicit sc_event(const char *); 17412837Sgabeblack@google.com ~sc_event(); 17512837Sgabeblack@google.com 17612837Sgabeblack@google.com const char *name() const; 17712837Sgabeblack@google.com const char *basename() const; 17812837Sgabeblack@google.com bool in_hierarchy() const; 17912837Sgabeblack@google.com sc_object *get_parent_object() const; 18012837Sgabeblack@google.com 18112837Sgabeblack@google.com void notify(); 18212837Sgabeblack@google.com void notify(const sc_time &); 18312837Sgabeblack@google.com void notify(double, sc_time_unit); 18412837Sgabeblack@google.com void cancel(); 18512837Sgabeblack@google.com 18612900Sgabeblack@google.com // Nonstandard 18712900Sgabeblack@google.com // Returns whether this event is currently triggered. 18812900Sgabeblack@google.com bool triggered() const; 18912900Sgabeblack@google.com 19012915Sgabeblack@google.com // Deprecated 19112915Sgabeblack@google.com void notify_delayed(); 19212915Sgabeblack@google.com void notify_delayed(const sc_time &); 19312915Sgabeblack@google.com 19412837Sgabeblack@google.com sc_event_and_expr operator & (const sc_event &) const; 19512837Sgabeblack@google.com sc_event_and_expr operator & (const sc_event_and_list &) const; 19612837Sgabeblack@google.com sc_event_or_expr operator | (const sc_event &) const; 19712837Sgabeblack@google.com sc_event_or_expr operator | (const sc_event_or_list &) const; 19812837Sgabeblack@google.com 19912837Sgabeblack@google.com private: 20012837Sgabeblack@google.com // Disabled 20112837Sgabeblack@google.com sc_event(const sc_event &) {} 20212837Sgabeblack@google.com sc_event &operator = (const sc_event &) { return *this; } 20312955Sgabeblack@google.com 20412955Sgabeblack@google.com friend class ::sc_gem5::Event; 20512955Sgabeblack@google.com ::sc_gem5::Event *_gem5_event; 20612837Sgabeblack@google.com}; 20712837Sgabeblack@google.com 20813294Sgabeblack@google.comclass sc_event_finder 20913294Sgabeblack@google.com{ 21013294Sgabeblack@google.com protected: 21113294Sgabeblack@google.com virtual ~sc_event_finder() {} 21213294Sgabeblack@google.com 21313294Sgabeblack@google.com public: 21413294Sgabeblack@google.com // Should be "implementation defined" but used in the tests. 21513294Sgabeblack@google.com virtual const sc_event &find_event(sc_interface *if_p=NULL) const = 0; 21613294Sgabeblack@google.com virtual const sc_port_base *port() const = 0; 21713294Sgabeblack@google.com}; 21813294Sgabeblack@google.com 21913294Sgabeblack@google.comtemplate <class IF> 22013294Sgabeblack@google.comclass sc_event_finder_t : public sc_event_finder 22113294Sgabeblack@google.com{ 22213294Sgabeblack@google.com public: 22313294Sgabeblack@google.com sc_event_finder_t(const sc_port_base &p, 22413294Sgabeblack@google.com const sc_event & (IF::*_method)() const) : 22513294Sgabeblack@google.com _method(_method) 22613294Sgabeblack@google.com { 22713294Sgabeblack@google.com _port = dynamic_cast<const sc_port_b<IF> *>(&p); 22813294Sgabeblack@google.com assert(_port); 22913294Sgabeblack@google.com } 23013294Sgabeblack@google.com 23113294Sgabeblack@google.com virtual ~sc_event_finder_t() {} 23213294Sgabeblack@google.com 23313294Sgabeblack@google.com const sc_port_base *port() const { return _port; } 23413294Sgabeblack@google.com 23513294Sgabeblack@google.com const sc_event & 23613294Sgabeblack@google.com find_event(sc_interface *if_p=NULL) const override 23713294Sgabeblack@google.com { 23813294Sgabeblack@google.com static const sc_event none; 23913294Sgabeblack@google.com const IF *iface = if_p ? dynamic_cast<const IF *>(if_p) : 24013294Sgabeblack@google.com dynamic_cast<const IF *>(_port->get_interface()); 24113294Sgabeblack@google.com if (!iface) { 24213294Sgabeblack@google.com std::ostringstream ss; 24313294Sgabeblack@google.com ss << "port is not bound: port '" << _port->name() << "' (" << 24413294Sgabeblack@google.com _port->kind() << ")"; 24513294Sgabeblack@google.com SC_REPORT_ERROR("(E118) find event failed", ss.str().c_str()); 24613294Sgabeblack@google.com return none; 24713294Sgabeblack@google.com } 24813294Sgabeblack@google.com return (const_cast<IF *>(iface)->*_method)(); 24913294Sgabeblack@google.com } 25013294Sgabeblack@google.com 25113294Sgabeblack@google.com private: 25213294Sgabeblack@google.com const sc_port_b<IF> *_port; 25313294Sgabeblack@google.com const sc_event &(IF::*_method)() const; 25413294Sgabeblack@google.com}; 25513294Sgabeblack@google.com 25612837Sgabeblack@google.comconst std::vector<sc_event *> &sc_get_top_level_events(); 25712837Sgabeblack@google.comsc_event *sc_find_event(const char *); 25812837Sgabeblack@google.com 25912837Sgabeblack@google.com} // namespace sc_core 26012837Sgabeblack@google.com 26112837Sgabeblack@google.com#endif //__SYSTEMC_EXT_CORE_SC_INTERFACE_HH__ 262