I do agree you can think of wait(expression)
as always checking the condition expression continuously. That's thought for the designer, but a computer program can not be designed at that way or it wastes CPU time in the condition checking loop.
In SystemVerilog
, its compiler might model the boolean expression as an event.
When the execution runs to wait()
and condition is false, the simulation kernel suspend the current thread and execute others. In the simulation, every time queuecount
or queuemax
has been changed, the condition is re-computed using <
operator. Once the condition is satisfied, the event is triggered and then the waiting thread is re-schedule and prepared to resume its execution.
In SystemC
, because it's C/C++
world plus an event driven hardware modeling library, that's the natural of C/C++
you write a function like function(<condition expression>)
. However, after C/C++
compilation like GCC
, actually the program will first evaluate the <condition expression>
then pass as the argument to the function. It is the software way. Such that, in wait()
function, it can only see true
or false
or 0/1, it does know about what you are waiting for. It does not make any sense for the real intent of wait()
in hardware modeling. Therefore, the wait()
can only accepts event
argument in SystemC. For example,
wait (event); // waiting for the event
wait (a_signal); // signal interface has value_changed_event, posedge_event, negedge_event
wait (10, SC_NS); // simulation time is also an event in SC kernel
If you would like to model the same condition for wait()
like SystemVerilog, you have to manually write the detail of events. Following is a proof of concept pseudo code, you can find examples from SystemC or sc_fifo class.
sc_event waiting_event;
void put( ... ) {
while (!(queuecount < queuemax))
wait( waiting_event);
push_back(...);
}
void get( ... ) {
...
notify_queue_available();
}
void notify_queue_available() {
if (queuecount < queuemax)
waiting_event.notify();
}