sc_join.h revision 12027
16145Snate@binkert.org/*****************************************************************************
212065Snikos.nikoleris@arm.com
312065Snikos.nikoleris@arm.com  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
412065Snikos.nikoleris@arm.com  more contributor license agreements.  See the NOTICE file distributed
512065Snikos.nikoleris@arm.com  with this work for additional information regarding copyright ownership.
612065Snikos.nikoleris@arm.com  Accellera licenses this file to you under the Apache License, Version 2.0
712065Snikos.nikoleris@arm.com  (the "License"); you may not use this file except in compliance with the
812065Snikos.nikoleris@arm.com  License.  You may obtain a copy of the License at
912065Snikos.nikoleris@arm.com
1012065Snikos.nikoleris@arm.com    http://www.apache.org/licenses/LICENSE-2.0
1112065Snikos.nikoleris@arm.com
1212065Snikos.nikoleris@arm.com  Unless required by applicable law or agreed to in writing, software
1312065Snikos.nikoleris@arm.com  distributed under the License is distributed on an "AS IS" BASIS,
146145Snate@binkert.org  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
156145Snate@binkert.org  implied.  See the License for the specific language governing
166145Snate@binkert.org  permissions and limitations under the License.
176145Snate@binkert.org
186145Snate@binkert.org *****************************************************************************/
196145Snate@binkert.org
206145Snate@binkert.org/*****************************************************************************
216145Snate@binkert.org
226145Snate@binkert.org  sc_join.h -- Join Process Synchronization Definition
236145Snate@binkert.org
246145Snate@binkert.org  Original Author: Andy Goodrich, Forte Design Systems, 5 May 2003
256145Snate@binkert.org
266145Snate@binkert.org  CHANGE LOG AT THE END OF THE FILE
276145Snate@binkert.org *****************************************************************************/
286145Snate@binkert.org
296145Snate@binkert.org// $Log: sc_join.h,v $
306145Snate@binkert.org// Revision 1.8  2011/08/26 21:45:00  acg
316145Snate@binkert.org//  Andy Goodrich: fix internal event naming.
326145Snate@binkert.org//
336145Snate@binkert.org// Revision 1.7  2011/08/26 20:46:09  acg
346145Snate@binkert.org//  Andy Goodrich: moved the modification log to the end of the file to
356145Snate@binkert.org//  eliminate source line number skew when check-ins are done.
366145Snate@binkert.org//
376145Snate@binkert.org
386145Snate@binkert.org#ifndef SC_JOIN_H
396145Snate@binkert.org#define SC_JOIN_H
406145Snate@binkert.org
416145Snate@binkert.org#include "sysc/kernel/sc_process.h"
427054Snate@binkert.org#include "sysc/kernel/sc_wait.h"
437054Snate@binkert.org
447054Snate@binkert.orgnamespace sc_core {
457054Snate@binkert.org
467054Snate@binkert.org//==============================================================================
477054Snate@binkert.org// CLASS sc_join
487054Snate@binkert.org//
497054Snate@binkert.org// This class provides a way of waiting for a set of threads to complete their
507054Snate@binkert.org// execution. The threads whose completion is to be monitored are registered,
516145Snate@binkert.org// and upon their completion an event notification will occur.
527054Snate@binkert.org//==============================================================================
537054Snate@binkert.orgclass sc_join : public sc_process_monitor {
546145Snate@binkert.org    friend class sc_process_b;
557055Snate@binkert.org    friend class sc_process_handle;
567055Snate@binkert.org  public:
5712065Snikos.nikoleris@arm.com    sc_join();
587454Snate@binkert.org    void add_process( sc_process_handle process_h );
597055Snate@binkert.org    inline int process_count();
6012065Snikos.nikoleris@arm.com    virtual void signal(sc_thread_handle thread_p, int type);
6112065Snikos.nikoleris@arm.com    inline void wait();
6212065Snikos.nikoleris@arm.com    inline void wait_clocked();
6313784Sgabeblack@google.com
6412065Snikos.nikoleris@arm.com  protected:
658645Snilay@cs.wisc.edu    void add_process( sc_process_b* process_p );
669594Snilay@cs.wisc.edu
6713784Sgabeblack@google.com  protected:
6814184Sgabeblack@google.com    sc_event m_join_event;  // Event to notify when all threads have reported.
6914184Sgabeblack@google.com    int      m_threads_n;   // # of threads still need to wait for.
707054Snate@binkert.org};
719465Snilay@cs.wisc.edu
726145Snate@binkert.orgint sc_join::process_count() { return m_threads_n; }
736145Snate@binkert.org
746145Snate@binkert.org// suspend a thread that does not have a sensitivity list:
756145Snate@binkert.org
769465Snilay@cs.wisc.eduinline void sc_join::wait() { ::sc_core::wait(m_join_event); }
777054Snate@binkert.org
787054Snate@binkert.org// suspend a thread that has a sensitivity list:
796876Ssteve.reinhardt@amd.com
806876Ssteve.reinhardt@amd.cominline void sc_join::wait_clocked()
819594Snilay@cs.wisc.edu{
8210917Sbrandon.potter@amd.com    do { ::sc_core::wait(); } while (m_threads_n != 0);
836145Snate@binkert.org}
8410303Snilay@cs.wisc.edu
8513799SAndrea.Mondelli@ucf.edu#define SC_CJOIN \
866145Snate@binkert.org    }; \
879497Snilay@cs.wisc.edu    sc_core::sc_join           join; \
8810303Snilay@cs.wisc.edu    for ( unsigned int i = 0; \
8910303Snilay@cs.wisc.edu        i < sizeof(forkees)/sizeof(sc_core::sc_process_handle); \
909275Snilay@cs.wisc.edu        i++ ) \
916493STushar.Krishna@amd.com        join.add_process(forkees[i]); \
927054Snate@binkert.org    join.wait_clocked(); \
9311113Sjoe.gross@amd.com}
9411113Sjoe.gross@amd.com
9510311Snilay@cs.wisc.edu#define SC_FORK \
9611113Sjoe.gross@amd.com{ \
9711113Sjoe.gross@amd.com    sc_core::sc_process_handle forkees[] = {
9811113Sjoe.gross@amd.com
9911113Sjoe.gross@amd.com#define SC_JOIN \
1006145Snate@binkert.org    }; \
10111663Stushar@ece.gatech.edu    sc_core::sc_join           join; \
1029799Snilay@cs.wisc.edu    for ( unsigned int i = 0; \
10311663Stushar@ece.gatech.edu        i < sizeof(forkees)/sizeof(sc_core::sc_process_handle); \
1049799Snilay@cs.wisc.edu        i++ ) \
1058257SBrad.Beckmann@amd.com        join.add_process(forkees[i]); \
10611664Stushar@ece.gatech.edu    join.wait(); \
10711664Stushar@ece.gatech.edu}
10811664Stushar@ece.gatech.edu
1096145Snate@binkert.org} // namespace sc_core
1109863Snilay@cs.wisc.edu
1117055Snate@binkert.org// Revision 1.6  2011/08/24 22:05:50  acg
1126145Snate@binkert.org//  Torsten Maehne: initialization changes to remove warnings.
1139302Snilay@cs.wisc.edu//
1149302Snilay@cs.wisc.edu// Revision 1.5  2011/02/18 20:27:14  acg
1159302Snilay@cs.wisc.edu//  Andy Goodrich: Updated Copyrights.
1169302Snilay@cs.wisc.edu//
1179302Snilay@cs.wisc.edu// Revision 1.4  2011/02/13 21:47:37  acg
1189302Snilay@cs.wisc.edu//  Andy Goodrich: update copyright notice.
1199302Snilay@cs.wisc.edu//
1209302Snilay@cs.wisc.edu// Revision 1.3  2009/07/28 01:10:53  acg
1219302Snilay@cs.wisc.edu//  Andy Goodrich: updates for 2.3 release candidate.
1229302Snilay@cs.wisc.edu//
12312065Snikos.nikoleris@arm.com// Revision 1.2  2008/05/22 17:06:25  acg
12412065Snikos.nikoleris@arm.com//  Andy Goodrich: updated copyright notice to include 2008.
12512065Snikos.nikoleris@arm.com//
12612065Snikos.nikoleris@arm.com// Revision 1.1.1.1  2006/12/15 20:20:05  acg
12712065Snikos.nikoleris@arm.com// SystemC 2.3
12812065Snikos.nikoleris@arm.com//
12912065Snikos.nikoleris@arm.com// Revision 1.5  2006/04/28 21:38:27  acg
13012065Snikos.nikoleris@arm.com//  Andy Goodrich: fixed loop constraint that was using sizeof(sc_thread_handle)
13112065Snikos.nikoleris@arm.com//  rather than sizeof(sc_process_handle).
13212065Snikos.nikoleris@arm.com//
13312065Snikos.nikoleris@arm.com// Revision 1.4  2006/01/13 18:44:29  acg
13412065Snikos.nikoleris@arm.com// Added $Log to record CVS changes into the source.
13512065Snikos.nikoleris@arm.com
13612065Snikos.nikoleris@arm.com#endif // SC_JOIN_H
13713784Sgabeblack@google.com