|
Real-Time Concepts for Embedded SystemsThe I/O task first inserts the data associated with an I/O device into the message queue. Then the I/O task signals this event to the task by setting the event's assigned bit in the event register. The timer ISR sets the event bit; this event is no more than a tick announcement to the task. After the task resumes execution, it performs the appropriate action according to the event-register state. Because the event register is only used as a signaling mechanism, a counting semaphore is used to keep track of the total number of tick occurrences. Listing 15.4 puts this discussion into perspective. The addition of the counting semaphore does not increase the code complexity. Listing 15.4: Pseudo code for using a counting semaphore for event accumulation combined with an event-register used for event notification. while (the_events = wait for events from Event-Register) Pif (the_events& EVENT_TYPE_DEVICE) P while (Get message from msgQueue) PP process the message P endwhile Pendif Pif (the_events& EVENT_TYPE_TIMER) P counter = 0 P disable(interrupts) P while (Get(Counting_Semaphore)) PP counter = counter + 1 P endwhile P enable(interrupts) P if (counter 1) PP recovery time P else PP process the timer tick P endif Pendif endwhile 15.7.4 Using Condition Variables to Synchronize between Readers and Writers The design pattern shown in Figure 15.20 demonstrates the use of condition variables ...» | Код для вставки книги в блог HTML
phpBB
текст
|
|