test219.cpp revision 12855:588919e0e4aa
1#define SC_INCLUDE_DYNAMIC_PROCESSES 2 3#include <systemc> 4using namespace sc_core; 5using namespace sc_dt; 6using std::cout; 7using std::endl; 8 9// 19) Call to sc_spawn in what would have been the final update phase... 10 11sc_event ev; 12 13struct Prim: sc_prim_channel, sc_interface 14{ 15 Prim() : count(0) {} 16 17 void write() { 18 request_update(); 19 } 20 void update() { 21 sc_spawn(sc_bind(&Prim::spawned_proc, this)); 22 } 23 void spawned_proc() 24 { 25 ++ count; 26 ev.notify(5, SC_NS); 27 } 28 const sc_event& default_event() const { return ev; } 29 int count; 30}; 31 32SC_MODULE(M) 33{ 34 Prim prim; 35 SC_CTOR(M) 36 : ME_count(0) 37 { 38 SC_THREAD(T); 39 SC_METHOD(ME); 40 sensitive << prim; 41 dont_initialize(); 42 } 43 void T() 44 { 45 wait(10, SC_NS); 46 prim.write(); 47 sc_assert(sc_time_stamp() == sc_time(10, SC_NS)); 48 } 49 void ME() 50 { 51 ++ ME_count; 52 sc_assert(sc_time_stamp() == sc_time(15, SC_NS)); 53 } 54 int ME_count; 55}; 56 57struct Top: sc_module 58{ 59 M *m; 60 Top(sc_module_name) 61 { 62 m = new M("m"); 63 } 64}; 65 66int sc_main(int argc, char* argv[]) 67{ 68 cout << "Should be silent..." << endl; 69 70 Top top("top"); 71 sc_start(); 72 73 sc_assert(top.m->prim.count == 1); 74 sc_assert(top.m->ME_count == 1); 75 76 77 cout << endl << "Success" << endl; 78 return 0; 79} 80