void TaskProxy::ExecuteTaskGroups( bool _bUseCallerThread, TaskGroup* _aGroup, const uint32 _cnGroup ) { const Array<WorkerThread*>& rvpThreadPool = WorkerThreadManager::s_GetInstance()->_GetPool(); uint32 i, j, nThread = rvpThreadPool.size(); // Define proxy for threads for( i = 0; i < nThread; i++ ) rvpThreadPool[i]->SetTaskProxy( this ); for( j = 0; j < _cnGroup; j++ ) { const Array<Task*>& rvpTask = _aGroup[j].m_vpTask; uint32 k, nTask = rvpTask.size(); for( k = 0; k < nTask; k++ ) PushTask( rvpTask[k] ); // Signal threads for( i = 0; i < nThread; i++ ) rvpThreadPool[i]->ForceBusy(); uint32 iFinishedTask = 0; if( _bUseCallerThread ) { Task* pTask = NULL; while( (pTask = PopTask()) != NULL ) { pTask->Execute(); iFinishedTask++; } } // Wait other threads completion while( iFinishedTask != nTask ) { for( i = 0; i < nThread; i++ ) { if( rvpThreadPool[i]->PopFinishedTask() ) iFinishedTask++; } } } // [Remove proxy once finished for( i = 0; i < nThread; i++ ) rvpThreadPool[i]->SetTaskProxy( NULL ); }
void RenderingTaskWorkerRoutine::Run(const INT64 timeslice) { SystemTimer& clientTimer = GooRoomVirtualClient::Instance().GetClientTimer(); const ServerTime startTime = clientTimer.Check(); const milliseconds timeSliceMil = milliseconds(timeslice); ServerTime availableTimeSlice = timeSliceMil - (clientTimer.Check()-startTime); // CFConnectionList& cfConnectionList = GooRoomVirtualClient::Instance().GetTemporaryCFConnectionList(); // for(int i = 0; i < cfConnectionList.size(); ++i) // { // CFConnectionPointer connection = cfConnectionList[i]; // // if(connection->CanBeDeleted()) // { // GooRoomVirtualClient::Instance().RemoveTemporaryCFConnection(connection.get()); // } // } if( m_IsPaused ) { return; } Task* task = m_TaskQueue.Pop(); while( task != nullptr ) { task->Execute(); delete task; task = nullptr; availableTimeSlice = timeSliceMil - (clientTimer.Check()-startTime); if( availableTimeSlice <= milliseconds(0) ) { return; } if( m_IsPaused ) { return; } task = m_TaskQueue.Pop(); } }
void TaskQueue::run( ) { RunProlog(); Task *pTask; LOG(VB_UPNP, LOG_INFO, "TaskQueue Thread Running."); while ( !m_bTermRequested ) { // ------------------------------------------------------------------ // Process Any Tasks that may need to be executed. // ------------------------------------------------------------------ TaskTime ttNow; gettimeofday( (&ttNow), nullptr ); if ((pTask = GetNextExpiredTask( ttNow )) != nullptr) { try { pTask->Execute( this ); pTask->DecrRef(); } catch( ... ) { LOG(VB_GENERAL, LOG_ERR, "Call to Execute threw an exception."); } } // Make sure to throttle our processing. msleep( 100 ); } RunEpilog(); }
void TaskProxy::ExecuteTasks( bool _bUseCallerThread, const uint32 _cnWaitTask ) { const Array<WorkerThread*>& rvpThreadPool = WorkerThreadManager::s_GetInstance()->_GetPool(); uint32 i, nThread = rvpThreadPool.size(); uint32 iFinishedTask = 0; // Define proxy for threads for( i = 0; i < nThread; i++ ) rvpThreadPool[i]->SetTaskProxy( this ); if( _bUseCallerThread ) { Task* pTask = NULL; while( (pTask = PopTask()) != NULL ) { pTask->Execute(); iFinishedTask++; } } // Wait other threads completion while( iFinishedTask != _cnWaitTask ) { for( i = 0; i < nThread; i++ ) { if( rvpThreadPool[i]->PopFinishedTask() ) iFinishedTask++; } } // Remove proxy once finished for( i = 0; i < nThread; i++ ) rvpThreadPool[i]->SetTaskProxy( NULL ); }
// Call a task: void TaskList::CallTask(const int num) { Task* task = operator[](num); task->Execute(); }