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
24  Original Author: Andy Goodrich, Forte Design Systems, 5 May 2003
25
26  CHANGE LOG AT THE END OF THE FILE
27 *****************************************************************************/
28
29// $Log: sc_join.h,v $
30// Revision 1.8  2011/08/26 21:45:00  acg
31//  Andy Goodrich: fix internal event naming.
32//
33// Revision 1.7  2011/08/26 20:46:09  acg
34//  Andy Goodrich: moved the modification log to the end of the file to
35//  eliminate source line number skew when check-ins are done.
36//
37
38#ifndef SC_JOIN_H
39#define SC_JOIN_H
40
41#include "sysc/kernel/sc_process.h"
42#include "sysc/kernel/sc_wait.h"
43
44namespace sc_core {
45
46//==============================================================================
47// CLASS sc_join
48//
49// This class provides a way of waiting for a set of threads to complete their
50// execution. The threads whose completion is to be monitored are registered,
51// and upon their completion an event notification will occur.
52//==============================================================================
53class sc_join : public sc_process_monitor {
54    friend class sc_process_b;
55    friend class sc_process_handle;
56  public:
57    sc_join();
58    void add_process( sc_process_handle process_h );
59    inline int process_count();
60    virtual void signal(sc_thread_handle thread_p, int type);
61    inline void wait();
62    inline void wait_clocked();
63
64  protected:
65    void add_process( sc_process_b* process_p );
66
67  protected:
68    sc_event m_join_event;  // Event to notify when all threads have reported.
69    int      m_threads_n;   // # of threads still need to wait for.
70};
71
72int sc_join::process_count() { return m_threads_n; }
73
74// suspend a thread that does not have a sensitivity list:
75
76inline void sc_join::wait() { ::sc_core::wait(m_join_event); }
77
78// suspend a thread that has a sensitivity list:
79
80inline void sc_join::wait_clocked()
81{
82    do { ::sc_core::wait(); } while (m_threads_n != 0);
83}
84
85#define SC_CJOIN \
86    }; \
87    sc_core::sc_join           join; \
88    for ( unsigned int i = 0; \
89        i < sizeof(forkees)/sizeof(sc_core::sc_process_handle); \
90        i++ ) \
91        join.add_process(forkees[i]); \
92    join.wait_clocked(); \
93}
94
95#define SC_FORK \
96{ \
97    sc_core::sc_process_handle forkees[] = {
98
99#define SC_JOIN \
100    }; \
101    sc_core::sc_join           join; \
102    for ( unsigned int i = 0; \
103        i < sizeof(forkees)/sizeof(sc_core::sc_process_handle); \
104        i++ ) \
105        join.add_process(forkees[i]); \
106    join.wait(); \
107}
108
109} // namespace sc_core
110
111// Revision 1.6  2011/08/24 22:05:50  acg
112//  Torsten Maehne: initialization changes to remove warnings.
113//
114// Revision 1.5  2011/02/18 20:27:14  acg
115//  Andy Goodrich: Updated Copyrights.
116//
117// Revision 1.4  2011/02/13 21:47:37  acg
118//  Andy Goodrich: update copyright notice.
119//
120// Revision 1.3  2009/07/28 01:10:53  acg
121//  Andy Goodrich: updates for 2.3 release candidate.
122//
123// Revision 1.2  2008/05/22 17:06:25  acg
124//  Andy Goodrich: updated copyright notice to include 2008.
125//
126// Revision 1.1.1.1  2006/12/15 20:20:05  acg
127// SystemC 2.3
128//
129// Revision 1.5  2006/04/28 21:38:27  acg
130//  Andy Goodrich: fixed loop constraint that was using sizeof(sc_thread_handle)
131//  rather than sizeof(sc_process_handle).
132//
133// Revision 1.4  2006/01/13 18:44:29  acg
134// Added $Log to record CVS changes into the source.
135
136#endif // SC_JOIN_H
137