Ejemplo n.º 1
0
void Database::EndThreads()
{
	//these 2 loops spin until theres nothing left
	while(1)
	{
		QueryBuffer* buf = query_buffer.pop();
		if(buf == NULL)
			break;
		query_buffer.push(buf);
	}
	while(1)
	{
		char* buf = queries_queue.pop();
		if(buf == NULL)
			break;
		queries_queue.push(buf);
	}

	SetThreadState(THREADSTATE_TERMINATE);

	while(ThreadRunning || qt)
	{
		arcpro::Sleep(100);
		if(!ThreadRunning)
			break;
	}
}
Ejemplo n.º 2
0
bool Lacrimi::run()
{
    Delay(400);
    if(GetConfigBool("Features", "LuaEngine", true))
    {
        L_LuaEngineMgr = new LuaEngineMgr();
        L_LuaEngineMgr->Startup();
        Delay(100);
        while(LuaEngineIsStarting)
            Delay(100);
    }

    uint32 curTime = getMSTime();
    uint32 m_StatDumpTimer = curTime+15000, m_CleanupDelay = curTime+10000;
    while(GetThreadState() != THREADSTATE_SELF_TERMINATE)
    {
        curTime = getMSTime();
        if(!SetThreadState(THREADSTATE_BUSY))
            break;

        if(dumpstats)
        {
            if(curTime > m_StatDumpTimer)
            {
                DumpStats();
                m_StatDumpTimer = curTime+60000;
            }
        }

        if(curTime > m_CleanupDelay)
            Cleanup();
        if(!SetThreadState(THREADSTATE_SLEEPING))
            break;
        Delay(5);
    }
    sLog.Notice("Lacrimi", "Terminating...");

    FinalCleanup();
    if(database)
        _StopDB();
    OnShutdown();
    return true;
}
Ejemplo n.º 3
0
bool OCThreadBase::Start()
{
	m_ThreadHandle = CreateThread( NULL, STACK_SIZE ,_ThreadProc, this, 0, &m_dwThreadID );
	assert( m_ThreadHandle );

	SetThreadState( THREAD_STATE_STARTED );

	bool bResult = ( m_ThreadHandle != NULL );

	return bResult;
}
void CBSPLightingThread::StartLighting( char const *pVMFFileWithEntities )
{
	// First, kill any lighting going on.
	Interrupt();

	// Store the VMF file data for the thread.
	int len = strlen( pVMFFileWithEntities ) + 1;
	m_VMFFileWithEntities.CopyArray( pVMFFileWithEntities, len );

	// Tell the thread to start lighting.
	SetThreadState( STATE_LIGHTING );
	SetThreadCmd( THREADCMD_LIGHT );
}
DWORD CBSPLightingThread::ThreadMainLoop()
{
	while( 1 )
	{
		int cmd = GetThreadCmd();

		if( cmd == THREADCMD_NONE )
		{
			// Keep waiting for a new command.
			Sleep( 10 );
		}
		else if( cmd == THREADCMD_LIGHT )
		{
			if( m_pVRadDLL->DoIncrementalLight( m_VMFFileWithEntities.Base() ) )
				SetThreadState( STATE_FINISHED );
			else
				SetThreadState( STATE_IDLE );
		}
		else if( cmd == THREADCMD_EXIT )
		{
			return 0;
		}
	}
}
Ejemplo n.º 6
0
bool Database::run()
{
	SetThreadName("Database Execute Thread");
	SetThreadState(THREADSTATE_BUSY);
	ThreadRunning = true;
	char* query = queries_queue.pop();
	DatabaseConnection* con = GetFreeConnection();
	while(1)
	{

		if(query != NULL)
		{
			if(con == NULL)
				con = GetFreeConnection();
			_SendQuery(con, query, false);
			delete[] query;
		}

		if(GetThreadState() == THREADSTATE_TERMINATE)
			break;
		query = queries_queue.pop();

		if(query == NULL)
		{
			if(con != NULL)
				con->Busy.Release();
			con = NULL;
			arcpro::Sleep(10);
		}
	}

	if(con != NULL)
		con->Busy.Release();

	// execute all the remaining queries
	query = queries_queue.pop();
	while(query)
	{
		con = GetFreeConnection();
		_SendQuery(con, query, false);
		con->Busy.Release();
		delete[] query;
		query = queries_queue.pop();
	}

	ThreadRunning = false;
	return false;
}
Ejemplo n.º 7
0
void OCThreadBase::RunThread()
{
	TCHAR str[512];
	wsprintf( str, L"Thread %d Start\n", m_dwThreadID );
	OutputDebugString( str );

	Loop();

	wsprintf( str, L"Thread %d End\n", m_dwThreadID );
	OutputDebugString( str );
	

	CloseHandle( m_ThreadHandle );
	m_ThreadHandle = NULL; 
	SetThreadState( THREAD_STATE_END );
}
Ejemplo n.º 8
0
void Database::EndThreads()
{
	SetThreadState(THREADSTATE_TERMINATE);
	while(ThreadRunning || qt)
	{
		if(query_buffer.get_size() == 0)
			query_buffer.GetCond().Broadcast();
	
		if(queries_queue.get_size() == 0)
			queries_queue.GetCond().Broadcast();

		Sleep(100);
		if(!ThreadRunning)
			break;
			
		Sleep(1000);
	}
}
Ejemplo n.º 9
0
bool Database::run()
{
	SetThreadName("Database Execute Thread");
	SetThreadState(THREADSTATE_BUSY);
	ThreadRunning = true;
	char * query = queries_queue.pop();
	DatabaseConnection * con = GetFreeConnection();
	while(query)
	{
		_SendQuery( con, query, false );
		delete[] query;
		if(ThreadState == THREADSTATE_TERMINATE)
			break;

		query = queries_queue.pop();
	}

	con->Busy.Release();

	if(queries_queue.get_size() > 0)
	{
		// execute all the remaining queries
		query = queries_queue.pop_nowait();
		while(query)
		{
			DatabaseConnection * con = GetFreeConnection();
			_SendQuery( con, query, false );
			con->Busy.Release();
			delete[] query;
			query=queries_queue.pop_nowait();
		}
	}

	ThreadRunning = false;
	return false;
}
Ejemplo n.º 10
0
void CThread::OnShutdown()
{
    SetThreadState(THREADSTATE_TERMINATE);
}
Ejemplo n.º 11
0
void CThread::OnShutdown()
{
	last_updated = 0;
	SetThreadState(THREADSTATE_TERMINATE);
}