sc_cor_fiber.cpp
来自「基于4个mips核的noc设计」· C++ 代码 · 共 147 行
CPP
147 行
/***************************************************************************** The following code is derived, directly or indirectly, from the SystemC source code Copyright (c) 1996-2002 by all Contributors. All Rights reserved. The contents of this file are subject to the restrictions and limitations set forth in the SystemC Open Source License Version 2.3 (the "License"); You may not use this file except in compliance with such restrictions and limitations. You may obtain instructions on how to receive a copy of the License at http://www.systemc.org/. Software distributed by Contributors under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. *****************************************************************************//***************************************************************************** sc_cor_fiber.cpp -- Coroutine implementation with fibers. Original Author: Martin Janssen, Synopsys, Inc., 2001-12-18 *****************************************************************************//***************************************************************************** MODIFICATION LOG - modifiers, enter your name, affiliation, date and changes you are making here. Name, Affiliation, Date: Description of Modification: *****************************************************************************/#ifdef WIN32#include "systemc/kernel/sc_cor_fiber.h"#include "systemc/kernel/sc_simcontext.h"// ----------------------------------------------------------------------------// File static variables.// ----------------------------------------------------------------------------// main coroutinestatic sc_cor_fiber main_cor;// ----------------------------------------------------------------------------// CLASS : sc_cor_fiber//// Coroutine class implemented with QuickThreads.// ----------------------------------------------------------------------------// destructorsc_cor_fiber::~sc_cor_fiber(){ if( m_fiber != 0 ) { DeleteFiber( m_fiber ); }}// ----------------------------------------------------------------------------// CLASS : sc_cor_pkg_fiber//// Coroutine package class implemented with QuickThreads.// ----------------------------------------------------------------------------int sc_cor_pkg_fiber::instance_count = 0;// constructorsc_cor_pkg_fiber::sc_cor_pkg_fiber( sc_simcontext* simc ): sc_cor_pkg( simc ){ if( ++ instance_count == 1 ) { // initialize the main coroutine assert( main_cor.m_fiber == 0 ); main_cor.m_fiber = ConvertThreadToFiber( 0 ); }}// destructorsc_cor_pkg_fiber::~sc_cor_pkg_fiber(){ if( -- instance_count == 0 ) { // cleanup the main coroutine main_cor.m_fiber = 0; }}// create a new coroutinesc_cor*sc_cor_pkg_fiber::create( size_t stack_size, sc_cor_fn* fn, void* arg ){ sc_cor_fiber* cor = new sc_cor_fiber; cor->m_pkg = this; cor->m_stack_size = stack_size; cor->m_fiber = CreateFiber( cor->m_stack_size, (LPFIBER_START_ROUTINE) fn, arg ); return cor;}// yield to the next coroutinevoidsc_cor_pkg_fiber::yield( sc_cor* next_cor ){ sc_cor_fiber* new_cor = SCAST<sc_cor_fiber*>( next_cor ); SwitchToFiber( new_cor->m_fiber );}// abort the current coroutine (and resume the next coroutine)voidsc_cor_pkg_fiber::abort( sc_cor* next_cor ){ sc_cor_fiber* new_cor = SCAST<sc_cor_fiber*>( next_cor ); SwitchToFiber( new_cor->m_fiber );}// get the main coroutinesc_cor*sc_cor_pkg_fiber::get_main(){ return &main_cor;}#endif// Taf!
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?