We have a application that the mailbox messages need to be process in a timely manner. But we found that the message processing could be hold off by lower priority task due to sysbios Mailbox implementation -- putting the message into the queue and posting the notification semaphore to the receiver is not atomic.
Scenario:
Task 1 -- low priority, message writer; Task 2 -- medium priority; Task 3 -- high priority, message writer; Task 4 -- highest priority, message receiver
Using certified mail (mailbox size > 1)
Mailbox message 1 contains -- Msg1, notification semaphore 1(Sem1), response semaphore(RspSem1)
Mailbox message 2 contains -- Msg2, notification semaphore 2(Sem2), response semaphore(RspSem2)
1. Task 4 pends on mailbox messages.
2. Task 1 sends message1. After mailbox put message1 into queue but before it can post out the notification semaphore, it's preempted by Task 2.
3. Task 3 preempts Task 2, sends message to Task 4,
4. Task 4 is unblocked by notification semaphore sent from Task 3. Then it get the message from the queue, which is from Task 1, and process it,
5 Task 4 pends on mailbox message notification.
6. Task 3 yield.
7. Task 2 resumes and continues to run.
Now the message sent from Task 3 can not be processed by Task 4 because the notification is blocking by Task 2.
Question1:
How do we resolve the issue?
Question 2:
Why the mailbox action from putting the message to the queue to posting notification semaphore is not atomic?
GanZ