112027Sjungma@eit.uni-kl.de/***************************************************************************** 212027Sjungma@eit.uni-kl.de 312027Sjungma@eit.uni-kl.de Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 412027Sjungma@eit.uni-kl.de more contributor license agreements. See the NOTICE file distributed 512027Sjungma@eit.uni-kl.de with this work for additional information regarding copyright ownership. 612027Sjungma@eit.uni-kl.de Accellera licenses this file to you under the Apache License, Version 2.0 712027Sjungma@eit.uni-kl.de (the "License"); you may not use this file except in compliance with the 812027Sjungma@eit.uni-kl.de License. You may obtain a copy of the License at 912027Sjungma@eit.uni-kl.de 1012027Sjungma@eit.uni-kl.de http://www.apache.org/licenses/LICENSE-2.0 1112027Sjungma@eit.uni-kl.de 1212027Sjungma@eit.uni-kl.de Unless required by applicable law or agreed to in writing, software 1312027Sjungma@eit.uni-kl.de distributed under the License is distributed on an "AS IS" BASIS, 1412027Sjungma@eit.uni-kl.de WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 1512027Sjungma@eit.uni-kl.de implied. See the License for the specific language governing 1612027Sjungma@eit.uni-kl.de permissions and limitations under the License. 1712027Sjungma@eit.uni-kl.de 1812027Sjungma@eit.uni-kl.de *****************************************************************************/ 1912027Sjungma@eit.uni-kl.de 2012027Sjungma@eit.uni-kl.de/***************************************************************************** 2112027Sjungma@eit.uni-kl.de 2212027Sjungma@eit.uni-kl.de sc_join.h -- Join Process Synchronization Definition 2312027Sjungma@eit.uni-kl.de 2412027Sjungma@eit.uni-kl.de Original Author: Andy Goodrich, Forte Design Systems, 5 May 2003 2512027Sjungma@eit.uni-kl.de 2612027Sjungma@eit.uni-kl.de CHANGE LOG AT THE END OF THE FILE 2712027Sjungma@eit.uni-kl.de *****************************************************************************/ 2812027Sjungma@eit.uni-kl.de 2912027Sjungma@eit.uni-kl.de// $Log: sc_join.h,v $ 3012027Sjungma@eit.uni-kl.de// Revision 1.8 2011/08/26 21:45:00 acg 3112027Sjungma@eit.uni-kl.de// Andy Goodrich: fix internal event naming. 3212027Sjungma@eit.uni-kl.de// 3312027Sjungma@eit.uni-kl.de// Revision 1.7 2011/08/26 20:46:09 acg 3412027Sjungma@eit.uni-kl.de// Andy Goodrich: moved the modification log to the end of the file to 3512027Sjungma@eit.uni-kl.de// eliminate source line number skew when check-ins are done. 3612027Sjungma@eit.uni-kl.de// 3712027Sjungma@eit.uni-kl.de 3812027Sjungma@eit.uni-kl.de#ifndef SC_JOIN_H 3912027Sjungma@eit.uni-kl.de#define SC_JOIN_H 4012027Sjungma@eit.uni-kl.de 4112027Sjungma@eit.uni-kl.de#include "sysc/kernel/sc_process.h" 4212027Sjungma@eit.uni-kl.de#include "sysc/kernel/sc_wait.h" 4312027Sjungma@eit.uni-kl.de 4412027Sjungma@eit.uni-kl.denamespace sc_core { 4512027Sjungma@eit.uni-kl.de 4612027Sjungma@eit.uni-kl.de//============================================================================== 4712027Sjungma@eit.uni-kl.de// CLASS sc_join 4812027Sjungma@eit.uni-kl.de// 4912027Sjungma@eit.uni-kl.de// This class provides a way of waiting for a set of threads to complete their 5012027Sjungma@eit.uni-kl.de// execution. The threads whose completion is to be monitored are registered, 5112027Sjungma@eit.uni-kl.de// and upon their completion an event notification will occur. 5212027Sjungma@eit.uni-kl.de//============================================================================== 5312027Sjungma@eit.uni-kl.declass sc_join : public sc_process_monitor { 5412027Sjungma@eit.uni-kl.de friend class sc_process_b; 5512027Sjungma@eit.uni-kl.de friend class sc_process_handle; 5612027Sjungma@eit.uni-kl.de public: 5712027Sjungma@eit.uni-kl.de sc_join(); 5812027Sjungma@eit.uni-kl.de void add_process( sc_process_handle process_h ); 5912027Sjungma@eit.uni-kl.de inline int process_count(); 6012027Sjungma@eit.uni-kl.de virtual void signal(sc_thread_handle thread_p, int type); 6112027Sjungma@eit.uni-kl.de inline void wait(); 6212027Sjungma@eit.uni-kl.de inline void wait_clocked(); 6312027Sjungma@eit.uni-kl.de 6412027Sjungma@eit.uni-kl.de protected: 6512027Sjungma@eit.uni-kl.de void add_process( sc_process_b* process_p ); 6612027Sjungma@eit.uni-kl.de 6712027Sjungma@eit.uni-kl.de protected: 6812027Sjungma@eit.uni-kl.de sc_event m_join_event; // Event to notify when all threads have reported. 6912027Sjungma@eit.uni-kl.de int m_threads_n; // # of threads still need to wait for. 7012027Sjungma@eit.uni-kl.de}; 7112027Sjungma@eit.uni-kl.de 7212027Sjungma@eit.uni-kl.deint sc_join::process_count() { return m_threads_n; } 7312027Sjungma@eit.uni-kl.de 7412027Sjungma@eit.uni-kl.de// suspend a thread that does not have a sensitivity list: 7512027Sjungma@eit.uni-kl.de 7612027Sjungma@eit.uni-kl.deinline void sc_join::wait() { ::sc_core::wait(m_join_event); } 7712027Sjungma@eit.uni-kl.de 7812027Sjungma@eit.uni-kl.de// suspend a thread that has a sensitivity list: 7912027Sjungma@eit.uni-kl.de 8012027Sjungma@eit.uni-kl.deinline void sc_join::wait_clocked() 8112027Sjungma@eit.uni-kl.de{ 8212027Sjungma@eit.uni-kl.de do { ::sc_core::wait(); } while (m_threads_n != 0); 8312027Sjungma@eit.uni-kl.de} 8412027Sjungma@eit.uni-kl.de 8512027Sjungma@eit.uni-kl.de#define SC_CJOIN \ 8612027Sjungma@eit.uni-kl.de }; \ 8712027Sjungma@eit.uni-kl.de sc_core::sc_join join; \ 8812027Sjungma@eit.uni-kl.de for ( unsigned int i = 0; \ 8912027Sjungma@eit.uni-kl.de i < sizeof(forkees)/sizeof(sc_core::sc_process_handle); \ 9012027Sjungma@eit.uni-kl.de i++ ) \ 9112027Sjungma@eit.uni-kl.de join.add_process(forkees[i]); \ 9212027Sjungma@eit.uni-kl.de join.wait_clocked(); \ 9312027Sjungma@eit.uni-kl.de} 9412027Sjungma@eit.uni-kl.de 9512027Sjungma@eit.uni-kl.de#define SC_FORK \ 9612027Sjungma@eit.uni-kl.de{ \ 9712027Sjungma@eit.uni-kl.de sc_core::sc_process_handle forkees[] = { 9812027Sjungma@eit.uni-kl.de 9912027Sjungma@eit.uni-kl.de#define SC_JOIN \ 10012027Sjungma@eit.uni-kl.de }; \ 10112027Sjungma@eit.uni-kl.de sc_core::sc_join join; \ 10212027Sjungma@eit.uni-kl.de for ( unsigned int i = 0; \ 10312027Sjungma@eit.uni-kl.de i < sizeof(forkees)/sizeof(sc_core::sc_process_handle); \ 10412027Sjungma@eit.uni-kl.de i++ ) \ 10512027Sjungma@eit.uni-kl.de join.add_process(forkees[i]); \ 10612027Sjungma@eit.uni-kl.de join.wait(); \ 10712027Sjungma@eit.uni-kl.de} 10812027Sjungma@eit.uni-kl.de 10912027Sjungma@eit.uni-kl.de} // namespace sc_core 11012027Sjungma@eit.uni-kl.de 11112027Sjungma@eit.uni-kl.de// Revision 1.6 2011/08/24 22:05:50 acg 11212027Sjungma@eit.uni-kl.de// Torsten Maehne: initialization changes to remove warnings. 11312027Sjungma@eit.uni-kl.de// 11412027Sjungma@eit.uni-kl.de// Revision 1.5 2011/02/18 20:27:14 acg 11512027Sjungma@eit.uni-kl.de// Andy Goodrich: Updated Copyrights. 11612027Sjungma@eit.uni-kl.de// 11712027Sjungma@eit.uni-kl.de// Revision 1.4 2011/02/13 21:47:37 acg 11812027Sjungma@eit.uni-kl.de// Andy Goodrich: update copyright notice. 11912027Sjungma@eit.uni-kl.de// 12012027Sjungma@eit.uni-kl.de// Revision 1.3 2009/07/28 01:10:53 acg 12112027Sjungma@eit.uni-kl.de// Andy Goodrich: updates for 2.3 release candidate. 12212027Sjungma@eit.uni-kl.de// 12312027Sjungma@eit.uni-kl.de// Revision 1.2 2008/05/22 17:06:25 acg 12412027Sjungma@eit.uni-kl.de// Andy Goodrich: updated copyright notice to include 2008. 12512027Sjungma@eit.uni-kl.de// 12612027Sjungma@eit.uni-kl.de// Revision 1.1.1.1 2006/12/15 20:20:05 acg 12712027Sjungma@eit.uni-kl.de// SystemC 2.3 12812027Sjungma@eit.uni-kl.de// 12912027Sjungma@eit.uni-kl.de// Revision 1.5 2006/04/28 21:38:27 acg 13012027Sjungma@eit.uni-kl.de// Andy Goodrich: fixed loop constraint that was using sizeof(sc_thread_handle) 13112027Sjungma@eit.uni-kl.de// rather than sizeof(sc_process_handle). 13212027Sjungma@eit.uni-kl.de// 13312027Sjungma@eit.uni-kl.de// Revision 1.4 2006/01/13 18:44:29 acg 13412027Sjungma@eit.uni-kl.de// Added $Log to record CVS changes into the source. 13512027Sjungma@eit.uni-kl.de 13612027Sjungma@eit.uni-kl.de#endif // SC_JOIN_H 137