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); } } }
/** * TODO: Function mainLoop() implementation: * 1. get the SDL events * 2. process the SDL events (send the physics object physics events * and possibly the graphics object some also) * 3. delay a few milliseconds * 4. repeat * * if quit event, send stop signal to phys and graphics objects and return. */ int EventHandler::mainLoop() { graphics.startThread(); while (!graphics.isInitialized()) SDL_Delay(10); physics.startThread(); GLuint oldTime = SDL_GetTicks(); GLuint newTime; while(keepRunning()){ newTime = SDL_GetTicks(); if (newTime-oldTime <= EVENT_CHECK_TIME) { SDL_Delay(EVENT_CHECK_TIME-(newTime-oldTime)); newTime=SDL_GetTicks(); } if (graphics.isInitialized()) handleEvents(); oldTime=newTime; } physics.stopThread(); physics.waitForStop(); graphics.stopThread(); graphics.waitForStop(); return 0; }
void DopeApp::Run() { boost::asio::io_service::work keepRunning(m_ioService); m_ioService.run(); if (m_persistenceHandler != nullptr) { m_persistenceHandler->Stop(); } }
/** * go(): This is in fact the main game loop. * For the moment it computes physics and output sounds on each frame * but this could be optimized further. It also computes IA on each frame... */ bool HOO::Application::go(){ startup(); while(keepRunning()){ renderOneFrame(); computePhysics(); computeIA(); outputSound(); } shutDown(); return 0; }
void EventHandler::handleEvents() { SDL_Event event; while(SDL_PollEvent(&event) && keepRunning()) { switch(event.type) { case SDL_QUIT: stopThread(); break; case SDL_KEYDOWN: switch(event.key.keysym.sym) { case SDLK_p: physics.togglePause(); break; case SDLK_q: stopThread(); break; default: break; }break; case SDL_KEYUP: switch(event.key.keysym.sym) { default: break; } break; case SDL_MOUSEBUTTONDOWN: switch(event.button.button) { case SDL_BUTTON_LEFT: addRandomPMovingObject(event.button.x, graphics.getWindowHeight()-event.button.y); break; default: break; } break; case SDL_MOUSEBUTTONUP: switch(event.button.button) { case SDL_BUTTON_LEFT: break; default: break; } break; } } }
void PionSingleServiceScheduler::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; // schedule a work item to make sure that the service doesn't complete m_service.reset(); keepRunning(m_service, m_timer); // 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)) )); m_thread_pool.push_back(new_thread); } } }
bool IoServicesImpl::Run() { io_service::work keepRunning(_ioService); system::error_code ec; while (_shouldRun.load()) { try { _ioService.run(ec); } catch (const std::exception& ex) { _exceptionNotifier("Exception in IO service: ", ex); } } std::cout << "Stopping IO service." << std::endl; return true; }
//------------------------------------------------------------------------- int App::Run() { m_connection.Open(L"VehicleDatabaseCpp", L"0", 0, this, &m_dispatch); DatabaseInteraction::Instance().Init(); VehicleDatabaseServices::Instance().Init(); #ifdef NO_ACE // Start the asio io-service loop in order to receive DOB callbacks // for example OnCreateRequest in EntityOwner. // We also need to define some dummy work in order for the io_service // to keep running until we tell it to stop. boost::asio::io_service::work keepRunning(m_ioService); m_ioService.run(); #else // Start Ace event loop in order to receive DOB callbacks // for example OnCreateRequest in EntityOwner. ACE_Reactor::instance()->run_reactor_event_loop(); #endif return 0; }
void DopeApp::Run() { boost::asio::io_service::work keepRunning(m_ioService); m_ioService.run(); }