00001 /***************************************************************************** 00002 00003 The following code is derived, directly or indirectly, from the SystemC 00004 source code Copyright (c) 1996-2014 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 (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.accellera.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.h -- Join Process Synchronization Definition 00021 00022 Original Author: Andy Goodrich, Forte Design Systems, 5 May 2003 00023 00024 CHANGE LOG AT THE END OF THE FILE 00025 *****************************************************************************/ 00026 00027 // $Log: sc_join.h,v $ 00028 // Revision 1.8 2011/08/26 21:45:00 acg 00029 // Andy Goodrich: fix internal event naming. 00030 // 00031 // Revision 1.7 2011/08/26 20:46:09 acg 00032 // Andy Goodrich: moved the modification log to the end of the file to 00033 // eliminate source line number skew when check-ins are done. 00034 // 00035 00036 #ifndef SC_JOIN_H 00037 #define SC_JOIN_H 00038 00039 #include "sysc/kernel/sc_process.h" 00040 #include "sysc/kernel/sc_wait.h" 00041 00042 namespace sc_core { 00043 00044 //============================================================================== 00045 // CLASS sc_join 00046 // 00047 // This class provides a way of waiting for a set of threads to complete their 00048 // execution. The threads whose completion is to be monitored are registered, 00049 // and upon their completion an event notification will occur. 00050 //============================================================================== 00051 class sc_join : public sc_process_monitor { 00052 friend class sc_process_b; 00053 friend class sc_process_handle; 00054 public: 00055 sc_join(); 00056 void add_process( sc_process_handle process_h ); 00057 inline int process_count(); 00058 virtual void signal(sc_thread_handle thread_p, int type); 00059 00064 // 08/19/2015 GL: modified for the OoO simulation 00065 inline void wait( int seg_id ); 00066 00071 // 08/19/2015 GL: modified for the OoO simulation 00072 inline void wait_clocked( int seg_id ); 00073 00074 protected: 00075 void add_process( sc_process_b* process_p ); 00076 00077 protected: 00078 sc_event m_join_event; // Event to notify when all threads have reported. 00079 int m_threads_n; // # of threads still need to wait for. 00080 }; 00081 00082 int sc_join::process_count() { return m_threads_n; } 00083 00084 // 08/19/2015 GL: modified for the OoO simulation 00085 00086 // suspend a thread that does not have a sensitivity list: 00087 00088 inline void sc_join::wait( int seg_id ) 00089 { ::sc_core::wait(m_join_event, seg_id); } 00090 00091 // suspend a thread that has a sensitivity list: 00092 00093 inline void sc_join::wait_clocked( int seg_id ) 00094 { 00095 do { ::sc_core::wait( seg_id ); } while (m_threads_n != 0); 00096 } 00097 00098 #define SC_CJOIN \ 00099 }; \ 00100 sc_core::sc_join join; \ 00101 for ( unsigned int i = 0; \ 00102 i < sizeof(forkees)/sizeof(sc_core::sc_process_handle); \ 00103 i++ ) \ 00104 join.add_process(forkees[i]); \ 00105 join.wait_clocked(); \ 00106 } 00107 00108 #define SC_FORK \ 00109 { \ 00110 sc_core::sc_process_handle forkees[] = { 00111 00112 #define SC_JOIN \ 00113 }; \ 00114 sc_core::sc_join join; \ 00115 for ( unsigned int i = 0; \ 00116 i < sizeof(forkees)/sizeof(sc_core::sc_process_handle); \ 00117 i++ ) \ 00118 join.add_process(forkees[i]); \ 00119 join.wait(); \ 00120 } 00121 00122 } // namespace sc_core 00123 00124 // Revision 1.6 2011/08/24 22:05:50 acg 00125 // Torsten Maehne: initialization changes to remove warnings. 00126 // 00127 // Revision 1.5 2011/02/18 20:27:14 acg 00128 // Andy Goodrich: Updated Copyrights. 00129 // 00130 // Revision 1.4 2011/02/13 21:47:37 acg 00131 // Andy Goodrich: update copyright notice. 00132 // 00133 // Revision 1.3 2009/07/28 01:10:53 acg 00134 // Andy Goodrich: updates for 2.3 release candidate. 00135 // 00136 // Revision 1.2 2008/05/22 17:06:25 acg 00137 // Andy Goodrich: updated copyright notice to include 2008. 00138 // 00139 // Revision 1.1.1.1 2006/12/15 20:20:05 acg 00140 // SystemC 2.3 00141 // 00142 // Revision 1.5 2006/04/28 21:38:27 acg 00143 // Andy Goodrich: fixed loop constraint that was using sizeof(sc_thread_handle) 00144 // rather than sizeof(sc_process_handle). 00145 // 00146 // Revision 1.4 2006/01/13 18:44:29 acg 00147 // Added $Log to record CVS changes into the source. 00148 00149 #endif // SC_JOIN_H