SystemC  2.3.2
Accellera SystemC proof-of-concept library
sc_join.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
4  more contributor license agreements. See the NOTICE file distributed
5  with this work for additional information regarding copyright ownership.
6  Accellera licenses this file to you under the Apache License, Version 2.0
7  (the "License"); you may not use this file except in compliance with the
8  License. You may obtain a copy of the License at
9 
10  http://www.apache.org/licenses/LICENSE-2.0
11 
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the License is distributed on an "AS IS" BASIS,
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15  implied. See the License for the specific language governing
16  permissions and limitations under the License.
17 
18  *****************************************************************************/
19 
20 /*****************************************************************************
21 
22  sc_join.h -- Join Process Synchronization Definition
23 */
33 // $Log: sc_join.h,v $
34 // Revision 1.8 2011/08/26 21:45:00 acg
35 // Andy Goodrich: fix internal event naming.
36 //
37 // Revision 1.7 2011/08/26 20:46:09 acg
38 // Andy Goodrich: moved the modification log to the end of the file to
39 // eliminate source line number skew when check-ins are done.
40 //
41 
42 #ifndef SC_JOIN_H
43 #define SC_JOIN_H
44 
45 #include "sysc/kernel/sc_process.h"
46 #include "sysc/kernel/sc_wait.h"
47 
48 namespace sc_core {
49 
50 //==============================================================================
51 // CLASS sc_join
52 //
53 // This class provides a way of waiting for a set of threads to complete their
54 // execution. The threads whose completion is to be monitored are registered,
55 // and upon their completion an event notification will occur.
56 //==============================================================================
58  friend class sc_process_b;
59  friend class sc_process_handle;
60  public:
61  sc_join();
62  void add_process( sc_process_handle process_h );
63  inline int process_count();
64  virtual void signal(sc_thread_handle thread_p, int type);
65  inline void wait();
66  inline void wait_clocked();
67 
68  protected:
69  void add_process( sc_process_b* process_p );
70 
71  protected:
72  sc_event m_join_event; // Event to notify when all threads have reported.
73  int m_threads_n; // # of threads still need to wait for.
74 
75  private:
76  sc_join( const sc_join& );
77  sc_join& operator = ( const sc_join& );
78 };
79 
80 int sc_join::process_count() { return m_threads_n; }
81 
82 // suspend a thread that does not have a sensitivity list:
83 
84 inline void sc_join::wait() { ::sc_core::wait(m_join_event); }
85 
86 // suspend a thread that has a sensitivity list:
87 
88 inline void sc_join::wait_clocked()
89 {
90  do { ::sc_core::wait(); } while (m_threads_n != 0);
91 }
92 
93 #define SC_CJOIN \
94  }; \
95  sc_core::sc_join join; \
96  for ( unsigned int i = 0; \
97  i < sizeof(forkees)/sizeof(sc_core::sc_process_handle); \
98  i++ ) \
99  join.add_process(forkees[i]); \
100  join.wait_clocked(); \
101 }
102 
103 #define SC_FORK \
104 { \
105  sc_core::sc_process_handle forkees[] = {
106 
107 #define SC_JOIN \
108  }; \
109  sc_core::sc_join join; \
110  for ( unsigned int i = 0; \
111  i < sizeof(forkees)/sizeof(sc_core::sc_process_handle); \
112  i++ ) \
113  join.add_process(forkees[i]); \
114  join.wait(); \
115 }
116 
117 } // namespace sc_core
118 
119 // Revision 1.6 2011/08/24 22:05:50 acg
120 // Torsten Maehne: initialization changes to remove warnings.
121 //
122 // Revision 1.5 2011/02/18 20:27:14 acg
123 // Andy Goodrich: Updated Copyrights.
124 //
125 // Revision 1.4 2011/02/13 21:47:37 acg
126 // Andy Goodrich: update copyright notice.
127 //
128 // Revision 1.3 2009/07/28 01:10:53 acg
129 // Andy Goodrich: updates for 2.3 release candidate.
130 //
131 // Revision 1.2 2008/05/22 17:06:25 acg
132 // Andy Goodrich: updated copyright notice to include 2008.
133 //
134 // Revision 1.1.1.1 2006/12/15 20:20:05 acg
135 // SystemC 2.3
136 //
137 // Revision 1.5 2006/04/28 21:38:27 acg
138 // Andy Goodrich: fixed loop constraint that was using sizeof(sc_thread_handle)
139 // rather than sizeof(sc_process_handle).
140 //
141 // Revision 1.4 2006/01/13 18:44:29 acg
142 // Added $Log to record CVS changes into the source.
143 
144 #endif // SC_JOIN_H
Process base class support.
void wait()
Definition: sc_join.h:84
Wait() and related functions.
The event class.
Definition: sc_event.h:256
void wait_clocked()
Definition: sc_join.h:88
class sc_thread_process * sc_thread_handle
Definition: sc_process.h:67
sc_event m_join_event
Definition: sc_join.h:72
int process_count()
Definition: sc_join.h:80
#define SC_API
Definition: sc_cmnhdr.h:168
void SC_API wait(int, sc_simcontext *)