sc_cor_fiber.h revision 12027
1/***************************************************************************** 2 3 Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 4 more contributor license agreements. See the NOTICE file distributed 5 with this work for additional information regarding copyright ownership. 6 Accellera licenses this file to you under the Apache License, Version 2.0 7 (the "License"); you may not use this file except in compliance with the 8 License. You may obtain a copy of the License at 9 10 http://www.apache.org/licenses/LICENSE-2.0 11 12 Unless required by applicable law or agreed to in writing, software 13 distributed under the License is distributed on an "AS IS" BASIS, 14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 15 implied. See the License for the specific language governing 16 permissions and limitations under the License. 17 18 *****************************************************************************/ 19 20/***************************************************************************** 21 22 sc_cor_fiber.h -- Coroutine implementation with fibers. 23 24 Original Author: Martin Janssen, Synopsys, Inc., 2001-12-18 25 26 CHANGE LOG AT THE END OF THE FILE 27 *****************************************************************************/ 28 29 30#ifndef SC_COR_FIBER_H 31#define SC_COR_FIBER_H 32 33#if defined(_WIN32) || defined(WIN32) || defined(WIN64) 34 35#include "sysc/kernel/sc_cor.h" 36#include "sysc/kernel/sc_cmnhdr.h" 37 38#if defined(__GNUC__) && __USING_SJLJ_EXCEPTIONS__ 39 // _Unwind_SjLj_Register() & _Unwind_SjLj_Unregister() only need first field. 40 struct SjLj_Function_Context { 41 struct SjLj_Function_Context *prev; 42 }; 43#endif 44 45namespace sc_core { 46 47class sc_cor_pkg_fiber; 48typedef sc_cor_pkg_fiber sc_cor_pkg_t; 49 50#if( defined(_MSC_VER) && _MSC_VER >= 1300 ) 51typedef std::size_t size_t; 52#endif 53 54// ---------------------------------------------------------------------------- 55// CLASS : sc_cor_fiber 56// 57// Coroutine class implemented with QuickThreads. 58// ---------------------------------------------------------------------------- 59 60class sc_cor_fiber 61: public sc_cor 62{ 63 64public: 65 66 // constructor 67 sc_cor_fiber() 68 : m_stack_size( 0 ), m_fiber( 0 ), m_pkg( 0 ) 69 { 70# if defined(__GNUC__) && __USING_SJLJ_EXCEPTIONS__ 71 m_eh.prev = 0; 72# endif 73 } 74 75 // destructor 76 virtual ~sc_cor_fiber(); 77 78public: 79 80 std::size_t m_stack_size; // stack size 81 void* m_fiber; // fiber 82 83 sc_cor_pkg_fiber* m_pkg; // the creating coroutine package 84#if defined(__GNUC__) && __USING_SJLJ_EXCEPTIONS__ 85 struct SjLj_Function_Context m_eh; // the exception handling context 86#endif 87 88 89private: 90 91 // disabled 92 sc_cor_fiber( const sc_cor_fiber& ); 93 sc_cor_fiber& operator = ( const sc_cor_fiber& ); 94}; 95 96 97// ---------------------------------------------------------------------------- 98// CLASS : sc_cor_pkg_fiber 99// 100// Coroutine package class implemented with QuickThreads. 101// ---------------------------------------------------------------------------- 102 103class sc_cor_pkg_fiber 104: public sc_cor_pkg 105{ 106 public: 107 108 // constructor 109 sc_cor_pkg_fiber( sc_simcontext* simc ); 110 111 // destructor 112 virtual ~sc_cor_pkg_fiber(); 113 114 // create a new coroutine 115 virtual sc_cor* create( std::size_t stack_size, sc_cor_fn* fn, void* arg ); 116 117 // yield to the next coroutine 118 virtual void yield( sc_cor* next_cor ); 119 120 // abort the current coroutine (and resume the next coroutine) 121 virtual void abort( sc_cor* next_cor ); 122 123 // get the main coroutine 124 virtual sc_cor* get_main(); 125 126private: 127 128 static int instance_count; 129 130private: 131 132 // disabled 133 sc_cor_pkg_fiber(); 134 sc_cor_pkg_fiber( const sc_cor_pkg_fiber& ); 135 sc_cor_pkg_fiber& operator = ( const sc_cor_pkg_fiber& ); 136}; 137 138} // namespace sc_core 139 140#endif // WIN32 141 142// $Log: sc_cor_fiber.h,v $ 143// Revision 1.6 2011/08/26 20:46:09 acg 144// Andy Goodrich: moved the modification log to the end of the file to 145// eliminate source line number skew when check-ins are done. 146// 147// Revision 1.5 2011/06/25 17:08:39 acg 148// Andy Goodrich: Jerome Cornet's changes to use libtool to build the 149// library. 150// 151// Revision 1.4 2011/02/18 20:27:14 acg 152// Andy Goodrich: Updated Copyrights. 153// 154// Revision 1.3 2011/02/13 21:47:37 acg 155// Andy Goodrich: update copyright notice. 156// 157// Revision 1.2 2008/05/22 17:06:25 acg 158// Andy Goodrich: updated copyright notice to include 2008. 159// 160// Revision 1.1.1.1 2006/12/15 20:20:05 acg 161// SystemC 2.3 162// 163// Revision 1.3 2006/01/13 18:44:29 acg 164// Added $Log to record CVS changes into the source. 165// 166 167#endif 168 169// Taf! 170