//--------------------------------------------------------------------------- // @function: // CScheduler::PjRetrieve // // @doc: // Retrieve next runnable job from queue // //--------------------------------------------------------------------------- CJob * CScheduler::PjRetrieve() { #ifdef GPOS_DEBUG // restrict parallelism to keep track of jobs CAutoMutex am(m_mutex); if (FTrackingJobs()) { am.Lock(); } #endif // GPOS_DEBUG // retrieve runnable job from lists of waiting jobs SJobLink *pjl = m_listjlWaiting.Pop(); CJob *pj = NULL; if (NULL != pjl) { pj = pjl->m_pj; GPOS_ASSERT(NULL != pj); GPOS_ASSERT(0 == pj->UlpRefs()); // decrement number of queued jobs (void) UlpExchangeAdd(&m_ulpQueued, -1); // update statistics (void) UlpExchangeAdd(&m_ulpStatsDequeued, 1); // recycle job link m_spjl.Recycle(pjl); #ifdef GPOS_DEBUG // add job to running list if (FTrackingJobs()) { GPOS_ASSERT(CJob::EjsWaiting == pj->Ejs()); pj->SetState(CJob::EjsRunning); m_listjRunning.Append(pj); } #endif // GPOS_DEBUG } return pj; }