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.cpp -- Join Process Synchronization Implementation
23 
24   Original Author: Andy Goodrich, Forte Design Systems, 5 May 2003
25 
26  CHANGE LOG APPEARS AT THE END OF THE FILE
27  *****************************************************************************/
28 
29 
30 #include <cstdlib>
31 #include <cstddef>
32 
33 #include "sysc/kernel/sc_process_handle.h"
34 #include "sysc/kernel/sc_simcontext.h"
35 #include "sysc/kernel/sc_simcontext_int.h"
36 #include "sysc/kernel/sc_kernel_ids.h"
37 #include "sysc/kernel/sc_thread_process.h"
38 #include "sysc/kernel/sc_join.h"
39 
40 namespace sc_core {
41 
42 //------------------------------------------------------------------------------
43 //"sc_join::sc_join"
44 //
45 // This is the object instance constructor for this class.
46 //------------------------------------------------------------------------------
sc_join()47 sc_join::sc_join()
48   : m_join_event( sc_event::kernel_event, "join_event" )
49   , m_threads_n(0)
50 {}
51 
52 //------------------------------------------------------------------------------
53 //"sc_join::add_process - sc_process_b*"
54 //
55 // This method adds a process to this join object instance. This consists of
56 // incrementing the count of processes in the join process and adding this
57 // object instance to the supplied thread's monitoring queue.
58 //     process_p -> thread to be monitored.
59 //------------------------------------------------------------------------------
add_process(sc_process_b * process_p)60 void sc_join::add_process( sc_process_b* process_p )
61 {
62     sc_thread_handle handle = dynamic_cast<sc_thread_handle>(process_p);
63     sc_assert( handle != 0 );
64     m_threads_n++;
65     handle->add_monitor( this );
66 }
67 
68 
69 //------------------------------------------------------------------------------
70 //"sc_join::add_process - sc_process_handle"
71 //
72 // This method adds a process to this join object instance. This consists of
73 // incrementing the count of processes in the join process and adding this
74 // object instance to the supplied thread's monitoring queue.
75 //     process_h = handle for process to be monitored.
76 //------------------------------------------------------------------------------
add_process(sc_process_handle process_h)77 void sc_join::add_process( sc_process_handle process_h )
78 {
79     sc_thread_handle thread_p; // Thread within process_h.
80 
81     thread_p = process_h.operator sc_thread_handle();
82     if ( thread_p )
83     {
84         m_threads_n++;
85         thread_p->add_monitor( this );
86     }
87     else
88     {
89         SC_REPORT_ERROR( SC_ID_JOIN_ON_METHOD_HANDLE_, 0 );
90     }
91 }
92 
93 
94 //------------------------------------------------------------------------------
95 //"sc_join::signal"
96 //
97 // This virtual method is called when a process being monitored by this object
98 // instance sends a signal. If the signal type is spm_exit and the count of
99 // threads that we are waiting to terminate on goes to zero we fire our join
100 // event.
101 //     thread_p -> thread that is signalling.
102 //     type     =  type of signal being sent.
103 //------------------------------------------------------------------------------
signal(sc_thread_handle thread_p,int type)104 void sc_join::signal(sc_thread_handle thread_p, int type)
105 {
106     switch ( type )
107     {
108       case sc_process_monitor::spm_exit:
109         thread_p->remove_monitor(this);
110         if ( --m_threads_n == 0 ) m_join_event.notify();
111         break;
112     }
113 }
114 
115 } // namespace sc_core
116 
117 // $Log: sc_join.cpp,v $
118 // Revision 1.7  2011/08/26 21:45:00  acg
119 //  Andy Goodrich: fix internal event naming.
120 //
121 // Revision 1.6  2011/08/26 20:46:09  acg
122 //  Andy Goodrich: moved the modification log to the end of the file to
123 //  eliminate source line number skew when check-ins are done.
124 //
125 // Revision 1.5  2011/02/18 20:27:14  acg
126 //  Andy Goodrich: Updated Copyrights.
127 //
128 // Revision 1.4  2011/02/13 21:47:37  acg
129 //  Andy Goodrich: update copyright notice.
130 //
131 // Revision 1.3  2009/07/28 01:10:53  acg
132 //  Andy Goodrich: updates for 2.3 release candidate.
133 //
134 // Revision 1.2  2008/05/22 17:06:25  acg
135 //  Andy Goodrich: updated copyright notice to include 2008.
136 //
137 // Revision 1.1.1.1  2006/12/15 20:20:05  acg
138 // SystemC 2.3
139 //
140 // Revision 1.3  2006/01/13 18:44:29  acg
141 // Added $Log to record CVS changes into the source.
142 //
143