112855Sgabeblack@google.com#define SC_INCLUDE_DYNAMIC_PROCESSES 212855Sgabeblack@google.com 312855Sgabeblack@google.com#include <systemc> 412855Sgabeblack@google.com#include <cstring> 512855Sgabeblack@google.comusing namespace sc_core; 612855Sgabeblack@google.comusing namespace sc_dt; 712855Sgabeblack@google.comusing std::cout; 812855Sgabeblack@google.comusing std::endl; 912855Sgabeblack@google.com 1012855Sgabeblack@google.com// 6) sc_get_current_process_handle 1112855Sgabeblack@google.com 1212855Sgabeblack@google.comSC_MODULE(M) 1312855Sgabeblack@google.com{ 1412855Sgabeblack@google.com SC_CTOR(M) 1512855Sgabeblack@google.com { 1612855Sgabeblack@google.com sc_process_handle h; 1712855Sgabeblack@google.com sc_assert (!h.valid()); 1812855Sgabeblack@google.com h = sc_get_current_process_handle(); 1912855Sgabeblack@google.com sc_assert (!h.valid()); 2012855Sgabeblack@google.com SC_THREAD(T); 2112855Sgabeblack@google.com h = sc_get_current_process_handle(); 2212855Sgabeblack@google.com sc_assert (h.valid()); 2312855Sgabeblack@google.com sc_assert (strcmp(h.name(),"top.m.T") == 0); 2412855Sgabeblack@google.com sc_assert (h.proc_kind()==SC_THREAD_PROC_); 2512855Sgabeblack@google.com sc_assert (h.dynamic()==false); 2612855Sgabeblack@google.com sc_assert (h.terminated()==false); 2712855Sgabeblack@google.com sc_assert (h.get_process_object() != 0); 2812855Sgabeblack@google.com sc_assert (h.get_parent_object() == this); 2912855Sgabeblack@google.com 3012855Sgabeblack@google.com sc_spawn(sc_bind(&M::proc, this), "static_proc"); 3112855Sgabeblack@google.com h = sc_get_current_process_handle(); 3212855Sgabeblack@google.com sc_assert (h.valid()); 3312855Sgabeblack@google.com sc_assert (strcmp(h.name(),"top.m.static_proc") == 0); 3412855Sgabeblack@google.com sc_assert (h.proc_kind()==SC_THREAD_PROC_); 3512855Sgabeblack@google.com sc_assert (h.dynamic()==false); 3612855Sgabeblack@google.com sc_assert (h.terminated()==false); 3712855Sgabeblack@google.com sc_assert (h.get_process_object() != 0); 3812855Sgabeblack@google.com sc_assert (h.get_parent_object() == this); 3912855Sgabeblack@google.com } 4012855Sgabeblack@google.com sc_object* obj; 4112855Sgabeblack@google.com void T() 4212855Sgabeblack@google.com { 4312855Sgabeblack@google.com sc_process_handle h; 4412855Sgabeblack@google.com sc_assert (!h.valid()); 4512855Sgabeblack@google.com h = sc_get_current_process_handle(); 4612855Sgabeblack@google.com sc_assert (h.valid()); 4712855Sgabeblack@google.com sc_assert (strcmp(h.name(),"top.m.T") == 0); 4812855Sgabeblack@google.com sc_assert (h.proc_kind()==SC_THREAD_PROC_); 4912855Sgabeblack@google.com sc_assert (h.dynamic()==false); 5012855Sgabeblack@google.com sc_assert (h.terminated()==false); 5112855Sgabeblack@google.com sc_assert (h.get_process_object() != 0); 5212855Sgabeblack@google.com sc_assert (h.get_parent_object() == this); 5312855Sgabeblack@google.com 5412855Sgabeblack@google.com obj = h.get_process_object(); 5512855Sgabeblack@google.com sc_spawn_options opt; 5612855Sgabeblack@google.com opt.spawn_method(); 5712855Sgabeblack@google.com sc_spawn(sc_bind(&M::proc, this), "dynamic_proc", &opt); 5812855Sgabeblack@google.com wait(1, SC_NS); 5912855Sgabeblack@google.com } 6012855Sgabeblack@google.com void proc() 6112855Sgabeblack@google.com { 6212855Sgabeblack@google.com sc_process_handle h = sc_get_current_process_handle(); 6312855Sgabeblack@google.com sc_assert (h.valid()); 6412855Sgabeblack@google.com if (h.dynamic()) 6512855Sgabeblack@google.com { 6612855Sgabeblack@google.com sc_assert (strcmp(h.name(),"top.m.T.dynamic_proc") == 0); 6712855Sgabeblack@google.com sc_assert (h.proc_kind()==SC_METHOD_PROC_); 6812855Sgabeblack@google.com sc_assert (h.get_parent_object() == obj); 6912855Sgabeblack@google.com } 7012855Sgabeblack@google.com else 7112855Sgabeblack@google.com { 7212855Sgabeblack@google.com sc_assert (strcmp(h.name(),"top.m.static_proc") == 0); 7312855Sgabeblack@google.com sc_assert (h.proc_kind()==SC_THREAD_PROC_); 7412855Sgabeblack@google.com sc_assert (h.get_parent_object() == this); 7512855Sgabeblack@google.com } 7612855Sgabeblack@google.com sc_assert (h.terminated()==false); 7712855Sgabeblack@google.com sc_assert (h.get_process_object() != 0); 7812855Sgabeblack@google.com } 7912855Sgabeblack@google.com}; 8012855Sgabeblack@google.com 8112855Sgabeblack@google.comstruct Top: sc_module 8212855Sgabeblack@google.com{ 8312855Sgabeblack@google.com M *m; 8412855Sgabeblack@google.com Top(sc_module_name) 8512855Sgabeblack@google.com { 8612855Sgabeblack@google.com m = new M("m"); 8712855Sgabeblack@google.com } 8812855Sgabeblack@google.com}; 8912855Sgabeblack@google.com 9012855Sgabeblack@google.comint sc_main(int argc, char* argv[]) 9112855Sgabeblack@google.com{ 9212855Sgabeblack@google.com cout << "Should be silent..." << endl; 9312855Sgabeblack@google.com sc_process_handle h; 9412855Sgabeblack@google.com sc_assert (!h.valid()); 9512855Sgabeblack@google.com h = sc_get_current_process_handle(); 9612855Sgabeblack@google.com sc_assert (!h.valid()); 9712855Sgabeblack@google.com 9812855Sgabeblack@google.com Top top("top"); 9912855Sgabeblack@google.com sc_start(); 10012855Sgabeblack@google.com 10112855Sgabeblack@google.com cout << endl << "Success" << endl; 10212855Sgabeblack@google.com return 0; 10312855Sgabeblack@google.com} 104