Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00014 #include <systemc>
00015
00016 #define DURING_MODE thread
00017 #include "during.h"
00018 #include <boost/bind.hpp>
00019 #include <boost/thread.hpp>
00020 #include "utils/io-lock.h"
00021
00022 using namespace std;
00023 using namespace sc_core;
00024
00025 SC_MODULE(A), sc_during
00026 {
00027 void compute() {
00028 i = 0;
00029 during(10, SC_NS, boost::bind(&A::f, this));
00030 }
00031
00032 void tick() {
00033 wait(1, SC_NS);
00034 for (i = 0; i <= 10;) {
00035 {
00036 boost::unique_lock<boost::mutex> lock(m_mut);
00037 i++;
00038 }
00039 m_cond.notify_all();
00040 usleep(10000);
00041 wait(2, SC_NS);
00042 L_COUT << "tick: " << sc_time_stamp() << " (i = " << i << ")" << endl;
00043 }
00044 }
00045
00046 void m1() {
00047 L_COUT << "m1: " << sc_time_stamp() << endl;
00048 }
00049
00050 void m2() {
00051 L_COUT << "m2: " << sc_time_stamp() << endl;
00052 }
00053
00054 SC_CTOR(A) {
00055 SC_THREAD(compute);
00056 SC_THREAD(tick);
00057 SC_METHOD(m1); sensitive << e1;
00058 SC_METHOD(m2); sensitive << e2;
00059 }
00060
00061 void wait_i(int expected_i) {
00062 boost::unique_lock<boost::mutex> lock(m_mut);
00063 while (i < expected_i) {
00064 m_cond.wait(lock);
00065 }
00066 }
00067
00068 void f() {
00069 wait_i(2);
00070 L_COUT << "// TEST-EXPECT: A.f(): 3 ns" << endl;
00071 L_COUT << "A.f(): " << sc_time_stamp() << endl;
00072 q.async_notify_event(e1);
00073
00074 q.async_notify_event(e1);
00075 q.async_notify_event(e2);
00076 wait_i(4);
00077 L_COUT << "// TEST-EXPECT: A.f(): 7 ns" << endl;
00078 L_COUT << "A.f(): " << sc_time_stamp() << endl;
00079 L_COUT << "// TEST-EXPECT: m1: 7 ns" << endl;
00080 q.async_notify_event(e1);
00081 };
00082
00083 sc_event e1, e2;
00084 async_event_queue q;
00085
00086 boost::condition_variable m_cond;
00087 boost::mutex m_mut;
00088 int i;
00089 };
00090
00091 int sc_main(int, char **)
00092 {
00093 #ifndef SC_CALL_USES_ASYNC_REQUEST_UPDATE
00094
00095 L_COUT << "// TEST-SKIPPED: SC_CALL_USES_ASYNC_REQUEST_UPDATE is not used" << endl;
00096 return 0;
00097 #endif
00098 A a("a");
00099 L_COUT << "elaboration done, start simulation" << endl;
00100 {
00101 measure_time t;
00102 sc_start();
00103 }
00104 L_COUT << "Simulation terminated. Terminating threads" << endl;
00105 return 0;
00106 }