Skip to content

File instr_queue.h

File List > projects > simtix > src > simtix > sm > instr_queue.h

Go to the documentation of this file

#pragma once

#include "sim/queue.h"
#include "sm/instr_ptr.h"

namespace simtix {

class InstrQueue : public sim::SizedQueue<InstrPtr> {
 public:
  using sized_queue_ = sim::SizedQueue<InstrPtr>;

  explicit InstrQueue(std::size_t capacity, const char *following_stage = "X")
      : sized_queue_(capacity), following_stage_(following_stage) {}

  ~InstrQueue() { Flush(); }

  std::optional<InstrPtr> Deq() override {
    auto instr = sized_queue_::Deq();
    if (instr) {
      KONATA(S, (*instr).unique_id(), 0, following_stage_);
    }
    return instr;
  }

  void Flush() {
    for (auto it = sized_queue_::begin(); it != sized_queue_::end(); ++it) {
      it->set_flushed();
    }
    sized_queue_::clear();
  }

 private:
  const char *following_stage_;
};

}  // namespace simtix