test04.cpp revision 12855
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 Original Author: Bishnupriya Bhattacharya, Cadence Design Systems, 23 September 5, 2003 24 25 *****************************************************************************/ 26 27// test error message for SC_FORK-SC_JOIN on dynamic method process handles 28 29/***************************************************************************** 30 31 MODIFICATION LOG - modifiers, enter your name, affiliation, date and 32 changes you are making here. 33 34 Name, Affiliation, Date: 35 Description of Modification: 36 37 *****************************************************************************/ 38// $Log: test04.cpp,v $ 39// Revision 1.2 2011/02/01 17:17:40 acg 40// Andy Goodrich: update of copyright notice, added visible CVS logging. 41// 42 43#define SC_INCLUDE_DYNAMIC_PROCESSES 44#include <systemc.h> 45 46 47class module1 : public sc_module 48{ 49private: 50 int method_count; 51public: 52 53 SC_HAS_PROCESS(module1); 54 55 module1(sc_module_name name) : sc_module(name), 56 method_count(0) 57 { 58 SC_THREAD(main); 59 } 60 61 void main() 62 { 63 int r; 64 sc_event e1, e2, e3, e4; 65 sc_spawn_options o1, o2, o3, o4; 66 67 cout << endl << sc_time_stamp() << ", " 68 << sc_get_current_process_handle().name() 69 << ": main thread, Before spawning round robin methods " 70 << endl << endl; 71 72 e1.notify(15, SC_NS); 73 o1.spawn_method(); 74 o2.spawn_method(); 75 o3.spawn_method(); 76 o4.spawn_method(); 77 78 // Spawn several threads that co-operatively execute in round robin order 79 80 SC_FORK 81 sc_spawn(&r, 82 sc_bind(&module1::round_robin, this, "1", sc_ref(e1), sc_ref(e2), 1), "mth1", &o1), 83 sc_spawn(&r, 84 sc_bind(&module1::round_robin, this, "2", sc_ref(e2), sc_ref(e3), 1), "mth2", &o2), 85 sc_spawn(&r, 86 sc_bind(&module1::round_robin, this, "3", sc_ref(e3), sc_ref(e4), 1), "mth3", &o3), 87 sc_spawn(&r, 88 sc_bind(&module1::round_robin, this, "4", sc_ref(e4), sc_ref(e1), 1), "mth4", &o4), 89 SC_JOIN 90 91 cout << endl << sc_time_stamp() << ", " 92 << sc_get_current_process_handle().name() 93 << ": main thread, Issuing wait(60, SC_NS)" << endl; 94 95 wait(60, SC_NS); 96 97 cout << endl << sc_time_stamp() << ", " 98 << sc_get_current_process_handle().name() 99 << ": Done main thread." << endl; 100 } 101 102 int round_robin(const char *str, sc_event& receive, sc_event& send, int cnt) 103 { 104 cout << sc_time_stamp() << ", " 105 << sc_get_current_process_handle().name() 106 << ": In Round robin method " << str; 107 108 if (method_count < 4) { 109 method_count++; 110 next_trigger(receive); 111 cout << ". Issued next_trigger. " << endl; 112 } else { 113 send.notify(10, SC_NS); 114 cout << ". Notified. Ending Round robin method " << str << endl; 115 } 116 117 return 0; 118 } 119 120}; 121int sc_main (int argc , char *argv[]) 122{ 123 module1 mod1("mod1"); 124 125 sc_start(100, SC_NS); 126 127 return 0; 128} 129