Semaphores
Thread Scheduling
4-59
4.7 Semaphores
DSP/BIOS provides a fundamental set of functions for intertask
synchronization and communication based upon
semaphores
. Semaphores
are often used to coordinate access to a shared resource among a set of
competing tasks. The SEM module provides functions that manipulate
semaphore objects accessed through handles of type SEM_Handle.
SEM objects are counting semaphores that can be used for both task
synchronization and mutual exclusion. Counting semaphores keep an
internal count of the number of corresponding resources available. When
count is greater than 0, tasks do not block when acquiring a semaphore.
The functions SEM_create and SEM_delete are used to create and delete
semaphore objects, respectively, as shown in Example 4-8. You can also
create semaphore objects statically. See Section 2.4,
, page 2-16, for a discussion of the benefits of creating
objects statically.
Example 4-8.
Creating and Deleting a Semaphore
The semaphore count is initialized to count when it is created. In general,
count is set to the number of resources that the semaphore is synchronizing.
SEM_pend waits for a semaphore. If the semaphore count is greater than 0,
SEM_pend simply decrements the count and returns. Otherwise, SEM_pend
waits for the semaphore to be posted by SEM_post.
Note:
When called within an HWI, the code sequence calling SEM_post or
SEM_ipost must be either wrapped within an HWI_enter/HWI_exit pair or
invoked by the HWI dispatcher.
The timeout parameter to SEM_pend, as shown in Example 4-9, allows the
task to wait until a timeout, to wait indefinitely (SYS_FOREVER), or to not
wait at all (0). SEM_pend’s return value is used to indicate if the semaphore
was acquired successfully.
SEM_Handle SEM_create(count, attrs);
Uns count;
SEM_Attrs *attrs;
Void SEM_delete(sem);
SEM_Handle sem;
Summary of Contents for TMS320 Series
Page 1: ...TMS320 DSP BIOS v5 40 User s Guide Literature Number SPRU423G April 2009 ...
Page 16: ...xvi ...
Page 152: ...Tasks 4 48 Figure 4 12 Trace from Example 4 7 ...
Page 168: ...Semaphores 4 64 Figure 4 14 Trace Results from Example 4 11 ...
Page 202: ...5 20 ...
Page 287: ...Index 9 Index Void 1 11 W words data memory 3 15 of code 1 5 wrapper function 2 29 ...
Page 288: ...Index 10 Index ...