gem5  v22.1.0.0
Classes | Public Member Functions | Protected Types | Protected Attributes | List of all members
gem5::CircularQueue< T > Class Template Reference

Circular queue. More...

#include <circular_queue.hh>

Classes

struct  iterator
 Iterator to the circular queue. More...
 

Public Member Functions

template<typename Idx >
std::enable_if_t< std::is_integral_v< Idx >, referenceoperator[] (const Idx &index)
 
template<typename Idx >
std::enable_if_t< std::is_integral_v< Idx >, const_referenceoperator[] (const Idx &index) const
 
 CircularQueue (size_t size=0)
 
void flush ()
 Remove all the elements in the queue. More...
 
bool isValidIdx (size_t idx) const
 Test if the index is in the range of valid elements. More...
 
reference front ()
 
reference back ()
 
size_t head () const
 
size_t tail () const
 
size_t capacity () const
 
size_t size () const
 
void pop_front (size_t num_elem=1)
 Circularly increase the head pointer. More...
 
void pop_back ()
 Circularly decrease the tail pointer. More...
 
void push_back (typename std::vector< T >::value_type val)
 Pushes an element at the end of the queue. More...
 
void advance_tail ()
 Increases the tail by one. More...
 
void advance_tail (size_t len)
 Increases the tail by a specified number of steps. More...
 
bool empty () const
 Is the queue empty? More...
 
bool full () const
 Is the queue full? A queue is full if the head is the 0^{th} element and the tail is the (size-1)^{th} element, or if the head is the n^{th} element and the tail the (n-1)^{th} element. More...
 
iterator begin ()
 Iterators. More...
 
iterator begin () const
 
iterator end ()
 
iterator end () const
 
iterator getIterator (size_t idx)
 Return an iterator to an index in the queue. More...
 

Protected Types

using reference = typename std::vector< T >::reference
 
using const_reference = typename std::vector< T >::const_reference
 

Protected Attributes

std::vector< T > data
 
const size_t _capacity
 
size_t _size = 0
 
size_t _head = 1
 

Detailed Description

template<typename T>
class gem5::CircularQueue< T >

Circular queue.

Circular queue implemented in a standard vector. All indices are monotonically increasing, and modulo is used at access time to alias them down to the actual storage.

The queue keeps track of two pieces of state, a head index, which is the index of the next element to come out of the queue, and a size which is how many valid elements are currently in the queue. Size can increase to, but never exceed, the capacity of the queue.

In theory the index may overflow at some point, but since it's a 64 bit value that would take a very long time.

Template Parameters
TType of the elements in the queue

Definition at line 69 of file circular_queue.hh.

Member Typedef Documentation

◆ const_reference

template<typename T >
using gem5::CircularQueue< T >::const_reference = typename std::vector<T>::const_reference
protected

Definition at line 75 of file circular_queue.hh.

◆ reference

template<typename T >
using gem5::CircularQueue< T >::reference = typename std::vector<T>::reference
protected

Definition at line 74 of file circular_queue.hh.

Member Function Documentation

◆ getIterator()

template<typename T >
iterator gem5::CircularQueue< T >::getIterator ( size_t  idx)
inline

Return an iterator to an index in the queue.

Definition at line 592 of file circular_queue.hh.

Referenced by gem5::o3::LSQUnit::insertLoad(), gem5::o3::LSQUnit::insertStore(), and gem5::prefetch::PIF::notifyRetiredInst().

◆ isValidIdx()

template<typename T >
bool gem5::CircularQueue< T >::isValidIdx ( size_t  idx) const
inline

Test if the index is in the range of valid elements.

Definition at line 433 of file circular_queue.hh.

References gem5::CircularQueue< T >::_head, and gem5::CircularQueue< T >::_size.

Referenced by gem5::CircularQueue< T >::iterator::dereferenceable().

◆ operator[]()

template<typename T >
template<typename Idx >
std::enable_if_t<std::is_integral_v<Idx>, const_reference> gem5::CircularQueue< T >::operator[] ( const Idx &  index) const
inline

Member Data Documentation

◆ _capacity

template<typename T >
const size_t gem5::CircularQueue< T >::_capacity
protected

◆ _head

template<typename T >
size_t gem5::CircularQueue< T >::_head = 1
protected

◆ _size

template<typename T >
size_t gem5::CircularQueue< T >::_size = 0
protected

◆ data

template<typename T >
std::vector<T> gem5::CircularQueue< T >::data
protected

Definition at line 72 of file circular_queue.hh.

Referenced by gem5::CircularQueue< T >::operator[]().


The documentation for this class was generated from the following file:

Generated on Wed Dec 21 2022 10:23:11 for gem5 by doxygen 1.9.1