Beispiel #1
0
bool ThreadPool::stop() {
  
  if (Thread::CurrentID() != mDriverThread) {
    return false;
  }
  
  mTasksAccess.lock();
  
  if (mState != TPS_RUNNING) {
    // pool is not running
    mTasksAccess.unlock();
    return true;
  }
  
  mState = TPS_STOPPED;
  mTasksChanged.notifyAll();
  mTasksAccess.unlock();

  mRestartWorkersCount = numWorkers();
  
  // wait all workers to be done

  mWorkersAccess.lock();
  while (mWorkers.size() > 0) {
    mWorkersChanged.wait(mWorkersAccess);
  }
  mWorkersAccess.unlock();
  
  return true;
}
Beispiel #2
0
bool
ThreadPool::submitOne(TaskExecutor *executor) {
    if (numWorkers() == 0)
        return false;

    // Find next worker in round-robin fashion.
    size_t id = nextId_;
    nextId_ = (nextId_ + 1) % workers_.length();
    return workers_[id]->submit(executor);
}