Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00014 #include "thread-pool-base.h"
00015 #include "utils/io-lock.h"
00016 #include "task-manager.h"
00017 #include "utils/cpu-affinity.h"
00018
00019 using namespace std;
00020
00021 atomic_variable<int> thread_pool_base::m_index(0);
00022
00023 void thread_pool_base::process_tasks(thread_pool_base *p,
00024 sc_core::sc_process_b *sc_process) {
00025 #ifdef SC_DURING_USE_AFFINITY
00026 int affinity = m_index++ % boost::thread::hardware_concurrency();
00027 L_COUT << "// TEST-IGNORE: affinity = " << affinity << endl;
00028 cpu_bind(affinity);
00029 #endif
00030 task_manager::get_instance()->alloc_current_task();
00031 while (true) {
00032 sync_task *r = p->pop_task(sc_process);
00033 task_manager::get_instance()->set_current_task(r);
00034 if (r == NULL) {
00035 return;
00036 }
00037
00038 r->process();
00039 }
00040 }
00041
00042 thread_pool_base::thread_ptr
00043 thread_pool_base::add_thread(sc_core::sc_process_b *sc_process) {
00044 thread_ptr t = new boost::thread(process_tasks, this, sc_process);
00045 m_thread_array.push_back(t);
00046
00047 return t;
00048 }
00049
00050 void thread_pool_base::stop_all_threads() {
00051 L_COUT << "// TEST-IGNORE: End of simulation, sending stop tasks" << endl;
00052 for (unsigned i = 0; i < m_thread_array.size(); i++)
00053 m_thread_array[i]->interrupt();
00054 L_COUT << "// TEST-IGNORE: All threads interrupted, now joining" << endl;
00055 for (unsigned i = 0; i < m_thread_array.size(); i++)
00056 m_thread_array[i]->join();
00057 L_COUT << "// TEST-IGNORE: all joins completed" << endl;
00058 }
00059
00060 thread_pool_base::thread_pool_base() {
00061
00062 task_manager::get_instance();
00063 }