示例#1
0
bool cbThreadPool::WaitingThread()
{
    wxMutexLocker lock(m_Mutex);
    --m_workingThreads;

    if (m_workingThreads <= 0 && m_tasksQueue.empty())
    {
        // Sends cbEVT_THREADTASK_ALLDONE message only the real task is all done
        if (m_taskAdded)
        {
            // notify the owner that all tasks are done
            CodeBlocksEvent evt = CodeBlocksEvent(cbEVT_THREADTASK_ALLDONE, m_ID);
            wxPostEvent(m_pOwner, evt);
        }

        // The last active thread is now waiting and there's a pending new number of threads to assign...
        if (m_concurrentThreadsSchedule)
        {
            _SetConcurrentThreads(m_concurrentThreadsSchedule);

            return false; // the thread must abort
        }
    }
    else
        m_semaphore->Post();

    return true;
}
示例#2
0
void cbThreadPool::SetConcurrentThreads(int concurrentThreads)
{
  // m_concurrentThreads is set here, it should always be a positive integer
  if (concurrentThreads <= 0)
  {
    concurrentThreads = wxThread::GetCPUCount(); // GetCPUCount will return -1 if it failed
    if (concurrentThreads == -1)
      m_concurrentThreads = 1;                   // as a fallback, we set the value to 1
  }

  if (concurrentThreads == m_concurrentThreads)
  {
    m_concurrentThreadsSchedule = 0;
    return;
  }

  wxMutexLocker lock(m_Mutex);
  _SetConcurrentThreads(concurrentThreads);
}
示例#3
0
void cbThreadPool::SetConcurrentThreads(int concurrentThreads)
{
    if (concurrentThreads <= 0)
    {
        concurrentThreads = wxThread::GetCPUCount();

        if (concurrentThreads == -1)
        {
            m_concurrentThreads = 1;
        }
    }

    if (concurrentThreads == m_concurrentThreads)
    {
        m_concurrentThreadsSchedule = 0;
        return;
    }

    wxMutexLocker lock(m_Mutex);
    _SetConcurrentThreads(concurrentThreads);
}