sc_join.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-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.h -- Join Process Synchronization Definition
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.h,v $
00037 // Revision 1.1.1.1  2006/12/15 20:31:37  acg
00038 // SystemC 2.2
00039 //
00040 // Revision 1.5  2006/04/28 21:38:27  acg
00041 //  Andy Goodrich: fixed loop constraint that was using sizeof(sc_thread_handle)
00042 //  rather than sizeof(sc_process_handle).
00043 //
00044 // Revision 1.4  2006/01/13 18:44:29  acg
00045 // Added $Log to record CVS changes into the source.
00046 //
00047 
00048 #ifndef SC_JOIN_H
00049 #define SC_JOIN_H
00050 
00051 #include "sysc/kernel/sc_process.h"
00052 #include "sysc/kernel/sc_wait.h"
00053 
00054 namespace sc_core {
00055 
00056 //==============================================================================
00057 // CLASS sc_join
00058 //
00059 // This class provides a way of waiting for a set of threads to complete their
00060 // execution. The threads whose completion is to be monitored are registered,
00061 // and upon their completion an event notification will occur.
00062 //==============================================================================
00063 class sc_join : public sc_process_monitor {
00064     friend class sc_process_b;
00065     friend class sc_process_handle;
00066   public:
00067     inline sc_join();
00068     virtual inline ~sc_join();
00069     void add_process( sc_process_handle process_h );
00070     inline int process_count();
00071     virtual void signal(sc_thread_handle thread_p, int type);
00072     inline void wait();
00073     inline void wait_clocked();
00074 
00075   protected: 
00076     void add_process( sc_process_b* process_p );
00077 
00078   protected:
00079     sc_event m_join_event;  // Event to notify when all threads have reported.
00080     int      m_threads_n;   // # of threads still need to wait for.
00081 };
00082 
00083 sc_join::sc_join() : m_threads_n(0) { }
00084 
00085 sc_join::~sc_join() {}
00086 
00087 
00088 int sc_join::process_count() { return m_threads_n; }
00089 
00090 // suspend a thread that does not have a sensitivity list:
00091 
00092 inline void sc_join::wait() { ::sc_core::wait(m_join_event); }
00093 
00094 // suspend a thread that has a sensitivity list:
00095 
00096 inline void sc_join::wait_clocked()
00097 {
00098     do { ::sc_core::wait(); } while (m_threads_n != 0);
00099 }
00100 
00101 #define SC_CJOIN \
00102     }; \
00103     sc_core::sc_join           join; \
00104     for ( unsigned int i = 0; \
00105         i < sizeof(forkees)/sizeof(sc_core::sc_process_handle); \
00106         i++ ) \
00107         join.add_process(forkees[i]); \
00108     join.wait_clocked(); \
00109 }
00110 
00111 #define SC_FORK \
00112 { \
00113     sc_core::sc_process_handle forkees[] = {
00114 
00115 #define SC_JOIN \
00116     }; \
00117     sc_core::sc_join           join; \
00118     for ( unsigned int i = 0; \
00119         i < sizeof(forkees)/sizeof(sc_core::sc_process_handle); \
00120         i++ ) \
00121         join.add_process(forkees[i]); \
00122     join.wait(); \
00123 }
00124 
00125 } // namespace sc_core
00126 
00127 #endif // SC_JOIN_H

Generated on Wed Jan 21 15:32:09 2009 for SystemC by  doxygen 1.5.5