Exemplo n.º 1
0
  void ThreadPoolPrivate::workLoop()
  {
    qi::os::setCurrentThreadName("tp-idle");
    while (true)
    {
      boost::function<void(void)> task;

      { /* -- Locked Section -- */
        boost::mutex::scoped_lock lock(_tasksMutex);

        if (_tasks.empty())
        {
          /* Should the thread be destroyed ? */
          if ((((*_workers - *_activeWorkers) > _maxIdleWorkers) && *_workers > _minWorkers)
               || (*_workers > _maxWorkers))
          {
            break;
          }

          /* Notify user that all tasks are done */
          if (*_activeWorkers == 0)
            _userCondition.notify_all();

          /* Wait for a task to be scheduled */
          _tasksCondition.wait(lock);
        }
        else /* Retrieve the task */
        {
          task = _tasks.front();
          _tasks.pop();
        }
      } /* -- End Locked Section -- */

      if (task)
      {
        qi::os::setCurrentThreadName("tp-worker");
        ++_activeWorkers;
        task();
        --_activeWorkers;
        qi::os::setCurrentThreadName("tp-idle");
      }
    }

    /* Thread destruction */
    --_workers;
    {
      boost::mutex::scoped_lock lock(_terminatedThreadsMutex);

      _terminatedThreads.push(boost::this_thread::get_id());
    }
    notifyManager();
  }
Exemplo n.º 2
0
  bool ThreadPoolPrivate::schedule(const boost::function<void(void)>& f)
  {
    {
      boost::mutex::scoped_lock lock(_tasksMutex);

      _tasks.push(f);
    }
    _tasksCondition.notify_one();

    /* Do we need more threads ? */
    notifyManager();

    return true;
  }
Exemplo n.º 3
0
void ProgramManager::startProgramChange(bool isr){
  if(isr)
    notifyManagerFromISR(STOP_PROGRAM_NOTIFICATION|PROGRAM_CHANGE_NOTIFICATION);
  else
    notifyManager(STOP_PROGRAM_NOTIFICATION|PROGRAM_CHANGE_NOTIFICATION);
}
Exemplo n.º 4
0
/* exit and restart program */
void ProgramManager::resetProgram(bool isr){
  if(isr)
    notifyManagerFromISR(STOP_PROGRAM_NOTIFICATION|START_PROGRAM_NOTIFICATION);
  else
    notifyManager(STOP_PROGRAM_NOTIFICATION|START_PROGRAM_NOTIFICATION);
}