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