Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00013 #ifndef DURING_THREAD_H
00014 #define DURING_THREAD_H
00015
00016 #include "during-if.h"
00017 #include <boost/thread.hpp>
00018 #include "task-manager.h"
00019 #include "async-event-queue.h"
00020
00021 class sc_during_thread : public sc_during_if {
00022 public:
00023 sc_during_thread();
00024
00025 using sc_during_if::during;
00026 using sc_during_if::extra_time;
00027 using sc_during_if::catch_up;
00028
00029 void extra_time(const sc_core::sc_time & t);
00030
00031 void catch_up(const sc_core::sc_time & t);
00032
00033 void sc_call(const boost::function<void()> & f);
00034
00035 void during(const sc_core::sc_time & time,
00036 const boost::function<void()> & routine) {
00037 sync_task r(routine, time);
00038 boost::thread t(call_routine, &r);
00039 m_current_thread = &t;
00040 r.wait_for_completion();
00041 m_current_thread = NULL;
00042 t.join();
00043 }
00044
00045 virtual ~sc_during_thread() {
00046 if (m_current_thread) {
00047
00048
00049
00050
00051
00052
00053
00054 m_current_thread->interrupt();
00055 m_current_thread->join();
00056 }
00057 };
00058
00059 mode get_mode() { return thread; }
00060
00061 private:
00062
00063 static void call_routine(sync_task *r) {
00064 task_manager::get_instance()->alloc_current_task();
00065 task_manager::get_instance()->set_current_task(r);
00066 r->process();
00067 task_manager::get_instance()->set_current_task(NULL);
00068 }
00069
00070 boost::thread *m_current_thread;
00071 };
00072
00073 #endif // DURING_THREAD_H