void timed_single_thread_context::run()

in source/timed_single_thread_context.cpp [66:99]


void timed_single_thread_context::run() {
  std::unique_lock lock{mutex_};

  while (!stop_) {
    if (head_ != nullptr) {
      auto now = clock_t::now();
      auto nextDueTime = head_->dueTime_;
      if (nextDueTime <= now) {
        // Ready to run

        // Dequeue item
        auto* task = head_;
        head_ = task->next_;
        if (head_ != nullptr) {
          head_->prevNextPtr_ = &head_;
        }

        // Flag the task as dequeued.
        task->prevNextPtr_ = nullptr;
        lock.unlock();

        task->execute();

        lock.lock();
      } else {
        // Not yet ready to run. Sleep until it's ready.
        cv_.wait_until(lock, nextDueTime);
      }
    } else {
      // Queue is empty.
      cv_.wait(lock);
    }
  }
}