Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00014 #include <systemc>
00015 #include "during.h"
00016
00017 using namespace std;
00018 using namespace sc_core;
00019
00020 SC_MODULE(A), sc_during
00021 {
00022 int x;
00023 void producer() {
00024 L_COUT << "A: 1" << endl;
00025 wait(10, SC_NS);
00026 usleep(100000);
00027 L_COUT << "A: before x = 10, " << sc_time_stamp() << endl;
00028 x = 10;
00029 wait(10, SC_NS);
00030 usleep(100000);
00031 L_COUT << "A: before x = 20, " << sc_time_stamp() << endl;
00032 x = 20;
00033 usleep(100000);
00034 wait(100, SC_NS);
00035 usleep(100000);
00036 L_COUT << "A: before x = 300, " << sc_time_stamp() << endl;
00037 x = 300;
00038 }
00039
00040 void consumer() {
00041 during(11, SC_NS, bind_this(&A::f));
00042 assert(x == 300);
00043 L_COUT << "// TEST-EXPECT: consumer: 122 ns" << endl;
00044 L_COUT << "consumer: " << sc_time_stamp() << endl;
00045 }
00046
00047 SC_CTOR(A) {
00048 x = 0;
00049 SC_THREAD(producer);
00050 SC_THREAD(consumer);
00051 }
00052
00053 void f(void) {
00054
00055 catch_up();
00056 L_COUT << "f: at t=11, x == " << x << endl;
00057 assert(x == 10);
00058 L_COUT << "f: assertion OK at t=11" << endl;
00059 usleep(100000);
00060
00061
00062 assert(x == 10);
00063 extra_time(8, SC_NS);
00064 L_COUT << "f: at t=19, x == " << x << endl;
00065 assert(x == 10);
00066 L_COUT << "f: assertion OK at t=19" << endl;
00067 extra_time(2, SC_NS);
00068 catch_up();
00069 L_COUT << "f: at t=21, x == " << x << endl;
00070 assert(x == 20);
00071 for (int i = 0; i < 50; i++)
00072 extra_time(1, SC_NS);
00073 for (int i = 0; i < 5; i++) {
00074 usleep(100000);
00075 for (int j = 0; j < 10; j++)
00076 extra_time(1, SC_NS);
00077 }
00078 extra_time(1, SC_NS);
00079 catch_up();
00080 assert(x == 300);
00081 };
00082 };
00083
00084 int sc_main(int argc, char *argv[])
00085 {
00086 (void)argc; (void)argv;
00087 A a("a");
00088 {
00089 measure_time t;
00090 sc_start();
00091 }
00092
00093 return 0;
00094 }