00001 /***************************************************************************** 00002 00003 The following code is derived, directly or indirectly, from the SystemC 00004 source code Copyright (c) 1996-2014 by all Contributors. 00005 All Rights reserved. 00006 00007 The contents of this file are subject to the restrictions and limitations 00008 set forth in the SystemC Open Source License (the "License"); 00009 You may not use this file except in compliance with such restrictions and 00010 limitations. You may obtain instructions on how to receive a copy of the 00011 License at http://www.accellera.org/. Software distributed by Contributors 00012 under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF 00013 ANY KIND, either express or implied. See the License for the specific 00014 language governing rights and limitations under the License. 00015 00016 *****************************************************************************/ 00017 00018 /***************************************************************************** 00019 00020 sc_cor_fiber.h -- Coroutine implementation with fibers. 00021 00022 Original Author: Martin Janssen, Synopsys, Inc., 2001-12-18 00023 00024 CHANGE LOG AT THE END OF THE FILE 00025 *****************************************************************************/ 00026 00027 00028 #ifndef SC_COR_FIBER_H 00029 #define SC_COR_FIBER_H 00030 00031 #if defined(_WIN32) || defined(WIN32) || defined(WIN64) 00032 00033 #include "sysc/kernel/sc_cor.h" 00034 #include "sysc/kernel/sc_cmnhdr.h" 00035 00036 #if defined(__GNUC__) && __USING_SJLJ_EXCEPTIONS__ 00037 // _Unwind_SjLj_Register() & _Unwind_SjLj_Unregister() only need first field. 00038 struct SjLj_Function_Context { 00039 struct SjLj_Function_Context *prev; 00040 }; 00041 #endif 00042 00043 namespace sc_core { 00044 00045 class sc_cor_pkg_fiber; 00046 typedef sc_cor_pkg_fiber sc_cor_pkg_t; 00047 00048 #if( defined(_MSC_VER) && _MSC_VER >= 1300 ) 00049 typedef std::size_t size_t; 00050 #endif 00051 00052 // ---------------------------------------------------------------------------- 00053 // CLASS : sc_cor_fiber 00054 // 00055 // Coroutine class implemented with QuickThreads. 00056 // ---------------------------------------------------------------------------- 00057 00058 class sc_cor_fiber 00059 : public sc_cor 00060 { 00061 00062 public: 00063 00064 // constructor 00065 sc_cor_fiber() 00066 : m_stack_size( 0 ), m_fiber( 0 ), m_pkg( 0 ) 00067 { 00068 # if defined(__GNUC__) && __USING_SJLJ_EXCEPTIONS__ 00069 m_eh.prev = 0; 00070 # endif 00071 } 00072 00073 // destructor 00074 virtual ~sc_cor_fiber(); 00075 00076 public: 00077 00078 std::size_t m_stack_size; // stack size 00079 void* m_fiber; // fiber 00080 00081 sc_cor_pkg_fiber* m_pkg; // the creating coroutine package 00082 #if defined(__GNUC__) && __USING_SJLJ_EXCEPTIONS__ 00083 struct SjLj_Function_Context m_eh; // the exception handling context 00084 #endif 00085 00086 00087 private: 00088 00089 // disabled 00090 sc_cor_fiber( const sc_cor_fiber& ); 00091 sc_cor_fiber& operator = ( const sc_cor_fiber& ); 00092 }; 00093 00094 00095 // ---------------------------------------------------------------------------- 00096 // CLASS : sc_cor_pkg_fiber 00097 // 00098 // Coroutine package class implemented with QuickThreads. 00099 // ---------------------------------------------------------------------------- 00100 00101 class sc_cor_pkg_fiber 00102 : public sc_cor_pkg 00103 { 00104 public: 00105 00106 // constructor 00107 sc_cor_pkg_fiber( sc_simcontext* simc ); 00108 00109 // destructor 00110 virtual ~sc_cor_pkg_fiber(); 00111 00112 // create a new coroutine 00113 virtual sc_cor* create( std::size_t stack_size, sc_cor_fn* fn, void* arg ); 00114 00115 // yield to the next coroutine 00116 virtual void yield( sc_cor* next_cor ); 00117 00118 // abort the current coroutine (and resume the next coroutine) 00119 virtual void abort( sc_cor* next_cor ); 00120 00121 // get the main coroutine 00122 virtual sc_cor* get_main(); 00123 00124 private: 00125 00126 static int instance_count; 00127 00128 private: 00129 00130 // disabled 00131 sc_cor_pkg_fiber(); 00132 sc_cor_pkg_fiber( const sc_cor_pkg_fiber& ); 00133 sc_cor_pkg_fiber& operator = ( const sc_cor_pkg_fiber& ); 00134 }; 00135 00136 } // namespace sc_core 00137 00138 #endif // WIN32 00139 00140 // $Log: sc_cor_fiber.h,v $ 00141 // Revision 1.6 2011/08/26 20:46:09 acg 00142 // Andy Goodrich: moved the modification log to the end of the file to 00143 // eliminate source line number skew when check-ins are done. 00144 // 00145 // Revision 1.5 2011/06/25 17:08:39 acg 00146 // Andy Goodrich: Jerome Cornet's changes to use libtool to build the 00147 // library. 00148 // 00149 // Revision 1.4 2011/02/18 20:27:14 acg 00150 // Andy Goodrich: Updated Copyrights. 00151 // 00152 // Revision 1.3 2011/02/13 21:47:37 acg 00153 // Andy Goodrich: update copyright notice. 00154 // 00155 // Revision 1.2 2008/05/22 17:06:25 acg 00156 // Andy Goodrich: updated copyright notice to include 2008. 00157 // 00158 // Revision 1.1.1.1 2006/12/15 20:20:05 acg 00159 // SystemC 2.3 00160 // 00161 // Revision 1.3 2006/01/13 18:44:29 acg 00162 // Added $Log to record CVS changes into the source. 00163 // 00164 00165 #endif 00166 00167 // Taf!