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_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 // $Log: sc_join.cpp,v $ 00037 // Revision 1.1.1.1 2006/12/15 20:31:37 acg 00038 // SystemC 2.2 00039 // 00040 // Revision 1.3 2006/01/13 18:44:29 acg 00041 // Added $Log to record CVS changes into the source. 00042 // 00043 00044 #include <cassert> 00045 #include <cstdlib> 00046 #include <cstddef> 00047 00048 #include "sysc/kernel/sc_process_handle.h" 00049 #include "sysc/kernel/sc_simcontext.h" 00050 #include "sysc/kernel/sc_simcontext_int.h" 00051 #include "sysc/kernel/sc_kernel_ids.h" 00052 #include "sysc/kernel/sc_thread_process.h" 00053 #include "sysc/kernel/sc_join.h" 00054 00055 namespace sc_core { 00056 00057 //------------------------------------------------------------------------------ 00058 //"sc_join::add_process - sc_process_b*" 00059 // 00060 // This method adds a process to this join object instance. This consists of 00061 // incrementing the count of processes in the join process and adding this 00062 // object instance to the supplied thread's monitoring queue. 00063 // process_p -> thread to be monitored. 00064 //------------------------------------------------------------------------------ 00065 void sc_join::add_process( sc_process_b* process_p ) 00066 { 00067 sc_thread_handle handle = DCAST<sc_thread_handle>(process_p); 00068 assert( handle != 0 ); 00069 m_threads_n++; 00070 handle->add_monitor( this ); 00071 } 00072 00073 00074 //------------------------------------------------------------------------------ 00075 //"sc_join::add_process - sc_process_handle" 00076 // 00077 // This method adds a process to this join object instance. This consists of 00078 // incrementing the count of processes in the join process and adding this 00079 // object instance to the supplied thread's monitoring queue. 00080 // process_h = handle for process to be monitored. 00081 //------------------------------------------------------------------------------ 00082 void sc_join::add_process( sc_process_handle process_h ) 00083 { 00084 sc_thread_handle thread_p; // Thread within process_h. 00085 00086 thread_p = process_h.operator sc_thread_handle(); 00087 if ( thread_p ) 00088 { 00089 m_threads_n++; 00090 thread_p->add_monitor( this ); 00091 } 00092 else 00093 { 00094 SC_REPORT_ERROR( SC_ID_JOIN_ON_METHOD_HANDLE_, 0 ); 00095 } 00096 } 00097 00098 00099 //------------------------------------------------------------------------------ 00100 //"sc_join::signal" 00101 // 00102 // This virtual method is called when a process being monitored by this object 00103 // instance sends a signal. If the signal type is spm_exit and the count of 00104 // threads that we are waiting to terminate on goes to zero we fire our join 00105 // event. 00106 // thread_p -> thread that is signalling. 00107 // type = type of signal being sent. 00108 //------------------------------------------------------------------------------ 00109 void sc_join::signal(sc_thread_handle thread_p, int type) 00110 { 00111 switch ( type ) 00112 { 00113 case sc_process_monitor::spm_exit: 00114 thread_p->remove_monitor(this); 00115 if ( --m_threads_n == 0 ) m_join_event.notify(); 00116 break; 00117 } 00118 } 00119 00120 } // namespace sc_core