Пример #1
0
/*
=============
RunThreadsOn
=============
*/
void RunThreadsOn( int workcnt, qboolean showpacifier, RunThreadsFn fn, void *pUserData )
{
    int		start, end;

    start = Plat_FloatTime();
    dispatch = 0;
    workcount = workcnt;
    StartPacifier("");
    pacifier = showpacifier;

#ifdef _PROFILE
    threaded = false;
    (*func)( 0 );
    return;
#endif


    RunThreads_Start( fn, pUserData );
    RunThreads_End();


    end = Plat_FloatTime();
    if (pacifier)
    {
        EndPacifier(false);
        printf (" (%i)\n", end-start);
    }
}
// This is called by VMPI_Finalize in case it's shutting down due to an Error() call.
// In this case, it's important that the worker threads here are shut down before VMPI shuts
// down its sockets.
void DistributeWork_Cancel()
{
    if ( g_pCurWorkerThreadsInfo )
    {
        Msg( "\nDistributeWork_Cancel saves the day!\n" );
        g_pCurWorkerThreadsInfo->m_bMasterFinished = true;
        g_bVMPIEarlyExit = true;
        RunThreads_End();
    }
}
void DistributeWork_Worker( CDSInfo *pInfo, ProcessWorkUnitFn processFn )
{
    if ( g_iVMPIVerboseLevel >= 1 )
        Msg( "VMPI_DistributeWork call %d started.\n", g_iCurDSInfo+1 );

    CWorkerInfo *pWorkerInfo = &pInfo->m_WorkerInfo;
    pWorkerInfo->m_pProcessFn = processFn;

    g_pCurWorkerThreadsInfo = pInfo;
    g_pCurDistributorWorker->Init( pInfo );

    // Start a couple threads to do the work.
    RunThreads_Start( VMPI_WorkerThread, pInfo, g_bSetThreadPriorities ? k_eRunThreadsPriority_Idle : k_eRunThreadsPriority_UseGlobalState );
    if ( g_iVMPIVerboseLevel >= 1 )
        Msg( "RunThreads_Start finished successfully.\n" );

    if ( VMPI_IsSDKMode() )
    {
        Msg( "\n" );
        while ( g_iMasterFinishedDistributeWorkCall < g_iCurDSInfo )
        {
            VMPI_DispatchNextMessage( 300 );

            Msg( "\rThreads status: " );
            for ( int i=0; i < ARRAYSIZE( g_ThreadWUs ); i++ )
            {
                if ( g_ThreadWUs[i] != ~0ull )
                    Msg( "%d: WU %5d  ", i, (int)g_ThreadWUs[i] );
            }

            VMPI_FlushGroupedPackets();
        }
        Msg( "\n" );
    }
    else
    {
        while ( g_iMasterFinishedDistributeWorkCall < g_iCurDSInfo )
        {
            VMPI_DispatchNextMessage();
        }
    }


    // Close the threads.
    g_pCurWorkerThreadsInfo = NULL;
    RunThreads_End();

    if ( g_iVMPIVerboseLevel >= 1 )
        Msg( "VMPI_DistributeWork call %d finished.\n", g_iCurDSInfo+1 );
}