Real-Time Embedded Multithreading: Using ThreadX and ARM

The counting semaphore services described in this appendix are:
| tx_semaphore_create | Create a counting semaphore |
| tx_semaphore_delete | Delete a counting semaphore |
| tx_semaphore_get | Get an instance from a counting semaphore |
| tx_semaphore_info_get | Retrieve information about a counting semaphore |
| tx_semaphore_prioritize | Prioritize a counting semaphore suspension list |
| tx_semaphore_put | Place an instance in a counting semaphore |
Create a counting semaphore
UINT <b class="bold">tx_semaphore_create</b>(TX_SEMAPHORE <b class="bold">*semaphore_ptr,</b> CHAR <b class="bold">*name_ptr,</b> ULONG <b class="bold">initial_count</b>)
This service creates a counting semaphore for inter-thread synchronization. The initial semaphore count is specified as a parameter. This service initializes the Semaphore Control Block through the parameter semaphore_ptr.
| semaphore_ptr | Pointer to a Semaphore Control Block. |
| name_ptr | Pointer to the name of the semaphore. |
| initial_count | Specifies the initial count for this semaphore. Legal values are from 0x00000000 to 0xFFFFFFFF (inclusive). |
| TX_SUCCESS 1 | (0x00) | Successful semaphore creation |
| TX_SEMAPHORE_ERROR | (0x0C) | Invalid semaphore pointer. Either the pointer is NULL or the semaphore has already been created. |
| TX_CALLER_ERROR | (0x13) | Invalid caller of this service. |
[98]
Initialization and threads
No
TX_SEMAPHORE my_semaphore;UINT status;/* Create a counting semaphore with an initial value of 1. This is typically the technique used to create a binary semaphore. Binary semaphores are used to provide protection over a common resource. */status = <b class="bold">tx_semaphore_create</b>(&my_semaphore,"my_semaphore_name", 1);/* If status equals TX_SUCCESS, my_semaphore is ready for use.