Danh mục

Real-Time Embedded Multithreading Using ThreadX and MIPS- P10

Số trang: 20      Loại file: pdf      Dung lượng: 137.07 KB      Lượt xem: 7      Lượt tải: 0    
10.10.2023

Xem trước 2 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

Real-Time Embedded Multithreading Using ThreadX and MIPS- P10:Although the history of embedded systems is relatively short, 1 the advances andsuccesses of this fi eld have been profound. Embedded systems are found in a vast array ofapplications such as consumer electronics, “ smart ” devices, communication equipment,automobiles, desktop computers, and medical equipment.
Nội dung trích xuất từ tài liệu:
Real-Time Embedded Multithreading Using ThreadX and MIPS- P10 182 Chapter 11 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 = tx_semaphore_create(&my_semaphore, my_semaphore_name, 1); /* If status equals TX_SUCCESS, my_semaphore is ready for use. */ Figure 11.4: Creating a counting semaphore TX_SEMAPHORE my_semaphore; UINT status; … /* Delete counting semaphore. Assume that the counting semaphore has already been created. */ status = tx_semaphore_delete(&my_semaphore); /* If status equals TX_SUCCESS, the counting semaphore has been deleted. */ Figure 11.5: Deleting a counting semaphore receive a TX_DELETED return status. Make certain that you don’t try to use a deleted semaphore. Figure 11.5 shows how a counting semaphore can be deleted. If variable status contains the return value TX_SUCCESS, we have successfully deleted the counting semaphore. 11.8 Getting an Instance of a Counting Semaphore The tx_semaphore_get service retrieves an instance (a single count) from the specified counting semaphore. If this call succeeds, the semaphore count decreases by one. Figure 11.6 shows how to get an instance of a counting semaphore, where we use the wait option value TX_WAIT_FOREVER. If variable status contains the return value TX_SUCCESS, we have successfully obtained an instance of the counting semaphore called my_semaphore. w ww. n e w n e s p r e s s .c o mPlease purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Event Notification and Synchronization with Counting Semaphores 183 TX_SEMAPHORE my_semaphore; UINT status; … /* Get a semaphore instance from the semaphore my_semaphore. If the semaphore count is zero, suspend until an instance becomes available. Note that this suspension is only possible from application threads. */ status = tx_semaphore_get(&my_semaphore, TX_WAIT_FOREVER); /* If status equals TX_SUCCESS, the thread has obtained an instance of the semaphore. */ Figure 11.6: Get an instance from a counting semaphore 11.9 Retrieving Information about Counting Semaphores There are three services that enable you to retrieve vital information about semaphores. The first such service for semaphores—the tx_semaphore_info_get service—retrieves a subset of information from the Semaphore Control Block. This information provides a “snapshot” at a particular instant in time, i.e., when the service is invoked. The other two services provide summary information that is based on the gathering of run-time performance data. One service—the tx_semaphore_performance_info_get service—provides an information summary for a particular semaphore up to the time the service is invoked. By contrast the tx_semaphore_performance_system_info_get retrieves an information summary for all semaphores in the system up to the time the service is invoked. These services are useful in analyzing the behavior of the system and determining whether there are potential problem areas. The tx_semaphore_info_get3 service retrieves several useful pieces of information about a counting semaphore. The information that is retrieved includes the counting semaphore name, its current count, the number of threads suspended for this semaphore, and a pointer to the next created counting semaphore. Figure 11.7 shows how this service can be used to obtain information about a counting semaphore. 3 By default, only the tx_semaphore_info_get service is enabled. The other two information gathering services must be enabled in order to use them. w w w.ne w nespress.comPlease purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 184 Chapter 11 TX_SEMAPHORE my_semaphore; CHAR *name; ULONG current_value; TX_THREAD *first_suspended; ULONG suspended_count; TX_SEMAPHORE *next_ ...

Tài liệu được xem nhiều: