示例#1
0
void MainWindow::StartGame(std::unique_ptr<BootParameters>&& parameters)
{
  // If we're running, only start a new game once we've stopped the last.
  if (Core::GetState() != Core::State::Uninitialized)
  {
    if (!RequestStop())
      return;

    // As long as the shutdown isn't complete, we can't boot, so let's boot later
    m_pending_boot = std::move(parameters);
    return;
  }
  // Boot up, show an error if it fails to load the game.
  if (!BootManager::BootCore(std::move(parameters)))
  {
    QMessageBox::critical(this, tr("Error"), tr("Failed to init core"), QMessageBox::Ok);
    return;
  }
  ShowRenderWidget();

#ifdef Q_OS_WIN
  // Prevents Windows from sleeping, turning off the display, or idling
  EXECUTION_STATE shouldScreenSave =
      SConfig::GetInstance().bDisableScreenSaver ? ES_DISPLAY_REQUIRED : 0;
  SetThreadExecutionState(ES_CONTINUOUS | shouldScreenSave | ES_SYSTEM_REQUIRED);
#endif
}
示例#2
0
void CThread::Stop(unsigned long ulSleepFrequency)
{
	//Ask the thread to stop
	RequestStop();

	//Wait until the end of the thread
	WaitTillStopped(ulSleepFrequency);
}
示例#3
0
Thread::~Thread()
{
	if (IsAlive())
	{
		RequestStop();

		glfwWaitThread(m_oThread, GLFW_WAIT);
		m_oThread = -1;
		std::cout << m_sName << " thread has been shut down.\n";
	}

	///FpsCounter::RemoveCounter(m_pFpsCounter);
}
示例#4
0
bool MainWindow::eventFilter(QObject* object, QEvent* event)
{
  if (event->type() == QEvent::Close)
  {
    if (RequestStop() && object == this)
      m_exit_requested = true;

    static_cast<QCloseEvent*>(event)->ignore();
    return true;
  }

  return false;
}
示例#5
0
bool CThread::WaitTimeout(unsigned long ulTimeout,int iStopMode)
{
	unsigned long ulCount=ulTimeout;

	//Wait until the end of the thread or the timeout
	while(IsRunning() && ulCount>0)
	{
		SleepMillisecs(1000);
		ulCount--;
	}

	/*
	iStopMode : 0 = do not stop the thread after timeout
	            1 = request the thread o stop after timeout
				2 = force the thread to stop
	*/
	if(IsRunning())
	{
		switch(iStopMode)
		{
		case 1:
			RequestStop();
			break;
		case 2:
			ForceStop();
			break;
		default:
			break;
		}
		return false;
	}
	else
	{
		return true;
	}
}
示例#6
0
	ThreadBoost::~ThreadBoost()
	{
		RequestStop();
		WaitForStop();
	}
示例#7
0
void CThread::ForceStop()
{
	//The thread must be killed
	//TODO (Now, we just ask the thread to stop)
	RequestStop();
}
示例#8
0
int RAD_Thread::StopAndWait(unsigned int delay)
{
    if(!m_StartStopLock.Acquire(5000, __FILE__, __LINE__))
        return -1;

    // Check state to see whether it could be stopped
    if(m_handle == 0) {
        radlog(L_WARN, "[RAD_Thread] '%s' already stopped",
               m_ThreadName.c_str());
        m_StartStopLock.Release(__FILE__, __LINE__);
        return -1;
    }

    m_bShouldWatch = false; // prevent from watching-dogged

    if(!IsStopped())
        RequestStop();

    DEBUG("[RAD_Thread] Requested termination of '%s', "
          "waiting %u msec for end", m_ThreadName.c_str(), delay);

    // wait for the thread to stop if it is still running
    rad_assert(m_Alive != ASUnused);
    bool isKilled = false;
    if(m_Alive == ASAlive) {
        bool ret = m_StartStopLock.Wait(delay, __FILE__, __LINE__);
        if(ret == false) {
            radlog(L_WARN, "[RAD_Thread] '%s' did not end within %u msec",
                   m_ThreadName.c_str(), delay);
            KillThread(9); // 9 - SIGKILL
            m_Alive = ASStop;
            isKilled = true;
        }
    }
    rad_assert(m_Alive == ASStop || m_Alive == ASDead);

    // join the thread to deallocate thread resources
#ifdef RAD_OS_WIN32
    if(WaitForSingleObject((HANDLE)m_handle, INFINITE) != WAIT_OBJECT_0) {
        radlog(L_ERROR|L_CONS, "[RAD_Thread] Failed to join: %s",
               RAD_Util::GetLastErrDesc("WaitForSingleObject").c_str());
        m_StartStopLock.Release(__FILE__, __LINE__);
        return -1;
    }
    DWORD dwExitCode;
    if(!GetExitCodeThread((HANDLE)m_handle, &dwExitCode)) {
        radlog(L_ERROR|L_CONS, "[RAD_Thread] %s",
               RAD_Util::GetLastErrDesc("GetExitCodeThread").c_str());
        m_StartStopLock.Release(__FILE__, __LINE__);
        return -1;
    }
    if(!CloseHandle((HANDLE)m_handle)) {
        radlog(L_ERROR|L_CONS, "[RAD_Thread] %s",
               RAD_Util::GetLastErrDesc("CloseHandle").c_str());
        m_StartStopLock.Release(__FILE__, __LINE__);
        return -1;
    }
    Reset();
    m_StartStopLock.Release(__FILE__, __LINE__);
    return dwExitCode;
#else
    void* retcode;
    if(pthread_join((pthread_t)m_handle, &retcode)) {
        radlog(L_ERROR|L_CONS, "[RAD_Thread] %s",
               RAD_Util::GetLastErrDesc("pthread_join").c_str());
        m_StartStopLock.Release(__FILE__, __LINE__);
        return -1;
    }
    Reset();
    m_StartStopLock.Release(__FILE__, __LINE__);
    return (isKilled ? 9 : (int)retcode);
#endif
}