112027Sjungma@eit.uni-kl.de/*****************************************************************************
212027Sjungma@eit.uni-kl.de
312027Sjungma@eit.uni-kl.de  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
412027Sjungma@eit.uni-kl.de  more contributor license agreements.  See the NOTICE file distributed
512027Sjungma@eit.uni-kl.de  with this work for additional information regarding copyright ownership.
612027Sjungma@eit.uni-kl.de  Accellera licenses this file to you under the Apache License, Version 2.0
712027Sjungma@eit.uni-kl.de  (the "License"); you may not use this file except in compliance with the
812027Sjungma@eit.uni-kl.de  License.  You may obtain a copy of the License at
912027Sjungma@eit.uni-kl.de
1012027Sjungma@eit.uni-kl.de    http://www.apache.org/licenses/LICENSE-2.0
1112027Sjungma@eit.uni-kl.de
1212027Sjungma@eit.uni-kl.de  Unless required by applicable law or agreed to in writing, software
1312027Sjungma@eit.uni-kl.de  distributed under the License is distributed on an "AS IS" BASIS,
1412027Sjungma@eit.uni-kl.de  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
1512027Sjungma@eit.uni-kl.de  implied.  See the License for the specific language governing
1612027Sjungma@eit.uni-kl.de  permissions and limitations under the License.
1712027Sjungma@eit.uni-kl.de
1812027Sjungma@eit.uni-kl.de *****************************************************************************/
1912027Sjungma@eit.uni-kl.de
2012027Sjungma@eit.uni-kl.de/*****************************************************************************
2112027Sjungma@eit.uni-kl.de
2212027Sjungma@eit.uni-kl.de  sc_join.cpp -- Join Process Synchronization Implementation
2312027Sjungma@eit.uni-kl.de
2412027Sjungma@eit.uni-kl.de  Original Author: Andy Goodrich, Forte Design Systems, 5 May 2003
2512027Sjungma@eit.uni-kl.de
2612027Sjungma@eit.uni-kl.de CHANGE LOG APPEARS AT THE END OF THE FILE
2712027Sjungma@eit.uni-kl.de *****************************************************************************/
2812027Sjungma@eit.uni-kl.de
2912027Sjungma@eit.uni-kl.de
3012027Sjungma@eit.uni-kl.de#include <cassert>
3112027Sjungma@eit.uni-kl.de#include <cstdlib>
3212027Sjungma@eit.uni-kl.de#include <cstddef>
3312027Sjungma@eit.uni-kl.de
3412027Sjungma@eit.uni-kl.de#include "sysc/kernel/sc_process_handle.h"
3512027Sjungma@eit.uni-kl.de#include "sysc/kernel/sc_simcontext.h"
3612027Sjungma@eit.uni-kl.de#include "sysc/kernel/sc_simcontext_int.h"
3712027Sjungma@eit.uni-kl.de#include "sysc/kernel/sc_kernel_ids.h"
3812027Sjungma@eit.uni-kl.de#include "sysc/kernel/sc_thread_process.h"
3912027Sjungma@eit.uni-kl.de#include "sysc/kernel/sc_join.h"
4012027Sjungma@eit.uni-kl.de
4112027Sjungma@eit.uni-kl.denamespace sc_core {
4212027Sjungma@eit.uni-kl.de
4312027Sjungma@eit.uni-kl.de//------------------------------------------------------------------------------
4412027Sjungma@eit.uni-kl.de//"sc_join::sc_join"
4512027Sjungma@eit.uni-kl.de//
4612027Sjungma@eit.uni-kl.de// This is the object instance constructor for this class.
4712027Sjungma@eit.uni-kl.de//------------------------------------------------------------------------------
4812027Sjungma@eit.uni-kl.desc_join::sc_join()
4912027Sjungma@eit.uni-kl.de  : m_join_event( (std::string(SC_KERNEL_EVENT_PREFIX)+"_join_event").c_str() )
5012027Sjungma@eit.uni-kl.de  , m_threads_n(0)
5112027Sjungma@eit.uni-kl.de{}
5212027Sjungma@eit.uni-kl.de
5312027Sjungma@eit.uni-kl.de//------------------------------------------------------------------------------
5412027Sjungma@eit.uni-kl.de//"sc_join::add_process - sc_process_b*"
5512027Sjungma@eit.uni-kl.de//
5612027Sjungma@eit.uni-kl.de// This method adds a process to this join object instance. This consists of
5712027Sjungma@eit.uni-kl.de// incrementing the count of processes in the join process and adding this
5812027Sjungma@eit.uni-kl.de// object instance to the supplied thread's monitoring queue.
5912027Sjungma@eit.uni-kl.de//     process_p -> thread to be monitored.
6012027Sjungma@eit.uni-kl.de//------------------------------------------------------------------------------
6112027Sjungma@eit.uni-kl.devoid sc_join::add_process( sc_process_b* process_p )
6212027Sjungma@eit.uni-kl.de{
6312027Sjungma@eit.uni-kl.de    sc_thread_handle handle = DCAST<sc_thread_handle>(process_p);
6412027Sjungma@eit.uni-kl.de    assert( handle != 0 );
6512027Sjungma@eit.uni-kl.de    m_threads_n++;
6612027Sjungma@eit.uni-kl.de    handle->add_monitor( this );
6712027Sjungma@eit.uni-kl.de}
6812027Sjungma@eit.uni-kl.de
6912027Sjungma@eit.uni-kl.de
7012027Sjungma@eit.uni-kl.de//------------------------------------------------------------------------------
7112027Sjungma@eit.uni-kl.de//"sc_join::add_process - sc_process_handle"
7212027Sjungma@eit.uni-kl.de//
7312027Sjungma@eit.uni-kl.de// This method adds a process to this join object instance. This consists of
7412027Sjungma@eit.uni-kl.de// incrementing the count of processes in the join process and adding this
7512027Sjungma@eit.uni-kl.de// object instance to the supplied thread's monitoring queue.
7612027Sjungma@eit.uni-kl.de//     process_h = handle for process to be monitored.
7712027Sjungma@eit.uni-kl.de//------------------------------------------------------------------------------
7812027Sjungma@eit.uni-kl.devoid sc_join::add_process( sc_process_handle process_h )
7912027Sjungma@eit.uni-kl.de{
8012027Sjungma@eit.uni-kl.de    sc_thread_handle thread_p; // Thread within process_h.
8112027Sjungma@eit.uni-kl.de
8212027Sjungma@eit.uni-kl.de    thread_p = process_h.operator sc_thread_handle();
8312027Sjungma@eit.uni-kl.de    if ( thread_p )
8412027Sjungma@eit.uni-kl.de    {
8512027Sjungma@eit.uni-kl.de        m_threads_n++;
8612027Sjungma@eit.uni-kl.de        thread_p->add_monitor( this );
8712027Sjungma@eit.uni-kl.de    }
8812027Sjungma@eit.uni-kl.de    else
8912027Sjungma@eit.uni-kl.de    {
9012027Sjungma@eit.uni-kl.de        SC_REPORT_ERROR( SC_ID_JOIN_ON_METHOD_HANDLE_, 0 );
9112027Sjungma@eit.uni-kl.de    }
9212027Sjungma@eit.uni-kl.de}
9312027Sjungma@eit.uni-kl.de
9412027Sjungma@eit.uni-kl.de
9512027Sjungma@eit.uni-kl.de//------------------------------------------------------------------------------
9612027Sjungma@eit.uni-kl.de//"sc_join::signal"
9712027Sjungma@eit.uni-kl.de//
9812027Sjungma@eit.uni-kl.de// This virtual method is called when a process being monitored by this object
9912027Sjungma@eit.uni-kl.de// instance sends a signal. If the signal type is spm_exit and the count of
10012027Sjungma@eit.uni-kl.de// threads that we are waiting to terminate on goes to zero we fire our join
10112027Sjungma@eit.uni-kl.de// event.
10212027Sjungma@eit.uni-kl.de//     thread_p -> thread that is signalling.
10312027Sjungma@eit.uni-kl.de//     type     =  type of signal being sent.
10412027Sjungma@eit.uni-kl.de//------------------------------------------------------------------------------
10512027Sjungma@eit.uni-kl.devoid sc_join::signal(sc_thread_handle thread_p, int type)
10612027Sjungma@eit.uni-kl.de{
10712027Sjungma@eit.uni-kl.de    switch ( type )
10812027Sjungma@eit.uni-kl.de    {
10912027Sjungma@eit.uni-kl.de      case sc_process_monitor::spm_exit:
11012027Sjungma@eit.uni-kl.de        thread_p->remove_monitor(this);
11112027Sjungma@eit.uni-kl.de        if ( --m_threads_n == 0 ) m_join_event.notify();
11212027Sjungma@eit.uni-kl.de        break;
11312027Sjungma@eit.uni-kl.de    }
11412027Sjungma@eit.uni-kl.de}
11512027Sjungma@eit.uni-kl.de
11612027Sjungma@eit.uni-kl.de} // namespace sc_core
11712027Sjungma@eit.uni-kl.de
11812027Sjungma@eit.uni-kl.de// $Log: sc_join.cpp,v $
11912027Sjungma@eit.uni-kl.de// Revision 1.7  2011/08/26 21:45:00  acg
12012027Sjungma@eit.uni-kl.de//  Andy Goodrich: fix internal event naming.
12112027Sjungma@eit.uni-kl.de//
12212027Sjungma@eit.uni-kl.de// Revision 1.6  2011/08/26 20:46:09  acg
12312027Sjungma@eit.uni-kl.de//  Andy Goodrich: moved the modification log to the end of the file to
12412027Sjungma@eit.uni-kl.de//  eliminate source line number skew when check-ins are done.
12512027Sjungma@eit.uni-kl.de//
12612027Sjungma@eit.uni-kl.de// Revision 1.5  2011/02/18 20:27:14  acg
12712027Sjungma@eit.uni-kl.de//  Andy Goodrich: Updated Copyrights.
12812027Sjungma@eit.uni-kl.de//
12912027Sjungma@eit.uni-kl.de// Revision 1.4  2011/02/13 21:47:37  acg
13012027Sjungma@eit.uni-kl.de//  Andy Goodrich: update copyright notice.
13112027Sjungma@eit.uni-kl.de//
13212027Sjungma@eit.uni-kl.de// Revision 1.3  2009/07/28 01:10:53  acg
13312027Sjungma@eit.uni-kl.de//  Andy Goodrich: updates for 2.3 release candidate.
13412027Sjungma@eit.uni-kl.de//
13512027Sjungma@eit.uni-kl.de// Revision 1.2  2008/05/22 17:06:25  acg
13612027Sjungma@eit.uni-kl.de//  Andy Goodrich: updated copyright notice to include 2008.
13712027Sjungma@eit.uni-kl.de//
13812027Sjungma@eit.uni-kl.de// Revision 1.1.1.1  2006/12/15 20:20:05  acg
13912027Sjungma@eit.uni-kl.de// SystemC 2.3
14012027Sjungma@eit.uni-kl.de//
14112027Sjungma@eit.uni-kl.de// Revision 1.3  2006/01/13 18:44:29  acg
14212027Sjungma@eit.uni-kl.de// Added $Log to record CVS changes into the source.
14312027Sjungma@eit.uni-kl.de//
144