sc_event.hh revision 13206
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; 4413206Sgabeblack@google.comclass DynamicSensitivityEventAndList; 4513206Sgabeblack@google.comclass DynamicSensitivityEventOrList; 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: 6213051Sgabeblack@google.com virtual ~sc_event_finder() {} 6312924Sgabeblack@google.com 6412924Sgabeblack@google.com public: 6512924Sgabeblack@google.com // Should be "implementation defined" but used in the tests. 6612924Sgabeblack@google.com virtual const sc_event &find_event(sc_interface *if_p=NULL) const = 0; 6713132Sgabeblack@google.com virtual const sc_port_base *port() 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 8413132Sgabeblack@google.com const sc_port_base *port() const { return _port; } 8513132Sgabeblack@google.com 8612924Sgabeblack@google.com const sc_event & 8712924Sgabeblack@google.com find_event(sc_interface *if_p=NULL) const override 8812924Sgabeblack@google.com { 8913051Sgabeblack@google.com const IF *iface = if_p ? dynamic_cast<const IF *>(if_p) : 9013051Sgabeblack@google.com dynamic_cast<const IF *>(_port->get_interface()); 9113051Sgabeblack@google.com return (const_cast<IF *>(iface)->*_method)(); 9212924Sgabeblack@google.com } 9313051Sgabeblack@google.com 9413051Sgabeblack@google.com private: 9513051Sgabeblack@google.com const sc_port_b<IF> *_port; 9613051Sgabeblack@google.com const sc_event &(IF::*_method)() const; 9712837Sgabeblack@google.com}; 9812837Sgabeblack@google.com 9912837Sgabeblack@google.comclass sc_event_and_list 10012837Sgabeblack@google.com{ 10112837Sgabeblack@google.com public: 10212837Sgabeblack@google.com sc_event_and_list(); 10312837Sgabeblack@google.com sc_event_and_list(const sc_event_and_list &); 10412837Sgabeblack@google.com sc_event_and_list(const sc_event &); 10512837Sgabeblack@google.com sc_event_and_list &operator = (const sc_event_and_list &); 10612955Sgabeblack@google.com ~sc_event_and_list(); 10712837Sgabeblack@google.com 10812837Sgabeblack@google.com int size() const; 10912837Sgabeblack@google.com void swap(sc_event_and_list &); 11012837Sgabeblack@google.com 11112837Sgabeblack@google.com sc_event_and_list &operator &= (const sc_event &); 11212837Sgabeblack@google.com sc_event_and_list &operator &= (const sc_event_and_list &); 11312837Sgabeblack@google.com 11412837Sgabeblack@google.com sc_event_and_expr operator & (const sc_event &) const; 11512837Sgabeblack@google.com sc_event_and_expr operator & (const sc_event_and_list &); 11612955Sgabeblack@google.com 11712955Sgabeblack@google.com private: 11812955Sgabeblack@google.com friend class sc_event_and_expr; 11913206Sgabeblack@google.com friend class sc_gem5::DynamicSensitivityEventAndList; 12012955Sgabeblack@google.com 12112955Sgabeblack@google.com explicit sc_event_and_list(bool auto_delete); 12212955Sgabeblack@google.com 12312955Sgabeblack@google.com void insert(sc_event const &e); 12412955Sgabeblack@google.com void insert(sc_event_and_list const &eal); 12512955Sgabeblack@google.com 12612955Sgabeblack@google.com std::set<const sc_event *> events; 12712955Sgabeblack@google.com bool autoDelete; 12812955Sgabeblack@google.com mutable unsigned busy; 12912837Sgabeblack@google.com}; 13012837Sgabeblack@google.com 13112837Sgabeblack@google.comclass sc_event_or_list 13212837Sgabeblack@google.com{ 13312837Sgabeblack@google.com public: 13412837Sgabeblack@google.com sc_event_or_list(); 13512837Sgabeblack@google.com sc_event_or_list(const sc_event_or_list &); 13612837Sgabeblack@google.com sc_event_or_list(const sc_event &); 13712837Sgabeblack@google.com sc_event_or_list& operator = (const sc_event_or_list &); 13812837Sgabeblack@google.com ~sc_event_or_list(); 13912837Sgabeblack@google.com 14012837Sgabeblack@google.com int size() const; 14112837Sgabeblack@google.com void swap(sc_event_or_list &); 14212837Sgabeblack@google.com 14312837Sgabeblack@google.com sc_event_or_list &operator |= (const sc_event &); 14412837Sgabeblack@google.com sc_event_or_list &operator |= (const sc_event_or_list &); 14512837Sgabeblack@google.com 14612837Sgabeblack@google.com sc_event_or_expr operator | (const sc_event &) const; 14712837Sgabeblack@google.com sc_event_or_expr operator | (const sc_event_or_list &) const; 14812955Sgabeblack@google.com 14912955Sgabeblack@google.com private: 15012955Sgabeblack@google.com friend class sc_event_or_expr; 15113206Sgabeblack@google.com friend class sc_gem5::DynamicSensitivityEventOrList; 15212955Sgabeblack@google.com 15312955Sgabeblack@google.com explicit sc_event_or_list(bool auto_delete); 15412955Sgabeblack@google.com 15512955Sgabeblack@google.com void insert(sc_event const &e); 15612955Sgabeblack@google.com void insert(sc_event_or_list const &eol); 15712955Sgabeblack@google.com 15812955Sgabeblack@google.com std::set<const sc_event *> events; 15912955Sgabeblack@google.com bool autoDelete; 16012955Sgabeblack@google.com mutable unsigned busy; 16112837Sgabeblack@google.com}; 16212837Sgabeblack@google.com 16312837Sgabeblack@google.comclass sc_event_and_expr 16412837Sgabeblack@google.com{ 16512837Sgabeblack@google.com public: 16612955Sgabeblack@google.com sc_event_and_expr(sc_event_and_expr const &e); 16712837Sgabeblack@google.com operator const sc_event_and_list &() const; 16812955Sgabeblack@google.com 16912955Sgabeblack@google.com void insert(sc_event const &e) const; 17012955Sgabeblack@google.com void insert(sc_event_and_list const &eal) const; 17112955Sgabeblack@google.com 17212955Sgabeblack@google.com ~sc_event_and_expr(); 17312955Sgabeblack@google.com 17412955Sgabeblack@google.com private: 17512955Sgabeblack@google.com friend class sc_event_and_list; 17612955Sgabeblack@google.com friend class sc_event; 17712955Sgabeblack@google.com 17812955Sgabeblack@google.com sc_event_and_expr(); 17912955Sgabeblack@google.com mutable sc_event_and_list *list; 18012837Sgabeblack@google.com}; 18112837Sgabeblack@google.com 18212837Sgabeblack@google.comsc_event_and_expr operator & (sc_event_and_expr, sc_event const &); 18312837Sgabeblack@google.comsc_event_and_expr operator & (sc_event_and_expr, sc_event_and_list const &); 18412837Sgabeblack@google.com 18512837Sgabeblack@google.comclass sc_event_or_expr 18612837Sgabeblack@google.com{ 18712837Sgabeblack@google.com public: 18812955Sgabeblack@google.com sc_event_or_expr(sc_event_or_expr const &e); 18912837Sgabeblack@google.com operator const sc_event_or_list &() const; 19012955Sgabeblack@google.com 19112955Sgabeblack@google.com void insert(sc_event const &e) const; 19212955Sgabeblack@google.com void insert(sc_event_or_list const &eol) const; 19312955Sgabeblack@google.com 19412955Sgabeblack@google.com ~sc_event_or_expr(); 19512955Sgabeblack@google.com 19612955Sgabeblack@google.com private: 19712955Sgabeblack@google.com friend class sc_event_or_list; 19812955Sgabeblack@google.com friend class sc_event; 19912955Sgabeblack@google.com 20012955Sgabeblack@google.com sc_event_or_expr(); 20112955Sgabeblack@google.com mutable sc_event_or_list *list; 20212837Sgabeblack@google.com}; 20312837Sgabeblack@google.com 20412837Sgabeblack@google.comsc_event_or_expr operator | (sc_event_or_expr, sc_event const &); 20512837Sgabeblack@google.comsc_event_or_expr operator | (sc_event_or_expr, sc_event_or_list const &); 20612837Sgabeblack@google.com 20712837Sgabeblack@google.comclass sc_event 20812837Sgabeblack@google.com{ 20912837Sgabeblack@google.com public: 21012837Sgabeblack@google.com sc_event(); 21112837Sgabeblack@google.com explicit sc_event(const char *); 21212837Sgabeblack@google.com ~sc_event(); 21312837Sgabeblack@google.com 21412837Sgabeblack@google.com const char *name() const; 21512837Sgabeblack@google.com const char *basename() const; 21612837Sgabeblack@google.com bool in_hierarchy() const; 21712837Sgabeblack@google.com sc_object *get_parent_object() const; 21812837Sgabeblack@google.com 21912837Sgabeblack@google.com void notify(); 22012837Sgabeblack@google.com void notify(const sc_time &); 22112837Sgabeblack@google.com void notify(double, sc_time_unit); 22212837Sgabeblack@google.com void cancel(); 22312837Sgabeblack@google.com 22412900Sgabeblack@google.com // Nonstandard 22512900Sgabeblack@google.com // Returns whether this event is currently triggered. 22612900Sgabeblack@google.com bool triggered() const; 22712900Sgabeblack@google.com 22812915Sgabeblack@google.com // Deprecated 22912915Sgabeblack@google.com void notify_delayed(); 23012915Sgabeblack@google.com void notify_delayed(const sc_time &); 23112915Sgabeblack@google.com 23212837Sgabeblack@google.com sc_event_and_expr operator & (const sc_event &) const; 23312837Sgabeblack@google.com sc_event_and_expr operator & (const sc_event_and_list &) const; 23412837Sgabeblack@google.com sc_event_or_expr operator | (const sc_event &) const; 23512837Sgabeblack@google.com sc_event_or_expr operator | (const sc_event_or_list &) const; 23612837Sgabeblack@google.com 23712837Sgabeblack@google.com private: 23812837Sgabeblack@google.com // Disabled 23912837Sgabeblack@google.com sc_event(const sc_event &) {} 24012837Sgabeblack@google.com sc_event &operator = (const sc_event &) { return *this; } 24112955Sgabeblack@google.com 24212955Sgabeblack@google.com friend class ::sc_gem5::Event; 24312955Sgabeblack@google.com ::sc_gem5::Event *_gem5_event; 24412837Sgabeblack@google.com}; 24512837Sgabeblack@google.com 24612837Sgabeblack@google.comconst std::vector<sc_event *> &sc_get_top_level_events(); 24712837Sgabeblack@google.comsc_event *sc_find_event(const char *); 24812837Sgabeblack@google.com 24912837Sgabeblack@google.com} // namespace sc_core 25012837Sgabeblack@google.com 25112837Sgabeblack@google.com#endif //__SYSTEMC_EXT_CORE_SC_INTERFACE_HH__ 252