sc_cor_fiber.h revision 12027
12686Sksewell@umich.edu/*****************************************************************************
25222Sksewell@umich.edu
32686Sksewell@umich.edu  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
45222Sksewell@umich.edu  more contributor license agreements.  See the NOTICE file distributed
52686Sksewell@umich.edu  with this work for additional information regarding copyright ownership.
65222Sksewell@umich.edu  Accellera licenses this file to you under the Apache License, Version 2.0
75222Sksewell@umich.edu  (the "License"); you may not use this file except in compliance with the
85222Sksewell@umich.edu  License.  You may obtain a copy of the License at
92706Sksewell@umich.edu
105222Sksewell@umich.edu    http://www.apache.org/licenses/LICENSE-2.0
115222Sksewell@umich.edu
125222Sksewell@umich.edu  Unless required by applicable law or agreed to in writing, software
135222Sksewell@umich.edu  distributed under the License is distributed on an "AS IS" BASIS,
145222Sksewell@umich.edu  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
155222Sksewell@umich.edu  implied.  See the License for the specific language governing
165222Sksewell@umich.edu  permissions and limitations under the License.
175222Sksewell@umich.edu
185222Sksewell@umich.edu *****************************************************************************/
195222Sksewell@umich.edu
205222Sksewell@umich.edu/*****************************************************************************
215222Sksewell@umich.edu
225222Sksewell@umich.edu  sc_cor_fiber.h -- Coroutine implementation with fibers.
235222Sksewell@umich.edu
245222Sksewell@umich.edu  Original Author: Martin Janssen, Synopsys, Inc., 2001-12-18
255222Sksewell@umich.edu
265222Sksewell@umich.edu  CHANGE LOG AT THE END OF THE FILE
275222Sksewell@umich.edu *****************************************************************************/
285222Sksewell@umich.edu
295222Sksewell@umich.edu
305222Sksewell@umich.edu#ifndef SC_COR_FIBER_H
315222Sksewell@umich.edu#define SC_COR_FIBER_H
325222Sksewell@umich.edu
335222Sksewell@umich.edu#if defined(_WIN32) || defined(WIN32) || defined(WIN64)
345222Sksewell@umich.edu
352686Sksewell@umich.edu#include "sysc/kernel/sc_cor.h"
362686Sksewell@umich.edu#include "sysc/kernel/sc_cmnhdr.h"
374661Sksewell@umich.edu
382686Sksewell@umich.edu#if defined(__GNUC__) && __USING_SJLJ_EXCEPTIONS__
394661Sksewell@umich.edu   // _Unwind_SjLj_Register() & _Unwind_SjLj_Unregister() only need first field.
404661Sksewell@umich.edu   struct SjLj_Function_Context {
414661Sksewell@umich.edu       struct SjLj_Function_Context *prev;
424661Sksewell@umich.edu   };
434661Sksewell@umich.edu#endif
442980Sgblack@eecs.umich.edu
452686Sksewell@umich.edunamespace sc_core {
465222Sksewell@umich.edu
475222Sksewell@umich.educlass sc_cor_pkg_fiber;
485222Sksewell@umich.edutypedef sc_cor_pkg_fiber sc_cor_pkg_t;
495222Sksewell@umich.edu
505222Sksewell@umich.edu#if( defined(_MSC_VER) && _MSC_VER >= 1300 )
515222Sksewell@umich.edutypedef std::size_t size_t;
522686Sksewell@umich.edu#endif
534661Sksewell@umich.edu
542686Sksewell@umich.edu// ----------------------------------------------------------------------------
555222Sksewell@umich.edu//  CLASS : sc_cor_fiber
565222Sksewell@umich.edu//
572686Sksewell@umich.edu//  Coroutine class implemented with QuickThreads.
585222Sksewell@umich.edu// ----------------------------------------------------------------------------
595222Sksewell@umich.edu
605222Sksewell@umich.educlass sc_cor_fiber
615222Sksewell@umich.edu: public sc_cor
625222Sksewell@umich.edu{
635222Sksewell@umich.edu
645222Sksewell@umich.edupublic:
655222Sksewell@umich.edu
665222Sksewell@umich.edu    // constructor
675222Sksewell@umich.edu    sc_cor_fiber()
685222Sksewell@umich.edu	: m_stack_size( 0 ), m_fiber( 0 ), m_pkg( 0 )
695222Sksewell@umich.edu       {
705222Sksewell@umich.edu#         if defined(__GNUC__) && __USING_SJLJ_EXCEPTIONS__
715222Sksewell@umich.edu              m_eh.prev = 0;
725222Sksewell@umich.edu#         endif
735222Sksewell@umich.edu       }
745222Sksewell@umich.edu
755222Sksewell@umich.edu    // destructor
765222Sksewell@umich.edu    virtual ~sc_cor_fiber();
775222Sksewell@umich.edu
785222Sksewell@umich.edupublic:
795222Sksewell@umich.edu
805222Sksewell@umich.edu    std::size_t       m_stack_size;     // stack size
815222Sksewell@umich.edu    void*             m_fiber;          // fiber
822686Sksewell@umich.edu
832686Sksewell@umich.edu    sc_cor_pkg_fiber* m_pkg;            // the creating coroutine package
842686Sksewell@umich.edu#if defined(__GNUC__) && __USING_SJLJ_EXCEPTIONS__
852686Sksewell@umich.edu    struct SjLj_Function_Context m_eh;  // the exception handling context
862686Sksewell@umich.edu#endif
872686Sksewell@umich.edu
882686Sksewell@umich.edu
892686Sksewell@umich.eduprivate:
902686Sksewell@umich.edu
912686Sksewell@umich.edu    // disabled
922686Sksewell@umich.edu    sc_cor_fiber( const sc_cor_fiber& );
932686Sksewell@umich.edu    sc_cor_fiber& operator = ( const sc_cor_fiber& );
942686Sksewell@umich.edu};
952686Sksewell@umich.edu
962686Sksewell@umich.edu
972686Sksewell@umich.edu// ----------------------------------------------------------------------------
982686Sksewell@umich.edu//  CLASS : sc_cor_pkg_fiber
992686Sksewell@umich.edu//
1002686Sksewell@umich.edu//  Coroutine package class implemented with QuickThreads.
1012686Sksewell@umich.edu// ----------------------------------------------------------------------------
1022686Sksewell@umich.edu
1032686Sksewell@umich.educlass sc_cor_pkg_fiber
1042686Sksewell@umich.edu: public sc_cor_pkg
1052686Sksewell@umich.edu{
1062686Sksewell@umich.edu  public:
1072686Sksewell@umich.edu
1082686Sksewell@umich.edu    // constructor
1092686Sksewell@umich.edu    sc_cor_pkg_fiber( sc_simcontext* simc );
1102686Sksewell@umich.edu
1112686Sksewell@umich.edu    // destructor
1122686Sksewell@umich.edu    virtual ~sc_cor_pkg_fiber();
1132686Sksewell@umich.edu
1142686Sksewell@umich.edu    // create a new coroutine
1152686Sksewell@umich.edu    virtual sc_cor* create( std::size_t stack_size, sc_cor_fn* fn, void* arg );
1162686Sksewell@umich.edu
1172686Sksewell@umich.edu    // yield to the next coroutine
1182686Sksewell@umich.edu    virtual void yield( sc_cor* next_cor );
1192686Sksewell@umich.edu
1202686Sksewell@umich.edu    // abort the current coroutine (and resume the next coroutine)
1212686Sksewell@umich.edu    virtual void abort( sc_cor* next_cor );
1222686Sksewell@umich.edu
1232686Sksewell@umich.edu    // get the main coroutine
1242686Sksewell@umich.edu    virtual sc_cor* get_main();
1255222Sksewell@umich.edu
1262686Sksewell@umich.eduprivate:
1272686Sksewell@umich.edu
1282686Sksewell@umich.edu    static int instance_count;
1292686Sksewell@umich.edu
1302686Sksewell@umich.eduprivate:
1312686Sksewell@umich.edu
1322686Sksewell@umich.edu    // disabled
1332686Sksewell@umich.edu    sc_cor_pkg_fiber();
1342686Sksewell@umich.edu    sc_cor_pkg_fiber( const sc_cor_pkg_fiber& );
1352686Sksewell@umich.edu    sc_cor_pkg_fiber& operator = ( const sc_cor_pkg_fiber& );
1365222Sksewell@umich.edu};
1372686Sksewell@umich.edu
1382686Sksewell@umich.edu} // namespace sc_core
1392686Sksewell@umich.edu
1402686Sksewell@umich.edu#endif // WIN32
1412686Sksewell@umich.edu
1422686Sksewell@umich.edu// $Log: sc_cor_fiber.h,v $
1435222Sksewell@umich.edu// Revision 1.6  2011/08/26 20:46:09  acg
1442686Sksewell@umich.edu//  Andy Goodrich: moved the modification log to the end of the file to
1452686Sksewell@umich.edu//  eliminate source line number skew when check-ins are done.
1462686Sksewell@umich.edu//
1472686Sksewell@umich.edu// Revision 1.5  2011/06/25 17:08:39  acg
1482686Sksewell@umich.edu//  Andy Goodrich: Jerome Cornet's changes to use libtool to build the
1492686Sksewell@umich.edu//  library.
1502686Sksewell@umich.edu//
1515222Sksewell@umich.edu// Revision 1.4  2011/02/18 20:27:14  acg
1522686Sksewell@umich.edu//  Andy Goodrich: Updated Copyrights.
1532686Sksewell@umich.edu//
1542686Sksewell@umich.edu// Revision 1.3  2011/02/13 21:47:37  acg
1552686Sksewell@umich.edu//  Andy Goodrich: update copyright notice.
1562686Sksewell@umich.edu//
1572686Sksewell@umich.edu// Revision 1.2  2008/05/22 17:06:25  acg
1582686Sksewell@umich.edu//  Andy Goodrich: updated copyright notice to include 2008.
1592686Sksewell@umich.edu//
1602686Sksewell@umich.edu// Revision 1.1.1.1  2006/12/15 20:20:05  acg
1612686Sksewell@umich.edu// SystemC 2.3
1622686Sksewell@umich.edu//
1635222Sksewell@umich.edu// Revision 1.3  2006/01/13 18:44:29  acg
1642686Sksewell@umich.edu// Added $Log to record CVS changes into the source.
1652686Sksewell@umich.edu//
1662686Sksewell@umich.edu
1672686Sksewell@umich.edu#endif
1682686Sksewell@umich.edu
1692686Sksewell@umich.edu// Taf!
1702686Sksewell@umich.edu