Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "ModulableThreadPool.h"
- namespace NB
- {
- ModulableThreadPool::ModulableThreadPool(uint32_t threads) :
- m_ioWork(m_ioService)
- {
- while (threads--)
- m_threadPool.create_thread(boost::bind(&boost::asio::io_service::run, &m_ioService));
- m_schedulerThread = new boost::thread(boost::bind(&ModulableThreadPool::schedulerFunc, this));
- }
- ModulableThreadPool::~ModulableThreadPool()
- {
- m_ioService.stop();
- m_threadPool.join_all();
- m_schedulerThread->join();
- }
- void ModulableThreadPool::registerModule(IModule* module, ModulableThreadPool::ThreadModulePriority priority)
- {
- m_registeredModules.insert(std::make_pair(priority, module));
- }
- void ModulableThreadPool::unregisterModule(IModule* module)
- {
- }
- void ModulableThreadPool::schedulerFunc()
- {
- auto sleepTime = boost::chrono::milliseconds(10);
- while (true)
- {
- for (auto& registeredModule : m_registeredModules)
- {
- m_ioService.post(boost::bind(&IModule::doWork, registeredModule.second));
- }
- boost::this_thread::sleep_for(sleepTime);
- }
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement