sc_cthread_process.cpp

Go to the documentation of this file.
00001 /*****************************************************************************
00002 
00003   The following code is derived, directly or indirectly, from the SystemC
00004   source code Copyright (c) 1996-2006 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 Version 2.4 (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.systemc.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_cthread_process.cpp -- Clocked thread implementation.
00021 
00022   Original Author: Andy Goodrich, Forte Design Systems, 4 August 2005
00023                
00024 
00025  *****************************************************************************/
00026 
00027 /*****************************************************************************
00028 
00029   MODIFICATION LOG - modifiers, enter your name, affiliation, date and
00030   changes you are making here.
00031 
00032       Name, Affiliation, Date:
00033   Description of Modification:
00034 
00035  *****************************************************************************/
00036 
00037 // $Log: sc_cthread_process.cpp,v $
00038 // Revision 1.1.1.1  2006/12/15 20:31:37  acg
00039 // SystemC 2.2
00040 //
00041 // Revision 1.5  2006/04/11 23:13:20  acg
00042 //   Andy Goodrich: Changes for reduced reset support that only includes
00043 //   sc_cthread, but has preliminary hooks for expanding to method and thread
00044 //   processes also.
00045 //
00046 // Revision 1.4  2006/01/24 20:49:04  acg
00047 // Andy Goodrich: changes to remove the use of deprecated features within the
00048 // simulator, and to issue warning messages when deprecated features are used.
00049 //
00050 // Revision 1.3  2006/01/13 18:44:29  acg
00051 // Added $Log to record CVS changes into the source.
00052 //
00053 
00054 #include "sysc/kernel/sc_cthread_process.h"
00055 
00056 namespace sc_core {
00057 
00058 //------------------------------------------------------------------------------
00059 //"sc_cthread_cor_fn"
00060 // 
00061 // This function invokes the coroutine for the supplied object instance.
00062 //------------------------------------------------------------------------------
00063 void sc_cthread_cor_fn( void* arg )
00064 {
00065     sc_cthread_handle cthread_h = RCAST<sc_cthread_handle>( arg );
00066 
00067     // EXECUTE THE CTHREAD AND PROCESS ANY EXCEPTIONS THAT ARE THROWN:
00068     //
00069     // We set the wait state to unknown before invoking the semantics
00070     // in case we are reset, since the wait state will not be cleared, 
00071     // since that happens only if we are not reset.
00072 
00073     while( true ) {
00074 
00075         try {
00076             cthread_h->semantics();
00077         }
00078         catch( sc_user ) {
00079             continue;
00080         }
00081         catch( sc_halt ) {
00082             ::std::cout << "Terminating process "
00083                       << cthread_h->name() << ::std::endl;
00084         }
00085         catch( const sc_report& ex ) {
00086             ::std::cout << "\n" << ex.what() << ::std::endl;
00087             cthread_h->simcontext()->set_error();
00088         }
00089 
00090         break;
00091     }
00092 
00093     // SCHEDULE THREAD FOR DESTRUCTION:
00094     //
00095     // If control reaches this point the process semantics have returned
00096     // so the process should die.
00097 
00098     cthread_h->kill_process();
00099 
00100 }
00101 
00102 //------------------------------------------------------------------------------
00103 //"sc_cthread_process::dont_initialize"
00104 //
00105 // This virtual method sets the initialization switch for this object instance.
00106 //------------------------------------------------------------------------------
00107 void sc_cthread_process::dont_initialize( bool dont )
00108 {
00109     SC_REPORT_WARNING( SC_ID_DONT_INITIALIZE_, 0 );
00110 }
00111 
00112 
00113 //------------------------------------------------------------------------------
00114 //"sc_cthread_process::prepare_for_simulation"
00115 //
00116 // This method prepares this object instance for simulation. It calls the
00117 // coroutine package to create the actual thread.
00118 //------------------------------------------------------------------------------
00119 void sc_cthread_process::prepare_for_simulation()
00120 {
00121     m_cor_p = simcontext()->cor_pkg()->create( m_stack_size,
00122                          sc_cthread_cor_fn, this );
00123     m_cor_p->stack_protect( true );
00124 }
00125 
00126 
00127 //------------------------------------------------------------------------------
00128 //"sc_cthread_process::sc_cthread_process"
00129 //
00130 // This is the object instance constructor for this class.
00131 //------------------------------------------------------------------------------
00132 sc_cthread_process::sc_cthread_process( const char* name_p, 
00133     bool free_host, SC_ENTRY_FUNC method_p, 
00134     sc_process_host* host_p, const sc_spawn_options* opt_p 
00135 ):
00136     sc_thread_process(name_p, free_host, method_p, host_p, opt_p)
00137 {
00138     m_dont_init = false;
00139     m_process_kind = SC_CTHREAD_PROC_;
00140 }
00141 
00142 //------------------------------------------------------------------------------
00143 //"sc_cthread_process::~sc_cthread_process"
00144 //
00145 // This is the object instance constructor for this class.
00146 //------------------------------------------------------------------------------
00147 sc_cthread_process::~sc_cthread_process()
00148 {
00149 }
00150 
00151 } // namespace sc_core 

Generated on Wed Jan 21 15:32:09 2009 for SystemC by  doxygen 1.5.5