Advertisement
Guest User

Untitled

a guest
Jan 4th, 2015
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. #include "ModulableThreadPool.h"
  2.  
  3. namespace NB
  4. {
  5.  
  6. ModulableThreadPool::ModulableThreadPool(uint32_t threads) :
  7.     m_ioWork(m_ioService)
  8. {
  9.     while (threads--)
  10.         m_threadPool.create_thread(boost::bind(&boost::asio::io_service::run, &m_ioService));
  11.  
  12.     m_schedulerThread = new boost::thread(boost::bind(&ModulableThreadPool::schedulerFunc, this));
  13. }
  14.  
  15. ModulableThreadPool::~ModulableThreadPool()
  16. {
  17.     m_ioService.stop();
  18.     m_threadPool.join_all();
  19.  
  20.     m_schedulerThread->join();
  21. }
  22.  
  23. void ModulableThreadPool::registerModule(IModule* module, ModulableThreadPool::ThreadModulePriority priority)
  24. {
  25.     m_registeredModules.insert(std::make_pair(priority, module));
  26. }
  27.  
  28. void ModulableThreadPool::unregisterModule(IModule* module)
  29. {
  30. }
  31.  
  32. void ModulableThreadPool::schedulerFunc()
  33. {
  34.     auto sleepTime = boost::chrono::milliseconds(10);
  35.     while (true)
  36.     {
  37.         for (auto& registeredModule : m_registeredModules)
  38.         {
  39.             m_ioService.post(boost::bind(&IModule::doWork, registeredModule.second));
  40.         }
  41.         boost::this_thread::sleep_for(sleepTime);
  42.     }
  43. }
  44.  
  45.  
  46. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement