EasyManua.ls Logo

Texas Instruments TMS320

Texas Instruments TMS320
288 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Queues
5-18
Example 5.18. Using QUE to Send Messages (continued)
/* ======== main ======== */
Void main()
{
/*
* Writer must be called before reader to ensure that the
* queue is non-empty for the reader.
*/
writer();
reader();
}
/* ======== reader ======== */
Void reader()
{
Msg msg;
Int i;
for (i=0; i < NUMMSGS; i++) {
/* The queue should never be empty */
if (QUE_empty(&queue)) {
SYS_abort("queue error\n");
}
/* dequeue message */
msg = QUE_get(&queue);
/* print value */
LOG_printf(&trace, "read '%c'.", msg->val);
/* free msg */
MEM_free(0, msg, sizeof(MsgObj));
}
}
/* ======== writer ======== */
Void writer()
{
Msg msg;
Int i;
for (i=0; i < NUMMSGS; i++) {
/* allocate msg */
msg = MEM_alloc(0, sizeof(MsgObj), 0);
if (msg == MEM_ILLEGAL) {
SYS_abort("Memory allocation failed!\n");
}
/* fill in value */
msg->val = i + 'a';
LOG_printf(&trace, "writing '%c' ...", msg->val);
/* enqueue message */
QUE_put(&queue, msg);
}
}

Table of Contents

Other manuals for Texas Instruments TMS320

Related product manuals