00001 /***************************************************************************** 00002 00003 The following code is derived, directly or indirectly, from the SystemC 00004 source code Copyright (c) 1996-2004 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.3 (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_join.cpp -- Join Process Synchronization Implementation 00021 00022 Original Author: Andy Goodrich, Forte Design Systems, 5 May 2003 00023 00024 *****************************************************************************/ 00025 00026 /***************************************************************************** 00027 00028 MODIFICATION LOG - modifiers, enter your name, affiliation, date and 00029 changes you are making here. 00030 00031 Name, Affiliation, Date: 00032 Description of Modification: 00033 00034 *****************************************************************************/ 00035 00036 #include <assert.h> 00037 #include <stdlib.h> 00038 #include <cstddef> 00039 00040 #include "systemc/kernel/sc_process_int.h" 00041 #include "systemc/kernel/sc_simcontext.h" 00042 #include "systemc/kernel/sc_simcontext_int.h" 00043 #include "systemc/utils/sc_exception.h" 00044 #include "systemc/kernel/sc_kernel_ids.h" 00045 #include "systemc/kernel/sc_join.h" 00046 00047 00048 //------------------------------------------------------------------------------ 00049 //"sc_join::add_process - sc_process_base*" 00050 // 00051 // This method adds a process to this join object instance. This consists of 00052 // incrementing the count of processes in the join process and adding this 00053 // object instance to the supplied thread's monitoring queue. 00054 // process_p -> thread to be monitored. 00055 //------------------------------------------------------------------------------ 00056 void sc_join::add_process( sc_process_base* process_p ) 00057 { 00058 m_threads_n++; 00059 process_p->operator sc_thread_handle()->add_monitor( this ); 00060 } 00061 00062 00063 //------------------------------------------------------------------------------ 00064 //"sc_join::add_process - sc_process_handle" 00065 // 00066 // This method adds a process to this join object instance. This consists of 00067 // incrementing the count of processes in the join process and adding this 00068 // object instance to the supplied thread's monitoring queue. 00069 // process_h = handle for process to be monitored. 00070 //------------------------------------------------------------------------------ 00071 void sc_join::add_process( const sc_process_handle& process_h ) 00072 { 00073 sc_thread_handle thread_p; // Thread within process_h. 00074 00075 thread_p = process_h.m_target_p->operator sc_thread_handle(); 00076 if ( thread_p ) 00077 { 00078 m_threads_n++; 00079 thread_p->add_monitor( this ); 00080 } 00081 else 00082 { 00083 SC_REPORT_ERROR( SC_ID_JOIN_ON_METHOD_HANDLE_, 0 ); 00084 } 00085 } 00086 00087 00088 //------------------------------------------------------------------------------ 00089 //"sc_join::signal" 00090 // 00091 // This virtual method is called when a process being monitored by this object 00092 // instance sends a signal. If the signal type is spm_exit and the count of 00093 // threads that we are waiting to terminate on goes to zero we fire our join 00094 // event. 00095 // thread_p -> thread that is signalling. 00096 // type = type of signal being sent. 00097 //------------------------------------------------------------------------------ 00098 void sc_join::signal(sc_thread_handle thread_p, int type) 00099 { 00100 switch ( type ) 00101 { 00102 case sc_process_monitor::spm_exit: 00103 thread_p->remove_monitor(this); 00104 if ( --m_threads_n == 0 ) m_join_event.notify(); 00105 break; 00106 } 00107 } 00108 00109
1.2.18