Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00014 #include <systemc>
00015 #include "during.h"
00016
00017 #include "utils/io-lock.h"
00018
00019 using namespace std;
00020 using namespace sc_core;
00021
00022 template<typename T>
00023 class atomic_variable {
00024 public:
00025 atomic_variable(T t) : v(t) {}
00026
00027 T read() {
00028 boost::unique_lock<boost::mutex> lock(m_mut);
00029 return v;
00030 }
00031
00032 void write(T t) {
00033 boost::unique_lock<boost::mutex> lock(m_mut);
00034 v = t;
00035 }
00036 private:
00037 T v;
00038 boost::mutex m_mut;
00039 };
00040
00041 SC_MODULE(A), sc_during
00042 {
00043 atomic_variable<bool> b;
00044
00045 void producer() {
00046 L_COUT << "A 1: " << sc_time_stamp() << endl;
00047 wait(100, SC_NS);
00048 b.write(true);
00049 }
00050
00051 void consumer() {
00052 L_COUT << "B 1: " << sc_time_stamp() << endl;
00053 during(1, SC_NS, bind_this(&A::poll));
00054 L_COUT << "B 2: polling done" << endl;
00055 L_COUT << "// TEST-EXPECT: B 3: 101 ns" << endl;
00056 L_COUT << "B 3: " << sc_time_stamp() << endl;
00057 }
00058 SC_CTOR(A) : b(false) {
00059 SC_THREAD(producer);
00060 SC_THREAD(consumer);
00061 }
00062
00063 void poll() {
00064 while (!b.read()) {
00065 extra_time(2, SC_NS);
00066 catch_up();
00067 }
00068 };
00069 };
00070
00071 int sc_main(int argc, char *argv[])
00072 {
00073 (void)argc; (void)argv;
00074 A a("a");
00075 {
00076 measure_time t;
00077 sc_start();
00078 }
00079
00080 return 0;
00081 }