sc_method_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_method_process.cpp -- Method process 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_method_process.cpp,v $
00038 // Revision 1.1.1.1  2006/12/15 20:31:37  acg
00039 // SystemC 2.2
00040 //
00041 // Revision 1.6  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.5  2006/01/26 21:04:54  acg
00047 //  Andy Goodrich: deprecation message changes and additional messages.
00048 //
00049 // Revision 1.4  2006/01/24 20:49:05  acg
00050 // Andy Goodrich: changes to remove the use of deprecated features within the
00051 // simulator, and to issue warning messages when deprecated features are used.
00052 //
00053 // Revision 1.3  2006/01/13 18:44:29  acg
00054 // Added $Log to record CVS changes into the source.
00055 //
00056 
00057 #include "sysc/kernel/sc_method_process.h"
00058 #include "sysc/kernel/sc_simcontext_int.h"
00059 #include "sysc/kernel/sc_module.h"
00060 
00061 namespace sc_core {
00062 
00063 //------------------------------------------------------------------------------
00064 //"sc_method_process::clear_trigger"
00065 //
00066 // This method clears any pending trigger for this object instance.
00067 //------------------------------------------------------------------------------
00068 void sc_method_process::clear_trigger()
00069 {
00070     switch( m_trigger_type ) {
00071       case STATIC: 
00072         return;
00073       case EVENT: 
00074         m_event_p->remove_dynamic( this );
00075         m_event_p = 0;
00076         break;
00077       case OR_LIST: 
00078         m_event_list_p->remove_dynamic( this, 0 );
00079         m_event_list_p->auto_delete();
00080         m_event_list_p = 0;
00081         break;
00082       case AND_LIST: 
00083         m_event_list_p->remove_dynamic( this, 0 );
00084         m_event_list_p->auto_delete();
00085         m_event_list_p = 0;
00086         m_event_count = 0;
00087         break;
00088       case TIMEOUT: 
00089         m_timeout_event_p->cancel();
00090         m_timeout_event_p->reset();
00091         break;
00092       case EVENT_TIMEOUT: 
00093         m_timeout_event_p->cancel();
00094         m_timeout_event_p->reset();
00095         m_event_p->remove_dynamic( this );
00096         m_event_p = 0;
00097         break;
00098       case OR_LIST_TIMEOUT: 
00099         m_timeout_event_p->cancel();
00100         m_timeout_event_p->reset();
00101         m_event_list_p->remove_dynamic( this, 0 );
00102         m_event_list_p->auto_delete();
00103         m_event_list_p = 0;
00104       break;
00105       case AND_LIST_TIMEOUT: 
00106         m_timeout_event_p->cancel();
00107         m_timeout_event_p->reset();
00108         m_event_list_p->remove_dynamic( this, 0 );
00109         m_event_list_p->auto_delete();
00110         m_event_list_p = 0;
00111         m_event_count = 0;
00112         break;
00113     }
00114     m_trigger_type = STATIC;
00115 }
00116 
00117 
00118 //------------------------------------------------------------------------------
00119 //"sc_method_process::kill_process"
00120 //
00121 // This method removes this object instance from use. It calls the
00122 // sc_process_b::kill_process() method to perform low level clean up. Then
00123 // it aborts this process if it is the active process.
00124 //------------------------------------------------------------------------------
00125 void sc_method_process::kill_process()
00126 {
00127     // CLEAN UP THE LOW LEVEL STUFF ASSOCIATED WITH THIS DATA STRUCTURE:
00128 
00129     sc_process_b::kill_process();
00130 
00131 
00132     // REMOVE METHOD FROM RUN QUEUE:
00133 
00134     simcontext()->remove_runnable_method( this );
00135 
00136 }
00137 
00138 
00139 //------------------------------------------------------------------------------
00140 //"sc_method_process::sc_method_process"
00141 //
00142 // This is the object instance constructor for this class.
00143 //------------------------------------------------------------------------------
00144 sc_method_process::sc_method_process( const char* name_p, 
00145     bool free_host, SC_ENTRY_FUNC method_p, 
00146     sc_process_host* host_p, const sc_spawn_options* opt_p 
00147 ):
00148     sc_process_b(
00149         name_p && name_p[0] ? name_p : sc_gen_unique_name("method_p"), 
00150         free_host, method_p, host_p, opt_p)
00151 {
00152 
00153     // CHECK IF THIS IS AN sc_module-BASED PROCESS AND SIMUALTION HAS STARTED:
00154 
00155     if ( DCAST<sc_module*>(host_p) != 0 && sc_is_running() )
00156     {
00157         SC_REPORT_ERROR( SC_ID_MODULE_METHOD_AFTER_START_, "" );
00158     }
00159 
00160     // INITIALIZE VALUES:
00161     //
00162     // If there are spawn options use them.
00163 
00164     m_process_kind = SC_METHOD_PROC_;
00165     if (opt_p) {
00166         m_dont_init = opt_p->m_dont_initialize;
00167 
00168         // traverse event sensitivity list
00169         for (unsigned int i = 0; i < opt_p->m_sensitive_events.size(); i++) {
00170             sc_sensitive::make_static_sensitivity(
00171                 this, *opt_p->m_sensitive_events[i]);
00172         }
00173 
00174         // traverse port base sensitivity list
00175         for ( unsigned int i = 0; i < opt_p->m_sensitive_port_bases.size(); i++)
00176         {
00177             sc_sensitive::make_static_sensitivity(
00178                 this, *opt_p->m_sensitive_port_bases[i]);
00179         }
00180 
00181         // traverse interface sensitivity list
00182         for ( unsigned int i = 0; i < opt_p->m_sensitive_interfaces.size(); i++)
00183         {
00184             sc_sensitive::make_static_sensitivity(
00185                 this, *opt_p->m_sensitive_interfaces[i]);
00186         }
00187 
00188         // traverse event finder sensitivity list
00189         for ( unsigned int i = 0; i < opt_p->m_sensitive_event_finders.size();
00190             i++)
00191         {
00192             sc_sensitive::make_static_sensitivity(
00193                 this, *opt_p->m_sensitive_event_finders[i]);
00194         }
00195     }
00196 
00197     else
00198     {
00199         m_dont_init = false;
00200     }
00201 }
00202 
00203 //------------------------------------------------------------------------------
00204 //"sc_method_process::sc_method_process"
00205 //
00206 // This is the object instance destructor for this class.
00207 //------------------------------------------------------------------------------
00208 sc_method_process::~sc_method_process()
00209 {
00210 }
00211 
00212 
00213 //------------------------------------------------------------------------------
00214 //"sc_method_process::trigger_dynamic"
00215 //
00216 // This method sets up a dynamic trigger on an event.
00217 //------------------------------------------------------------------------------
00218 bool
00219 sc_method_process::trigger_dynamic( sc_event* e )
00220 {
00221     if( is_runnable() ) {
00222         return false;
00223     }
00224     m_timed_out = false;
00225     switch( m_trigger_type ) {
00226       case EVENT: 
00227         m_event_p = 0;
00228         m_trigger_type = STATIC;
00229         return true;
00230       case OR_LIST: 
00231         m_event_list_p->remove_dynamic( this, e );
00232         m_event_list_p->auto_delete();
00233         m_event_list_p = 0;
00234         m_trigger_type = STATIC;
00235         return true;
00236       case AND_LIST:
00237         if( -- m_event_count == 0 ) {
00238             // no need to remove_dynamic
00239             m_event_list_p->auto_delete();
00240             m_event_list_p = 0;
00241             m_trigger_type = STATIC;
00242             return true;
00243         }
00244         return false;
00245       case TIMEOUT:
00246         m_trigger_type = STATIC;
00247         return true;
00248       case EVENT_TIMEOUT:
00249         if( e == m_event_p ) {
00250             m_timeout_event_p->cancel();
00251             m_timeout_event_p->reset();
00252         } else {
00253             m_timed_out = true;
00254             m_event_p->remove_dynamic( this );
00255         }
00256         m_event_p = 0;
00257         m_trigger_type = STATIC;
00258         return true;
00259       case OR_LIST_TIMEOUT:
00260         if( e != m_timeout_event_p ) {
00261             m_timeout_event_p->cancel();
00262             m_timeout_event_p->reset();
00263         } else {
00264             m_timed_out = true;
00265         }
00266         m_event_list_p->remove_dynamic( this, e );
00267         m_event_list_p->auto_delete();
00268         m_event_list_p = 0;
00269         m_trigger_type = STATIC;
00270         return true;
00271       case AND_LIST_TIMEOUT:
00272         if( e == m_timeout_event_p ) {
00273             m_timed_out = true;
00274             m_event_list_p->remove_dynamic( this, e );
00275             m_event_list_p->auto_delete();
00276             m_event_list_p = 0;
00277             m_trigger_type = STATIC;
00278             return true;
00279         } else if( -- m_event_count == 0 ) {
00280             m_timeout_event_p->cancel();
00281             m_timeout_event_p->reset();
00282             // no need to remove_dynamic
00283             m_event_list_p->auto_delete();
00284             m_event_list_p = 0;
00285             m_trigger_type = STATIC;
00286             return true;
00287         }
00288         return false;
00289       case STATIC:
00290         // we should never get here
00291         assert( false );
00292     }
00293     return false;
00294 }
00295 
00296 
00297 } // namespace sc_core 

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