sc_event.hh revision 13303:045f002c325c
1/* 2 * Copyright 2018 Google, Inc. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: redistributions of source code must retain the above copyright 7 * notice, this list of conditions and the following disclaimer; 8 * redistributions in binary form must reproduce the above copyright 9 * notice, this list of conditions and the following disclaimer in the 10 * documentation and/or other materials provided with the distribution; 11 * neither the name of the copyright holders nor the names of its 12 * contributors may be used to endorse or promote products derived from 13 * this software without specific prior written permission. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * 27 * Authors: Gabe Black 28 */ 29 30#ifndef __SYSTEMC_EXT_CORE_SC_EVENT_HH__ 31#define __SYSTEMC_EXT_CORE_SC_EVENT_HH__ 32 33#include <cassert> 34#include <set> 35#include <sstream> 36#include <vector> 37 38#include "../utils/sc_report_handler.hh" 39#include "sc_port.hh" 40#include "sc_time.hh" 41 42namespace sc_gem5 43{ 44 45class Event; 46class DynamicSensitivityEventAndList; 47class DynamicSensitivityEventOrList; 48class InternalScEvent; 49 50} 51 52namespace sc_core 53{ 54 55class sc_event; 56class sc_event_and_expr; 57class sc_event_or_expr; 58class sc_interface; 59class sc_object; 60class sc_port_base; 61 62class sc_event_and_list 63{ 64 public: 65 sc_event_and_list(); 66 sc_event_and_list(const sc_event_and_list &); 67 sc_event_and_list(const sc_event &); 68 sc_event_and_list &operator = (const sc_event_and_list &); 69 ~sc_event_and_list(); 70 71 int size() const; 72 void swap(sc_event_and_list &); 73 74 sc_event_and_list &operator &= (const sc_event &); 75 sc_event_and_list &operator &= (const sc_event_and_list &); 76 77 sc_event_and_expr operator & (const sc_event &) const; 78 sc_event_and_expr operator & (const sc_event_and_list &); 79 80 private: 81 friend class sc_event_and_expr; 82 friend class sc_gem5::DynamicSensitivityEventAndList; 83 84 explicit sc_event_and_list(bool auto_delete); 85 86 void insert(sc_event const &e); 87 void insert(sc_event_and_list const &eal); 88 89 std::set<const sc_event *> events; 90 bool autoDelete; 91 mutable unsigned busy; 92}; 93 94class sc_event_or_list 95{ 96 public: 97 sc_event_or_list(); 98 sc_event_or_list(const sc_event_or_list &); 99 sc_event_or_list(const sc_event &); 100 sc_event_or_list& operator = (const sc_event_or_list &); 101 ~sc_event_or_list(); 102 103 int size() const; 104 void swap(sc_event_or_list &); 105 106 sc_event_or_list &operator |= (const sc_event &); 107 sc_event_or_list &operator |= (const sc_event_or_list &); 108 109 sc_event_or_expr operator | (const sc_event &) const; 110 sc_event_or_expr operator | (const sc_event_or_list &) const; 111 112 private: 113 friend class sc_event_or_expr; 114 friend class sc_gem5::DynamicSensitivityEventOrList; 115 116 explicit sc_event_or_list(bool auto_delete); 117 118 void insert(sc_event const &e); 119 void insert(sc_event_or_list const &eol); 120 121 std::set<const sc_event *> events; 122 bool autoDelete; 123 mutable unsigned busy; 124}; 125 126class sc_event_and_expr 127{ 128 public: 129 sc_event_and_expr(sc_event_and_expr const &e); 130 operator const sc_event_and_list &() const; 131 132 void insert(sc_event const &e) const; 133 void insert(sc_event_and_list const &eal) const; 134 135 ~sc_event_and_expr(); 136 137 private: 138 friend class sc_event_and_list; 139 friend class sc_event; 140 141 sc_event_and_expr(); 142 mutable sc_event_and_list *list; 143}; 144 145sc_event_and_expr operator & (sc_event_and_expr, sc_event const &); 146sc_event_and_expr operator & (sc_event_and_expr, sc_event_and_list const &); 147 148class sc_event_or_expr 149{ 150 public: 151 sc_event_or_expr(sc_event_or_expr const &e); 152 operator const sc_event_or_list &() const; 153 154 void insert(sc_event const &e) const; 155 void insert(sc_event_or_list const &eol) const; 156 157 ~sc_event_or_expr(); 158 159 private: 160 friend class sc_event_or_list; 161 friend class sc_event; 162 163 sc_event_or_expr(); 164 mutable sc_event_or_list *list; 165}; 166 167sc_event_or_expr operator | (sc_event_or_expr, sc_event const &); 168sc_event_or_expr operator | (sc_event_or_expr, sc_event_or_list const &); 169 170class sc_event 171{ 172 public: 173 sc_event(); 174 explicit sc_event(const char *); 175 ~sc_event(); 176 177 const char *name() const; 178 const char *basename() const; 179 bool in_hierarchy() const; 180 sc_object *get_parent_object() const; 181 182 void notify(); 183 void notify(const sc_time &); 184 void notify(double, sc_time_unit); 185 void cancel(); 186 187 // Nonstandard 188 // Returns whether this event is currently triggered. 189 bool triggered() const; 190 191 // Deprecated 192 void notify_delayed(); 193 void notify_delayed(const sc_time &); 194 195 sc_event_and_expr operator & (const sc_event &) const; 196 sc_event_and_expr operator & (const sc_event_and_list &) const; 197 sc_event_or_expr operator | (const sc_event &) const; 198 sc_event_or_expr operator | (const sc_event_or_list &) const; 199 200 protected: 201 explicit sc_event(bool); 202 explicit sc_event(bool, const char *); 203 204 private: 205 // Disabled 206 sc_event(const sc_event &) {} 207 sc_event &operator = (const sc_event &) { return *this; } 208 209 friend class ::sc_gem5::Event; 210 ::sc_gem5::Event *_gem5_event; 211}; 212 213class sc_event_finder 214{ 215 protected: 216 virtual ~sc_event_finder() {} 217 218 public: 219 // Should be "implementation defined" but used in the tests. 220 virtual const sc_event &find_event(sc_interface *if_p=NULL) const = 0; 221 virtual const sc_port_base *port() const = 0; 222}; 223 224template <class IF> 225class sc_event_finder_t : public sc_event_finder 226{ 227 public: 228 sc_event_finder_t(const sc_port_base &p, 229 const sc_event & (IF::*_method)() const) : 230 _method(_method) 231 { 232 _port = dynamic_cast<const sc_port_b<IF> *>(&p); 233 assert(_port); 234 } 235 236 virtual ~sc_event_finder_t() {} 237 238 const sc_port_base *port() const { return _port; } 239 240 const sc_event & 241 find_event(sc_interface *if_p=NULL) const override 242 { 243 static const sc_gem5::InternalScEvent none; 244 const IF *iface = if_p ? dynamic_cast<const IF *>(if_p) : 245 dynamic_cast<const IF *>(_port->get_interface()); 246 if (!iface) { 247 std::ostringstream ss; 248 ss << "port is not bound: port '" << _port->name() << "' (" << 249 _port->kind() << ")"; 250 SC_REPORT_ERROR("(E118) find event failed", ss.str().c_str()); 251 return none; 252 } 253 return (const_cast<IF *>(iface)->*_method)(); 254 } 255 256 private: 257 const sc_port_b<IF> *_port; 258 const sc_event &(IF::*_method)() const; 259}; 260 261const std::vector<sc_event *> &sc_get_top_level_events(); 262sc_event *sc_find_event(const char *); 263 264} // namespace sc_core 265 266namespace sc_gem5 267{ 268 269class InternalScEvent : public ::sc_core::sc_event 270{ 271 public: 272 InternalScEvent(); 273 InternalScEvent(const char *); 274}; 275 276} // namespace sc_gem5 277 278#endif //__SYSTEMC_EXT_CORE_SC_INTERFACE_HH__ 279