sc_process.h

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-2005 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_process.h -- Declarations for process classes. Requires
00021                   cstdlib -- We need size_t.
00022 
00023   Original Author: Stan Y. Liao, Synopsys, Inc.
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: Andy Goodrich, Forte Design Systems 20 May 2003
00033   Description of Modification: Changes to support dynamic processes.
00034 
00035 
00036  *****************************************************************************/
00037 
00038 #ifndef SC_PROCESS_H
00039 #define SC_PROCESS_H
00040 
00041 #include "sysc/utils/sc_iostream.h"
00042 #include "sysc/kernel/sc_constants.h"
00043 
00044 namespace sc_core {
00045 
00046 // -----------------------------------------------------------------------------
00047 // PROCESS HANDLES AND BASE CLASS FORWARD REFERENCE:
00048 // -----------------------------------------------------------------------------
00049 
00050 typedef class sc_cthread_process* sc_cthread_handle;
00051 typedef class sc_method_process*  sc_method_handle;
00052 typedef class sc_thread_process*  sc_thread_handle;
00053 
00054 class sc_process_b;     // Base class for all kinds of processes.
00055 class sc_process_host;  // Base class for objects which have processes.
00056 
00057 
00058 // -----------------------------------------------------------------------------
00059 // PROCESS INVOCATION METHOD OR FUNCTION:
00060 //
00061 //  Define SC_USE_MEMBER_FUNC_PTR if we want to use member function pointers 
00062 //  to implement process dispatch. Otherwise, we'll use a hack that involves 
00063 //  creating a templated invocation object which will invoke the member
00064 //  function. This should not be necessary, but some compilers (e.g., VC++)
00065 //  do not allow the conversion from `void (callback_tag::*)()' to 
00066 //  `void (sc_process_host::*)()'. This is supposed to be OK as long as the 
00067 //  dynamic type is correct.  C++ Standard 5.4 "Explicit type conversion", 
00068 //  clause 7: a pointer to member of derived class type may be explicitly 
00069 //  converted to a pointer to member of an unambiguous non-virtual base class 
00070 //  type. 
00071 // -----------------------------------------------------------------------------
00072 
00073 #if defined(_MSC_VER)
00074 #if ( _MSC_VER > 1200 )
00075 #   define SC_USE_MEMBER_FUNC_PTR
00076 #endif
00077 #else
00078 #   define SC_USE_MEMBER_FUNC_PTR
00079 #endif
00080 
00081 
00082 // COMPILER DOES SUPPORT CAST TO void (sc_process_host::*)() from (T::*)():
00083 
00084 #if defined(SC_USE_MEMBER_FUNC_PTR)
00085 
00086     typedef void (sc_process_host::*SC_ENTRY_FUNC)();
00087 #   define SC_DEFUNCT_PROCESS_FUNCTION &::sc_core::sc_process_host::defunct
00088 #   define SC_DECL_HELPER_STRUCT(callback_tag, func) /*EMPTY*/
00089 #   define SC_MAKE_FUNC_PTR(callback_tag, func) \
00090         (void (::sc_core::sc_process_host::*)())(&callback_tag::func)
00091         // static_cast<SC_ENTRY_FUNC>(&callback_tag::func)
00092 
00093 
00094 // COMPILER NOT DOES SUPPORT CAST TO void (sc_process_host::*)() from (T::*)():
00095 
00096 #else // !defined(SC_USE_MEMBER_FUNC_PTR)
00097         class sc_process_call_base {
00098           public:
00099                 inline sc_process_call_base()
00100                 {
00101                 }
00102 
00103                 virtual ~sc_process_call_base()
00104                 {
00105                 }
00106 
00107                 virtual void invoke(sc_process_host* host_p)
00108                 {
00109                 }
00110         };
00111         extern sc_process_call_base sc_process_defunct;
00112 
00113         template<class T>
00114         class sc_process_call : public sc_process_call_base {
00115           public:
00116                 sc_process_call( void (T::*method_p)() ) :
00117                         sc_process_call_base()
00118                 {
00119                          m_method_p = method_p;
00120                 }
00121 
00122                 virtual ~sc_process_call()
00123                 {
00124                 }
00125 
00126                 virtual void invoke(sc_process_host* host_p)
00127                 {
00128                         (((T*)host_p)->*m_method_p)();
00129                 }
00130 
00131           protected:
00132                 void (T::*m_method_p)();  // Method implementing the process.
00133         };
00134 
00135     typedef sc_process_call_base* SC_ENTRY_FUNC;
00136 #   define SC_DEFUNCT_PROCESS_FUNCTION &::sc_core::sc_process_defunct       
00137 #   define SC_DECL_HELPER_STRUCT(callback_tag, func) /*EMPTY*/
00138 #   define SC_MAKE_FUNC_PTR(callback_tag, func) \
00139         (::sc_core::SC_ENTRY_FUNC) (new \
00140         ::sc_core::sc_process_call<callback_tag>(&callback_tag::func))
00141 
00142 #endif // !defined(SC_USE_MEMBER_FUNC_PTR)
00143 
00144 
00145 extern void sc_set_stack_size( sc_thread_handle, size_t );
00146 
00147 } // namespace sc_core
00148 
00149 #endif // SC_PROCESS_H
00150 
00151 
Generated by
Matthieu Moy <Matthieu.Moy@st.com>
Back to Pinapa Home Page