112943Sgabeblack@google.com/* 212943Sgabeblack@google.com * Copyright 2018 Google, Inc. 312943Sgabeblack@google.com * 412943Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 512943Sgabeblack@google.com * modification, are permitted provided that the following conditions are 612943Sgabeblack@google.com * met: redistributions of source code must retain the above copyright 712943Sgabeblack@google.com * notice, this list of conditions and the following disclaimer; 812943Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright 912943Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 1012943Sgabeblack@google.com * documentation and/or other materials provided with the distribution; 1112943Sgabeblack@google.com * neither the name of the copyright holders nor the names of its 1212943Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 1312943Sgabeblack@google.com * this software without specific prior written permission. 1412943Sgabeblack@google.com * 1512943Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1612943Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1712943Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1812943Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1912943Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2012943Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2112943Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2212943Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2312943Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2412943Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2512943Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2612943Sgabeblack@google.com * 2712943Sgabeblack@google.com * Authors: Gabe Black 2812943Sgabeblack@google.com */ 2912943Sgabeblack@google.com 3013196Sgabeblack@google.com#include "systemc/core/process.hh" 3113317Sgabeblack@google.com#include "systemc/ext/core/messages.hh" 3213196Sgabeblack@google.com#include "systemc/ext/core/sc_event.hh" 3312943Sgabeblack@google.com#include "systemc/ext/core/sc_join.hh" 3413196Sgabeblack@google.com#include "systemc/ext/core/sc_module.hh" 3513249Sgabeblack@google.com#include "systemc/ext/utils/sc_report_handler.hh" 3612943Sgabeblack@google.com 3712943Sgabeblack@google.comnamespace sc_core 3812943Sgabeblack@google.com{ 3912943Sgabeblack@google.com 4013196Sgabeblack@google.comsc_join::sc_join() : remaining(0) {} 4113196Sgabeblack@google.com 4213196Sgabeblack@google.comvoid 4313196Sgabeblack@google.comsc_join::add_process(sc_process_handle h) 4412943Sgabeblack@google.com{ 4513196Sgabeblack@google.com auto p = (::sc_gem5::Process *)h; 4613196Sgabeblack@google.com assert(p); 4713196Sgabeblack@google.com 4813249Sgabeblack@google.com if (p->procKind() == SC_METHOD_PROC_) { 4913317Sgabeblack@google.com SC_REPORT_ERROR(SC_ID_JOIN_ON_METHOD_HANDLE_, ""); 5013249Sgabeblack@google.com return; 5113249Sgabeblack@google.com } 5213249Sgabeblack@google.com 5313196Sgabeblack@google.com remaining++; 5413196Sgabeblack@google.com p->joinWait(this); 5512943Sgabeblack@google.com} 5612943Sgabeblack@google.com 5713196Sgabeblack@google.comint sc_join::process_count() { return remaining; } 5813196Sgabeblack@google.comvoid sc_join::signal() { if (!--remaining) joinEvent.notify(); } 5913196Sgabeblack@google.comvoid sc_join::wait() { ::sc_core::wait(joinEvent); } 6013196Sgabeblack@google.comvoid sc_join::wait_clocked() { do { ::sc_core::wait(); } while (remaining); } 6112943Sgabeblack@google.com 6212943Sgabeblack@google.com} // namespace sc_core 63