Danh mục tài liệu

Real-Time Embedded Multithreading Using ThreadX and MIPS- P13

Số trang: 20      Loại file: pdf      Dung lượng: 164.74 KB      Lượt xem: 21      Lượt tải: 0    
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- P13: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- P13 244 Chapter 13 TX_QUEUE my_queue; CHAR *name; ULONG enqueued; TX_THREAD *first_suspended; ULONG suspended_count; ULONG available_storage; TX_QUEUE *next_queue; UINT status; … /* Retrieve information about the previously created message queue my_queue. */ status = tx_queue_info_get(&my_queue, &name, &enqueued, &available_storage, &first_suspended, &suspended_count, &next_queue); /* If status equals TX_SUCCESS, the information requested is valid. */ Figure 13.11: Retrieving information about a message queue Status of Queue Effect of Prioritization The highest priority thread suspended for this queue will Queue is empty receive the next message placed on the queue The highest priority thread suspended for this queue will Queue is full send the next message to this queue when space becomes available Figure 13.12: Effect of prioritizing a message queue suspension list If return variable status contains the value TX_SUCCESS, we have retrieved valid information about the message queue. 13.11 Prioritizing a Message Queue Suspension List The tx_queue_prioritize service places the highest priority thread suspended for a message queue at the front of the suspension list. This applies either to a thread waiting to receive a message from an empty queue, or to a thread waiting to send a message to a full queue, as described in Figure 13.12. All other threads remain in the same FIFO order in which they were suspended. 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. Thread Communication with Message Queues 245 TX_QUEUE my_queue; UINT status; /* Depending on the queue status, this service ensures that the highest priority thread will either receive the next message placed on this queue, or will send the next message to the queue. */ status = tx_queue_prioritize(&my_queue); /* If status equals TX_SUCCESS, the highest priority suspended thread is at the front of the list. If the suspended thread is waiting to receive a message, the next tx_queue_send or tx_queue_front_send call made to this queue will wake up this thread. If the suspended thread is waiting to send a message, the next tx_queue_receive call will wake up this thread. */ Figure 13.13: Prioritizing a message queue suspension list Figure 13.13 contains an example showing how this service can be used to prioritize a message queue suspension list. If return variable status contains the value TX_SUCCESS, we have successfully prioritized the message queue suspension list. 13.12 Message Queue Notification and Event-Chaining The tx_queue_send_notify service registers a notification callback function that is invoked whenever a message is sent to the specified queue. The processing of the notification callback is defined by the application. This is an example of event-chaining where notification services are used to chain various synchronization events together. This is typically useful when a single thread must process multiple synchronization events. 13.13 Sample System Using a Message Queue for Interthread Communication We have used counting semaphores for mutual exclusion and for event notification in the two previous sample systems. We have also used an event flags group to synchronize the behavior of two threads. In this sample system, we will use a message queue to w w w.ne w nespress.comPlease purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 246 Chapter 13 Activity 2 Activity 4 Activity 1 Send counting Activity 3 Send counting Sleep 2 ticks message to the queue Sleep 4 ticks message to the queue and sleep 5 ticks and sleep 3 ticks Figure 13.14: Activities of the Speedy_Thread ...