void PionOneToOneScheduler::startup(void) { // lock mutex for thread safety boost::mutex::scoped_lock scheduler_lock(m_mutex); if (! m_is_running) { PION_LOG_INFO(m_logger, "Starting thread scheduler"); m_is_running = true; // make sure there are enough services initialized while (m_service_pool.size() < m_num_threads) { boost::shared_ptr<ServicePair> service_ptr(new ServicePair()); m_service_pool.push_back(service_ptr); } // schedule a work item for each service to make sure that it doesn't complete for (ServicePool::iterator i = m_service_pool.begin(); i != m_service_pool.end(); ++i) { keepRunning((*i)->first, (*i)->second); } // start multiple threads to handle async tasks for (boost::uint32_t n = 0; n < m_num_threads; ++n) { boost::shared_ptr<boost::thread> new_thread(new boost::thread( boost::bind(&PionScheduler::processServiceWork, this, boost::ref(m_service_pool[n]->first)) )); m_thread_pool.push_back(new_thread); } } }
service_ptr service_pool::find(object_id const& id) const { boost::lock_guard<boost::recursive_mutex> lock(m_mutex); services::const_iterator iter = m_services.find(id); if(iter == m_services.end()) return service_ptr(); return iter->second; }