SystemC  2.3.1
Accellera SystemC proof-of-concept library
sc_join.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3  The following code is derived, directly or indirectly, from the SystemC
4  source code Copyright (c) 1996-2014 by all Contributors.
5  All Rights reserved.
6 
7  The contents of this file are subject to the restrictions and limitations
8  set forth in the SystemC Open Source License (the "License");
9  You may not use this file except in compliance with such restrictions and
10  limitations. You may obtain instructions on how to receive a copy of the
11  License at http://www.accellera.org/. Software distributed by Contributors
12  under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
13  ANY KIND, either express or implied. See the License for the specific
14  language governing rights and limitations under the License.
15 
16  *****************************************************************************/
17 
18 /*****************************************************************************
19 
20  sc_join.h -- Join Process Synchronization Definition
21 
22  Original Author: Andy Goodrich, Forte Design Systems, 5 May 2003
23 
24  CHANGE LOG AT THE END OF THE FILE
25  *****************************************************************************/
26 
27 // $Log: sc_join.h,v $
28 // Revision 1.8 2011/08/26 21:45:00 acg
29 // Andy Goodrich: fix internal event naming.
30 //
31 // Revision 1.7 2011/08/26 20:46:09 acg
32 // Andy Goodrich: moved the modification log to the end of the file to
33 // eliminate source line number skew when check-ins are done.
34 //
35 
36 #ifndef SC_JOIN_H
37 #define SC_JOIN_H
38 
39 #include "sysc/kernel/sc_process.h"
40 #include "sysc/kernel/sc_wait.h"
41 
42 namespace sc_core {
43 
44 //==============================================================================
45 // CLASS sc_join
46 //
47 // This class provides a way of waiting for a set of threads to complete their
48 // execution. The threads whose completion is to be monitored are registered,
49 // and upon their completion an event notification will occur.
50 //==============================================================================
51 class sc_join : public sc_process_monitor {
52  friend class sc_process_b;
53  friend class sc_process_handle;
54  public:
55  sc_join();
56  void add_process( sc_process_handle process_h );
57  inline int process_count();
58  virtual void signal(sc_thread_handle thread_p, int type);
59  inline void wait();
60  inline void wait_clocked();
61 
62  protected:
63  void add_process( sc_process_b* process_p );
64 
65  protected:
66  sc_event m_join_event; // Event to notify when all threads have reported.
67  int m_threads_n; // # of threads still need to wait for.
68 };
69 
71 
72 // suspend a thread that does not have a sensitivity list:
73 
75 
76 // suspend a thread that has a sensitivity list:
77 
78 inline void sc_join::wait_clocked()
79 {
80  do { ::sc_core::wait(); } while (m_threads_n != 0);
81 }
82 
83 #define SC_CJOIN \
84  }; \
85  sc_core::sc_join join; \
86  for ( unsigned int i = 0; \
87  i < sizeof(forkees)/sizeof(sc_core::sc_process_handle); \
88  i++ ) \
89  join.add_process(forkees[i]); \
90  join.wait_clocked(); \
91 }
92 
93 #define SC_FORK \
94 { \
95  sc_core::sc_process_handle forkees[] = {
96 
97 #define SC_JOIN \
98  }; \
99  sc_core::sc_join join; \
100  for ( unsigned int i = 0; \
101  i < sizeof(forkees)/sizeof(sc_core::sc_process_handle); \
102  i++ ) \
103  join.add_process(forkees[i]); \
104  join.wait(); \
105 }
106 
107 } // namespace sc_core
108 
109 // Revision 1.6 2011/08/24 22:05:50 acg
110 // Torsten Maehne: initialization changes to remove warnings.
111 //
112 // Revision 1.5 2011/02/18 20:27:14 acg
113 // Andy Goodrich: Updated Copyrights.
114 //
115 // Revision 1.4 2011/02/13 21:47:37 acg
116 // Andy Goodrich: update copyright notice.
117 //
118 // Revision 1.3 2009/07/28 01:10:53 acg
119 // Andy Goodrich: updates for 2.3 release candidate.
120 //
121 // Revision 1.2 2008/05/22 17:06:25 acg
122 // Andy Goodrich: updated copyright notice to include 2008.
123 //
124 // Revision 1.1.1.1 2006/12/15 20:20:05 acg
125 // SystemC 2.3
126 //
127 // Revision 1.5 2006/04/28 21:38:27 acg
128 // Andy Goodrich: fixed loop constraint that was using sizeof(sc_thread_handle)
129 // rather than sizeof(sc_process_handle).
130 //
131 // Revision 1.4 2006/01/13 18:44:29 acg
132 // Added $Log to record CVS changes into the source.
133 
134 #endif // SC_JOIN_H
void wait(int, sc_simcontext *)
int process_count()
Definition: sc_join.h:70
sc_event m_join_event
Definition: sc_join.h:66
void add_process(sc_process_handle process_h)
class sc_thread_process * sc_thread_handle
Definition: sc_process.h:58
virtual void signal(sc_thread_handle thread_p, int type)
void wait()
Definition: sc_join.h:74
void wait_clocked()
Definition: sc_join.h:78