Coma FW-C2800 User's Guide Page 160

  • Download
  • Add to my manuals
  • Print
  • Page
    / 276
  • Table of contents
  • BOOKMARKS
  • Rated. / 5. Based on customer reviews
Page view 159
Semaphores
Thread Scheduling 4-55
4.6 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-9. You can also use
the Configuration Tool to create semaphore objects. See section 2.2.8,
Creating, Referencing, and Deleting Dynamically-Created DSP/BIOS
Objects, page 2-10, for a discussion of the benefits of creating objects with
the Configuration Tool.
Example 4-9. 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-10, 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;
Page view 159
1 2 ... 155 156 157 158 159 160 161 162 163 164 165 ... 275 276

Comments to this Manuals

No comments