00001
00002
00003
00004
00005
00006
00013 #include <systemc>
00014 #include "during.h"
00015 #include <boost/bind.hpp>
00016 #include "utils/io-lock.h"
00017 #include <signal.h>
00018
00019 using namespace std;
00020 using namespace sc_core;
00021
00022 SC_MODULE(A), sc_during
00023 {
00024 void compute() {
00025 L_COUT << "A 1: " << sc_time_stamp() << endl;
00026 L_COUT << "// TEST-EXPECT: A.f()" << endl;
00027 during(10, SC_NS, boost::bind(&A::f, this));
00028 L_COUT << "// TEST-EXPECT: A 2: 20 ns" << endl;
00029 L_COUT << "A 2: " << sc_time_stamp() << endl;
00030 }
00031
00032 SC_CTOR(A) {
00033 SC_THREAD(compute);
00034 }
00035
00036 void f() {
00037 L_COUT << "A.f()" << endl;
00038 L_COUT << "// TEST-EXPECT: A.g()" << endl;
00039 sc_call(boost::bind(&A::call_g, this));
00040 };
00041 void call_g() {
00042 during(10, SC_NS, boost::bind(&A::g, this));
00043 }
00044
00045 void g() {
00046 L_COUT << "A.g()" << endl;
00047 };
00048 };
00049
00050 void timeout(int sig) {
00051 (void)sig;
00052 cout << "Timeout occured!" << endl;
00053 exit(1);
00054 }
00055
00056 int sc_main(int argc, char *argv[])
00057 {
00058
00059 if (argc > 2 && !strcmp(argv[1], "--timeout")) {
00060 int t = atoi(argv[2]);
00061 cout << "// TEST-IGNORE: Setting up timeout of " << t << " seconds." << endl;
00062 struct sigaction action;
00063 action.sa_handler = timeout;
00064 sigaction(SIGALRM, &action, NULL);
00065 alarm(t);
00066 }
00067 A a("a");
00068 L_COUT << "elaboration done, start simulation" << endl;
00069 {
00070 measure_time t;
00071 sc_start();
00072 }
00073 L_COUT << "Simulation terminated. Terminating threads" << endl;
00074 return 0;
00075 }