This page demonstrates the usage of
queues in
C++ and discusses some motivation to implement
it.
-
In this site I usually talk about verification
and design issues. For the former usually
specman is the language while for the latter
VHDL, verilog or systemc are the ones.
-
Recently I started to work with a customer, that
uses C++ for controlling the test bench. In one
of them, I came across queues, which immediately
reminded me of lists and scoreboards and its wide
usage, as an important building block of any
verification environment.
-
There are plenty of good examples on the web. The
examples, that I saw, were simple using unsigned integers or
characters. I decided to make a small exercise,
using the transaction class from: producer
consumer systemc example:
systemc c_trans
-
The example creates a queue of c_trans
transactions. The queue push command is
used for data input and empty, front and pop
are used for data output.
#include <iostream>
#include <queue>
using namespace std;
...
class c_trans {
public:
unsigned seq_n;
unsigned data[BSZ];
c_trans();
c_trans(unsigned da_i[], unsigned s);
};
...
queue<c_trans> myqueue;
unsigned da[BSZ]={1,2,3,4,5,6,7,8};
const c_trans arr[2] = {c_trans(), c_trans(da, 1)};
myqueue.push (arr[0]);
myqueue.push (arr[1]);
...
while (!myqueue.empty())
{
c_trans c = myqueue.front();
cout << c.seq_n << " " << c.data[0] << ".. " << c.data[7] << " " << endl;
myqueue.pop();
}
...
-
I intend to use queues in my systemc test-
benches, so I compiled it in the same way as
the above mentioned systemc example.
The full code as well as the makefile can be
downloaded from:
queues code .
-
In the next
page .
I show how to debug this simple program with gdb.
As this is a simple program, it is a very good
case study to see the input elements added to
queue and extract using gdb commands.
Contact me now at: |