112855Sgabeblack@google.com/*****************************************************************************
212855Sgabeblack@google.com
312855Sgabeblack@google.com  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
412855Sgabeblack@google.com  more contributor license agreements.  See the NOTICE file distributed
512855Sgabeblack@google.com  with this work for additional information regarding copyright ownership.
612855Sgabeblack@google.com  Accellera licenses this file to you under the Apache License, Version 2.0
712855Sgabeblack@google.com  (the "License"); you may not use this file except in compliance with the
812855Sgabeblack@google.com  License.  You may obtain a copy of the License at
912855Sgabeblack@google.com
1012855Sgabeblack@google.com    http://www.apache.org/licenses/LICENSE-2.0
1112855Sgabeblack@google.com
1212855Sgabeblack@google.com  Unless required by applicable law or agreed to in writing, software
1312855Sgabeblack@google.com  distributed under the License is distributed on an "AS IS" BASIS,
1412855Sgabeblack@google.com  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
1512855Sgabeblack@google.com  implied.  See the License for the specific language governing
1612855Sgabeblack@google.com  permissions and limitations under the License.
1712855Sgabeblack@google.com
1812855Sgabeblack@google.com *****************************************************************************/
1912855Sgabeblack@google.com
2012855Sgabeblack@google.com/*****************************************************************************
2112855Sgabeblack@google.com
2212855Sgabeblack@google.com  test10.cpp -- Testing proper process execution order for SC_METHOD murderer.
2312855Sgabeblack@google.com
2412855Sgabeblack@google.com  Original Author: Andy Goodrich
2512855Sgabeblack@google.com
2612855Sgabeblack@google.com *****************************************************************************/
2712855Sgabeblack@google.com
2812855Sgabeblack@google.com/*****************************************************************************
2912855Sgabeblack@google.com
3012855Sgabeblack@google.com  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
3112855Sgabeblack@google.com  changes you are making here.
3212855Sgabeblack@google.com
3312855Sgabeblack@google.com      Name, Affiliation, Date:
3412855Sgabeblack@google.com  Description of Modification:
3512855Sgabeblack@google.com
3612855Sgabeblack@google.com *****************************************************************************/
3712855Sgabeblack@google.com// $Log: test10.cpp,v $
3812855Sgabeblack@google.com// Revision 1.2  2011/02/01 20:00:37  acg
3912855Sgabeblack@google.com//  Andy Goodrich: better messaging for output.
4012855Sgabeblack@google.com//
4112855Sgabeblack@google.com// Revision 1.1  2011/02/01 17:16:48  acg
4212855Sgabeblack@google.com//  Andy Goodrich: first check-in.
4312855Sgabeblack@google.com//
4412855Sgabeblack@google.com
4512855Sgabeblack@google.com#define SC_INCLUDE_DYNAMIC_PROCESSES
4612855Sgabeblack@google.com#include "systemc.h"
4712855Sgabeblack@google.com
4812855Sgabeblack@google.comSC_MODULE(DUT)
4912855Sgabeblack@google.com{
5012855Sgabeblack@google.com    SC_CTOR(DUT)
5112855Sgabeblack@google.com    {
5212855Sgabeblack@google.com	SC_METHOD(killer);
5312855Sgabeblack@google.com        sensitive << m_clk.pos();
5412855Sgabeblack@google.com        SC_CTHREAD(stimulus,m_clk.pos());
5512855Sgabeblack@google.com        SC_THREAD(thread0);
5612855Sgabeblack@google.com        sensitive << m_clk.pos();
5712855Sgabeblack@google.com        m_thread0 = sc_get_current_process_handle();
5812855Sgabeblack@google.com        SC_THREAD(thread1);
5912855Sgabeblack@google.com        sensitive << m_clk.pos();
6012855Sgabeblack@google.com        m_thread1 = sc_get_current_process_handle();
6112855Sgabeblack@google.com        SC_THREAD(thread2);
6212855Sgabeblack@google.com        sensitive << m_clk.pos();
6312855Sgabeblack@google.com        m_thread2 = sc_get_current_process_handle();
6412855Sgabeblack@google.com	m_kill = false;
6512855Sgabeblack@google.com    }
6612855Sgabeblack@google.com
6712855Sgabeblack@google.com    void killer()
6812855Sgabeblack@google.com    {
6912855Sgabeblack@google.com        if ( m_kill )
7012855Sgabeblack@google.com	{
7112855Sgabeblack@google.com	    cout << sc_time_stamp() << " killer: killing thread0 " << endl;
7212855Sgabeblack@google.com	    m_thread0.kill();
7312855Sgabeblack@google.com	    cout << sc_time_stamp() << " killer: after killing thread0" << endl;
7412855Sgabeblack@google.com	    m_thread2.kill();
7512855Sgabeblack@google.com	    cout << sc_time_stamp() << " killer: after killing thread2" << endl;
7612855Sgabeblack@google.com	}
7712855Sgabeblack@google.com   }
7812855Sgabeblack@google.com
7912855Sgabeblack@google.com    void thread0()
8012855Sgabeblack@google.com    {
8112855Sgabeblack@google.com        cout << sc_time_stamp() << " thread 0: initialization" << endl;
8212855Sgabeblack@google.com        try {
8312855Sgabeblack@google.com            for (;;)
8412855Sgabeblack@google.com            {
8512855Sgabeblack@google.com                wait();
8612855Sgabeblack@google.com            }
8712855Sgabeblack@google.com        }
8812855Sgabeblack@google.com        catch(sc_core::sc_unwind_exception& ex)
8912855Sgabeblack@google.com        {
9012855Sgabeblack@google.com	    if ( !ex.is_reset() )
9112855Sgabeblack@google.com	    {
9212855Sgabeblack@google.com		cout << sc_time_stamp() << " thread0: received kill" << endl;
9312855Sgabeblack@google.com		m_thread1.kill();
9412855Sgabeblack@google.com		cout << sc_time_stamp() << " thread0: after killing thread1"
9512855Sgabeblack@google.com		     << endl;
9612855Sgabeblack@google.com	    }
9712855Sgabeblack@google.com	    throw ex;
9812855Sgabeblack@google.com        }
9912855Sgabeblack@google.com    }
10012855Sgabeblack@google.com
10112855Sgabeblack@google.com    void thread1()
10212855Sgabeblack@google.com    {
10312855Sgabeblack@google.com        cout << sc_time_stamp() << " thread 1: initialization" << endl;
10412855Sgabeblack@google.com        try {
10512855Sgabeblack@google.com            for (;;)
10612855Sgabeblack@google.com            {
10712855Sgabeblack@google.com                wait();
10812855Sgabeblack@google.com            }
10912855Sgabeblack@google.com        }
11012855Sgabeblack@google.com        catch(sc_core::sc_unwind_exception& ex)
11112855Sgabeblack@google.com        {
11212855Sgabeblack@google.com	    if ( !ex.is_reset() )
11312855Sgabeblack@google.com	    {
11412855Sgabeblack@google.com		cout << sc_time_stamp() << " thread1: received kill" << endl;
11512855Sgabeblack@google.com	    }
11612855Sgabeblack@google.com	    throw ex;
11712855Sgabeblack@google.com        }
11812855Sgabeblack@google.com    }
11912855Sgabeblack@google.com
12012855Sgabeblack@google.com    void thread2()
12112855Sgabeblack@google.com    {
12212855Sgabeblack@google.com        cout << sc_time_stamp() << " thread 2: initialization" << endl;
12312855Sgabeblack@google.com        try {
12412855Sgabeblack@google.com            for (;;)
12512855Sgabeblack@google.com            {
12612855Sgabeblack@google.com                wait();
12712855Sgabeblack@google.com            }
12812855Sgabeblack@google.com        }
12912855Sgabeblack@google.com        catch(sc_core::sc_unwind_exception& ex)
13012855Sgabeblack@google.com        {
13112855Sgabeblack@google.com	    if ( !ex.is_reset() )
13212855Sgabeblack@google.com	    {
13312855Sgabeblack@google.com		cout << sc_time_stamp() << " thread2: received kill" << endl;
13412855Sgabeblack@google.com	    }
13512855Sgabeblack@google.com	    throw ex;
13612855Sgabeblack@google.com        }
13712855Sgabeblack@google.com    }
13812855Sgabeblack@google.com
13912855Sgabeblack@google.com    void stimulus()
14012855Sgabeblack@google.com    {
14112855Sgabeblack@google.com        for (;;)
14212855Sgabeblack@google.com        {
14312855Sgabeblack@google.com            wait();
14412855Sgabeblack@google.com            wait();
14512855Sgabeblack@google.com            wait();
14612855Sgabeblack@google.com            wait();
14712855Sgabeblack@google.com	    cout << sc_time_stamp() << " stimulus setting kill" << endl;
14812855Sgabeblack@google.com	    m_kill = true;
14912855Sgabeblack@google.com            wait();
15012855Sgabeblack@google.com	    m_kill = false;
15112855Sgabeblack@google.com            wait();
15212855Sgabeblack@google.com            wait();
15312855Sgabeblack@google.com	    sc_stop();
15412855Sgabeblack@google.com        }
15512855Sgabeblack@google.com    }
15612855Sgabeblack@google.com
15712855Sgabeblack@google.com    sc_in<bool>       m_clk;
15812855Sgabeblack@google.com    bool              m_kill;
15912855Sgabeblack@google.com    sc_process_handle m_thread0;
16012855Sgabeblack@google.com    sc_process_handle m_thread1;
16112855Sgabeblack@google.com    sc_process_handle m_thread2;
16212855Sgabeblack@google.com};
16312855Sgabeblack@google.com
16412855Sgabeblack@google.comint sc_main(int argc, char* argv[])
16512855Sgabeblack@google.com{
16612855Sgabeblack@google.com    sc_clock        clock;
16712855Sgabeblack@google.com    DUT             dut("dut");
16812855Sgabeblack@google.com
16912855Sgabeblack@google.com    dut.m_clk(clock);
17012855Sgabeblack@google.com
17112855Sgabeblack@google.com    sc_start();
17212855Sgabeblack@google.com
17312855Sgabeblack@google.com    cout << "Program completed" << endl;
17412855Sgabeblack@google.com    return 0;
17512855Sgabeblack@google.com}
176