00001
00002
00003
00004
00005
00006
00015 #include <systemc>
00016 #include "during.h"
00017 #include "utils/io-lock.h"
00018
00019 #include <signal.h>
00020 #include <unistd.h>
00021
00022 using namespace std;
00023 using namespace sc_core;
00024
00025 SC_MODULE(Eat_one_thread), sc_during
00026 {
00027 void compute() {
00028 during(0, SC_SEC, boost::bind(&Eat_one_thread::forever, this));
00029 }
00030
00031 SC_CTOR(Eat_one_thread) {
00032 SC_THREAD(compute);
00033 }
00034
00035 void forever(void) {
00036 L_COUT << "Eat_one_thread started one task" << endl;
00037 extra_time(1, SC_NS);
00038 for (int i = 1; i <= 10; i++) {
00039 extra_time(5, SC_SEC);
00040 usleep(1000);
00041 catch_up();
00042 }
00043 };
00044 };
00045
00046 SC_MODULE(B), sc_during
00047 {
00048 void compute() {
00049 wait(2, SC_NS);
00050 L_COUT << "All Eat_one_thread must have started by now" << endl;
00051 during(4, SC_NS, boost::bind(&B::f, this));
00052 L_COUT << "// TEST-EXPECT: B 2: 10 ns" << endl;
00053 L_COUT << "B 2: " << sc_time_stamp() << endl;
00054 wait(14, SC_NS);
00055 L_COUT << "B 3: " << sc_time_stamp() << endl;
00056 }
00057
00058 SC_CTOR(B) {
00059 SC_THREAD(compute);
00060 }
00061
00062 void f(void) {
00063 L_COUT << "B.f()" << endl;
00064 for (int i = 0; i < 4; i++) {
00065 extra_time(1, SC_NS);
00066 }
00067 };
00068 };
00069
00070 void timeout(int sig) {
00071 (void)sig;
00072 cout << "Timeout occured!" << endl;
00073 exit(1);
00074 }
00075
00076 int sc_main(int argc, char *argv[])
00077 {
00078 if (argc > 2 && !strcmp(argv[1], "--timeout")) {
00079 int t = atoi(argv[2]);
00080 cout << "// TEST-IGNORE: Setting up timeout of " << t << " seconds." << endl;
00081 struct sigaction action;
00082 action.sa_handler = timeout;
00083 sigaction(SIGALRM, &action, NULL);
00084 alarm(t);
00085 }
00086 Eat_one_thread one("one"), two("two"), three("three");
00087 B b("b");
00088 {
00089 measure_time t;
00090 sc_start();
00091 }
00092
00093 return 0;
00094 }