Real-Time Embedded Multithreading: Using ThreadX and ARM

Appendix G: Counting Semaphore Services

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

tx_semaphore_create

Create a counting semaphore

Prototype

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>)

Description

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.

Input Parameters

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).

Return Values

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]

Allowed From

Initialization and threads

Preemption Possible

No

Example

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.

UNLIMITED FREE
ACCESS
TO THE WORLD'S BEST IDEAS

SUBMIT
Already a GlobalSpec user? Log in.

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.

Customize Your GlobalSpec Experience

Category: Hemocytometers
Finish!
Privacy Policy

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.