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);
}
}
Содержание TMS320 Series
Страница 1: ...TMS320 DSP BIOS v5 40 User s Guide Literature Number SPRU423G April 2009 ...
Страница 16: ...xvi ...
Страница 152: ...Tasks 4 48 Figure 4 12 Trace from Example 4 7 ...
Страница 168: ...Semaphores 4 64 Figure 4 14 Trace Results from Example 4 11 ...
Страница 202: ...5 20 ...
Страница 287: ...Index 9 Index Void 1 11 W words data memory 3 15 of code 1 5 wrapper function 2 29 ...
Страница 288: ...Index 10 Index ...