sc_event.hh revision 13051
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 <vector> 36 37#include "sc_port.hh" 38#include "sc_time.hh" 39 40namespace sc_gem5 41{ 42 43class Event; 44class SensitivityEventAndList; 45class SensitivityEventOrList; 46 47} 48 49namespace sc_core 50{ 51 52class sc_event; 53class sc_event_and_expr; 54class sc_event_or_expr; 55class sc_interface; 56class sc_object; 57class sc_port_base; 58 59class sc_event_finder 60{ 61 protected: 62 void warn_unimpl(const char *func) const; 63 virtual ~sc_event_finder() {} 64 65 public: 66 // Should be "implementation defined" but used in the tests. 67 virtual const sc_event &find_event(sc_interface *if_p=NULL) const = 0; 68}; 69 70template <class IF> 71class sc_event_finder_t : public sc_event_finder 72{ 73 public: 74 sc_event_finder_t(const sc_port_base &p, 75 const sc_event & (IF::*_method)() const) : 76 _method(_method) 77 { 78 _port = dynamic_cast<const sc_port_b<IF> *>(&p); 79 assert(_port); 80 } 81 82 virtual ~sc_event_finder_t() {} 83 84 const sc_event & 85 find_event(sc_interface *if_p=NULL) const override 86 { 87 const IF *iface = if_p ? dynamic_cast<const IF *>(if_p) : 88 dynamic_cast<const IF *>(_port->get_interface()); 89 return (const_cast<IF *>(iface)->*_method)(); 90 } 91 92 private: 93 const sc_port_b<IF> *_port; 94 const sc_event &(IF::*_method)() const; 95}; 96 97class sc_event_and_list 98{ 99 public: 100 sc_event_and_list(); 101 sc_event_and_list(const sc_event_and_list &); 102 sc_event_and_list(const sc_event &); 103 sc_event_and_list &operator = (const sc_event_and_list &); 104 ~sc_event_and_list(); 105 106 int size() const; 107 void swap(sc_event_and_list &); 108 109 sc_event_and_list &operator &= (const sc_event &); 110 sc_event_and_list &operator &= (const sc_event_and_list &); 111 112 sc_event_and_expr operator & (const sc_event &) const; 113 sc_event_and_expr operator & (const sc_event_and_list &); 114 115 private: 116 friend class sc_event_and_expr; 117 friend class sc_gem5::SensitivityEventAndList; 118 119 explicit sc_event_and_list(bool auto_delete); 120 121 void insert(sc_event const &e); 122 void insert(sc_event_and_list const &eal); 123 124 std::set<const sc_event *> events; 125 bool autoDelete; 126 mutable unsigned busy; 127}; 128 129class sc_event_or_list 130{ 131 public: 132 sc_event_or_list(); 133 sc_event_or_list(const sc_event_or_list &); 134 sc_event_or_list(const sc_event &); 135 sc_event_or_list& operator = (const sc_event_or_list &); 136 ~sc_event_or_list(); 137 138 int size() const; 139 void swap(sc_event_or_list &); 140 141 sc_event_or_list &operator |= (const sc_event &); 142 sc_event_or_list &operator |= (const sc_event_or_list &); 143 144 sc_event_or_expr operator | (const sc_event &) const; 145 sc_event_or_expr operator | (const sc_event_or_list &) const; 146 147 private: 148 friend class sc_event_or_expr; 149 friend class sc_gem5::SensitivityEventOrList; 150 151 explicit sc_event_or_list(bool auto_delete); 152 153 void insert(sc_event const &e); 154 void insert(sc_event_or_list const &eol); 155 156 std::set<const sc_event *> events; 157 bool autoDelete; 158 mutable unsigned busy; 159}; 160 161class sc_event_and_expr 162{ 163 public: 164 sc_event_and_expr(sc_event_and_expr const &e); 165 operator const sc_event_and_list &() const; 166 167 void insert(sc_event const &e) const; 168 void insert(sc_event_and_list const &eal) const; 169 170 ~sc_event_and_expr(); 171 172 private: 173 friend class sc_event_and_list; 174 friend class sc_event; 175 176 sc_event_and_expr(); 177 mutable sc_event_and_list *list; 178}; 179 180sc_event_and_expr operator & (sc_event_and_expr, sc_event const &); 181sc_event_and_expr operator & (sc_event_and_expr, sc_event_and_list const &); 182 183class sc_event_or_expr 184{ 185 public: 186 sc_event_or_expr(sc_event_or_expr const &e); 187 operator const sc_event_or_list &() const; 188 189 void insert(sc_event const &e) const; 190 void insert(sc_event_or_list const &eol) const; 191 192 ~sc_event_or_expr(); 193 194 private: 195 friend class sc_event_or_list; 196 friend class sc_event; 197 198 sc_event_or_expr(); 199 mutable sc_event_or_list *list; 200}; 201 202sc_event_or_expr operator | (sc_event_or_expr, sc_event const &); 203sc_event_or_expr operator | (sc_event_or_expr, sc_event_or_list const &); 204 205class sc_event 206{ 207 public: 208 sc_event(); 209 explicit sc_event(const char *); 210 ~sc_event(); 211 212 const char *name() const; 213 const char *basename() const; 214 bool in_hierarchy() const; 215 sc_object *get_parent_object() const; 216 217 void notify(); 218 void notify(const sc_time &); 219 void notify(double, sc_time_unit); 220 void cancel(); 221 222 // Nonstandard 223 // Returns whether this event is currently triggered. 224 bool triggered() const; 225 226 // Deprecated 227 void notify_delayed(); 228 void notify_delayed(const sc_time &); 229 230 sc_event_and_expr operator & (const sc_event &) const; 231 sc_event_and_expr operator & (const sc_event_and_list &) const; 232 sc_event_or_expr operator | (const sc_event &) const; 233 sc_event_or_expr operator | (const sc_event_or_list &) const; 234 235 private: 236 // Disabled 237 sc_event(const sc_event &) {} 238 sc_event &operator = (const sc_event &) { return *this; } 239 240 friend class ::sc_gem5::Event; 241 ::sc_gem5::Event *_gem5_event; 242}; 243 244const std::vector<sc_event *> &sc_get_top_level_events(); 245sc_event *sc_find_event(const char *); 246 247} // namespace sc_core 248 249#endif //__SYSTEMC_EXT_CORE_SC_INTERFACE_HH__ 250