Semaphores
4-60
Example 4-9.
Setting a Timeout with SEM_pend
Example 4-10 provides an example of SEM_post, which is used to signal a
semaphore. If a task is waiting for the semaphore, SEM_post removes the
task from the semaphore queue and puts it on the ready queue. If no tasks
are waiting, SEM_post simply increments the semaphore count and returns.
Example 4-10.
Signaling a Semaphore with SEM_post
4.7.1
SEM Example
Example 4-11 provides sample code for three writer tasks which create
unique messages and place them on a queue for one reader task. The writer
tasks call SEM_post to indicate that another message has been enqueued.
The reader task calls SEM_pend to wait for messages. SEM_pend returns
only when a message is available on the queue. The reader task prints the
message using the LOG_printf function.
The three writer tasks, reader task, semaphore, and queues in this example
program were created statically.
Since this program employs multiple tasks, a counting semaphore is used to
synchronize access to the queue. Figure 4-14 provides a view of the results
from Example 4-10. Though the three writer tasks are scheduled first, the
messages are read as soon as they have been enqueued because the
reader’s task priority is higher than that of the writer.
Bool SEM_pend(sem, timeout);
SEM_Handle sem;
Uns timeout; /* return after this many system clock ticks*/
Void SEM_post(sem);
SEM_Handle sem;
Содержание 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 ...