JobProvider的tryWakeone:
主要的功能是,找到一个workthread来执行当前的任务
void JobProvider::tryWakeOne()
{
int id = m_pool->tryAcquireSleepingThread(m_ownerBitmap, ALL_POOL_THREADS);//尝试获取一个睡眠的线程,优先获取它绑定的workthread(m_ownerBitmap)
if (id < 0)
{
m_helpWanted = true;//如果没有找到,说明当前job是需要help的,即需要等待有空闲的thread;
return;
}
WorkerThread& worker = m_pool->m_workers[id];//获取找到的workthread
if (worker.m_curJobProvider != this) /* poaching */ //获取的workerthread绑定的jobprovider不是当前的jobprovider时,需要修改相应的标志位
{
sleepbitmap_t bit = (sleepbitmap_t)1 << id;
SLEEPBITMAP_AND(&worker.m_curJobProvider->m_ownerBitmap, ~bit);
worker.m_curJobProvider = this;
SLEEPBITMAP_OR(&worker.m_curJobProvider->m_ownerBitmap, bit);
}