sc_spawn.hh revision 12993:977fa1dfe9b3
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_SPAWN_HH__ 31#define __SYSTEMC_EXT_CORE_SC_SPAWN_HH__ 32 33#include <vector> 34 35#include "sc_process_handle.hh" 36 37namespace sc_core 38{ 39 40class sc_spawn_options; 41 42} // namespace sc_core 43 44namespace sc_gem5 45{ 46 47class Process; 48 49template <typename T> 50struct ProcessObjFuncWrapper : public ProcessFuncWrapper 51{ 52 T t; 53 54 ProcessObjFuncWrapper(T t) : t(t) {} 55 56 void call() override { t(); } 57}; 58 59template <typename T, typename R> 60struct ProcessObjRetFuncWrapper : public ProcessFuncWrapper 61{ 62 T t; 63 R *r; 64 65 ProcessObjRetFuncWrapper(T t, R *r) : t(t), r(r) {} 66 67 void call() override { *r = t(); } 68}; 69 70Process *spawnWork(ProcessFuncWrapper *func, const char *name, 71 const ::sc_core::sc_spawn_options *); 72 73} // namespace sc_gem5 74 75namespace sc_core 76{ 77 78template <class T> 79class sc_in; 80template <class T> 81class sc_inout; 82template <class T> 83class sc_out; 84template <class T> 85class sc_signal_in_if; 86 87class sc_event; 88class sc_event_finder; 89class sc_export_base; 90class sc_interface; 91class sc_port_base; 92 93class sc_spawn_options 94{ 95 public: 96 friend ::sc_gem5::Process *::sc_gem5::spawnWork( 97 ::sc_gem5::ProcessFuncWrapper *, const char *, 98 const sc_spawn_options *); 99 100 sc_spawn_options(); 101 102 void spawn_method(); 103 void dont_initialize(); 104 void set_stack_size(int); 105 106 void set_sensitivity(const sc_event *); 107 void set_sensitivity(sc_port_base *); 108 void set_sensitivity(sc_export_base *); 109 void set_sensitivity(sc_interface *); 110 void set_sensitivity(sc_event_finder *); 111 112 void reset_signal_is(const sc_in<bool> &, bool); 113 void reset_signal_is(const sc_inout<bool> &, bool); 114 void reset_signal_is(const sc_out<bool> &, bool); 115 void reset_signal_is(const sc_signal_in_if<bool> &, bool); 116 117 void async_reset_signal_is(const sc_in<bool> &, bool); 118 void async_reset_signal_is(const sc_inout<bool> &, bool); 119 void async_reset_signal_is(const sc_out<bool> &, bool); 120 void async_reset_signal_is(const sc_signal_in_if<bool> &, bool); 121 122 private: 123 bool _spawnMethod; 124 bool _dontInitialize; 125 int _stackSize; 126 std::vector<const sc_event *> _events; 127 std::vector<sc_port_base *> _ports; 128 std::vector<sc_export_base *> _exports; 129 std::vector<sc_interface *> _interfaces; 130 std::vector<sc_event_finder *> _finders; 131 132 // Disabled 133 sc_spawn_options(const sc_spawn_options &) {} 134 sc_spawn_options &operator = (const sc_spawn_options &) { return *this; } 135}; 136 137void sc_spawn_warn_unimpl(const char *func); 138 139template <typename T> 140sc_process_handle 141sc_spawn(T object, const char *name_p=nullptr, 142 const sc_spawn_options *opt_p=nullptr) 143{ 144 auto func = new ::sc_gem5::ProcessObjFuncWrapper<T>(object); 145 ::sc_gem5::Process *p = spawnWork(func, name_p, opt_p); 146 return sc_process_handle() = p; 147} 148 149template <typename T> 150sc_process_handle 151sc_spawn(typename T::result_type *r_p, T object, const char *name_p=nullptr, 152 const sc_spawn_options *opt_p=nullptr) 153{ 154 auto func = new ::sc_gem5::ProcessObjRetFuncWrapper< 155 T, typename T::result_type>(object, r_p); 156 ::sc_gem5::Process *p = spawnWork(func, name_p, opt_p); 157 return sc_process_handle() = p; 158} 159 160#define sc_bind boost::bind 161#define sc_ref(r) boost::ref(r) 162#define sc_cref(r) boost::cref(r) 163 164#define SC_FORK \ 165{ \ 166 ::sc_core::sc_process_handle forkees[] = { 167 168#define SC_JOIN \ 169 }; /* TODO wait for the forkees. */ \ 170} 171 172// Non-standard 173#define SC_CJOIN SC_JOIN 174 175} // namespace sc_core 176 177namespace sc_unnamed 178{ 179 180typedef int ImplementationDefined; 181extern ImplementationDefined _1; 182extern ImplementationDefined _2; 183extern ImplementationDefined _3; 184extern ImplementationDefined _4; 185extern ImplementationDefined _5; 186extern ImplementationDefined _6; 187extern ImplementationDefined _7; 188extern ImplementationDefined _8; 189extern ImplementationDefined _9; 190 191} // namespace sc_unnamed 192 193#endif //__SYSTEMC_EXT_CORE_SC_SPAWN_HH__ 194