コード例 #1
0
ファイル: Scheduler.cpp プロジェクト: dreamfrog/ArangoDB
void Scheduler::destroyTask (Task* task) {
  SchedulerThread* thread = 0;

  {
    MUTEX_LOCKER(schedulerLock);

    map<Task*, SchedulerThread*>::iterator i = task2thread.find(task);

    if (i == task2thread.end()) {
      LOGGER_WARNING("destroyTask called for an unknown task " << task << " (" << task->getName() << ")");

      return;
    }
    else {
      LOGGER_TRACE("destroyTask for task " << task << " (" << task->getName() << ")");

      thread = i->second;

      if (taskRegistered.count(task) > 0) {
        taskRegistered.erase(task);
        --current[task->getName()];
      }

      task2thread.erase(i);
    }
  }

  thread->destroyTask(task);
}
コード例 #2
0
ファイル: Scheduler.cpp プロジェクト: JiangKevin/arangodb
int Scheduler::destroyTask(Task* task) {
  if (stopping) {
    return TRI_ERROR_SHUTTING_DOWN;
  }
  SchedulerThread* thread = nullptr;
  std::string const taskName(task->name());

  {
    MUTEX_LOCKER(mutexLocker, schedulerLock);

    auto it = task2thread.find(task);

    if (it == task2thread.end()) {
      LOG(WARN) << "destroyTask called for an unknown task " << (void*)task << " (" << taskName << ")";

      return TRI_ERROR_TASK_NOT_FOUND;
    }

    LOG(TRACE) << "destroyTask for task " << (void*)task << " (" << taskName << ")";

    thread = (*it).second;

    taskRegistered.erase(task->taskId());
    task2thread.erase(it);
  }

  thread->destroyTask(task);

  return TRI_ERROR_NO_ERROR;
}
コード例 #3
0
ファイル: Scheduler.cpp プロジェクト: frankmayer/ArangoDB
void Scheduler::unregisterTask (Task* task) {
  SchedulerThread* thread = 0;

  {
    MUTEX_LOCKER(schedulerLock);

    map<Task*, SchedulerThread*>::iterator i = task2thread.find(task);

    if (i == task2thread.end()) {
      LOG_WARNING("unregisterTask called for an unknown task %p (%s)", (void*) task, task->getName().c_str());

      return;
    }
    else {
      LOG_TRACE("unregisterTask for task %p (%s)", (void*) task, task->getName().c_str());

      thread = i->second;

      if (taskRegistered.count(task) > 0) {
        taskRegistered.erase(task);
        --current[task->getName()];
      }

      task2thread.erase(i);
    }
  }

  thread->unregisterTask(task);
}
コード例 #4
0
void LsiRewriteDriverFactory::StartThreads()
{
    if (m_bThreadsStarted)
        return;

    SchedulerThread *thread = new SchedulerThread(thread_system(),
            scheduler());
    bool ok = thread->Start();
    CHECK(ok) << "Unable to start scheduler thread";
    defer_cleanup(thread->MakeDeleter());
    m_bThreadsStarted = true;
}
コード例 #5
0
ファイル: Scheduler.cpp プロジェクト: dreamfrog/ArangoDB
void Scheduler::registerTask (Task* task) {
  SchedulerThread* thread = 0;

  {
    MUTEX_LOCKER(schedulerLock);

    LOGGER_TRACE("registerTask for task " << task << " (" << task->getName() << ")");

    size_t n = 0;

    if (multiThreading && ! task->needsMainEventLoop()) {
      n = (++nextLoop) % nrThreads;
    }

    thread = threads[n];

    task2thread[task] = thread;
    taskRegistered.insert(task);
    ++current[task->getName()];
  }

  thread->registerTask(this, task);
}
コード例 #6
0
ファイル: Scheduler.cpp プロジェクト: JiangKevin/arangodb
int Scheduler::registerTask(Task* task, ssize_t* got, ssize_t want) {
  if (stopping) {
    return TRI_ERROR_SHUTTING_DOWN;
  }
  TRI_ASSERT(task != nullptr);

  if (task->isUserDefined() && task->id().empty()) {
    // user-defined task without id is invalid
    deleteTask(task);
    return TRI_ERROR_TASK_INVALID_ID;
  }

  std::string const& name = task->name();
  LOG(TRACE) << "registerTask for task " << (void*)task << " (" << name << ")";

  // determine thread
  SchedulerThread* thread = nullptr;
  size_t n = 0;
  if (0 <= want) {
    n = want;

    if (nrThreads <= n) {
      deleteTask(task);
      return TRI_ERROR_INTERNAL;
    }
  }

  try {
    MUTEX_LOCKER(mutexLocker, schedulerLock);

    int res = checkInsertTask(task);

    if (res != TRI_ERROR_NO_ERROR) {
      deleteTask(task);
      return res;
    }

    if (0 > want) {
      if (multiThreading && !task->needsMainEventLoop()) {
        n = (++nextLoop) % nrThreads;
      }
    }

    thread = threads[n];

    task2thread[task] = thread;
    taskRegistered[task->taskId()] = task;
  } catch (...) {
    destroyTask(task);
    throw;
  }

  if (nullptr != got) {
    *got = static_cast<ssize_t>(n);
  }

  if (!thread->registerTask(this, task)) {
    // no need to delete the task here, as SchedulerThread::registerTask
    // takes over the ownership
    return TRI_ERROR_INTERNAL;
  }

  return TRI_ERROR_NO_ERROR;
}