Example - cont...
nclass
fifo : public sc_channel,
npublic
write_if,
npublic
read_if
n{
npublic:
nSC_CTOR(fifo)
{ // channel constructor
nnum_elements
= first = 0;
n}
nvoid
write(char c) {
nif
(num_elements == max)
nwait(read_event);
ndata[(first
+ num_elements) % max ] = c;
n++
num_elements;
nwrite_event.notify();
n}
nvoid
read(char& c) {
nif
(num_elements == 0)
nwait(write_event);
nc =
data[first];
n--
num_elements;
nfirst
= (first + 1) % max;
nread_event.notify();
n}
nvoid
reset() { num_elements = first = 0; }
nint
num_available() {return num_elements;}
nprivate:
nenum
e { max = 10 };
n//max
is just a constant in class scope
nchar
data[max];
nint
num_elements, first;
nsc_event
write_event, read_event;
n};