This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Peak next Mailbox message

Hello,

Is there a way to peak, not pull the next mailbox message?

I could not find any function that will do so and I'm currently pulling the next message and depending if there is space on a different buffer saving the message for later or using the recently pulled msg.

Cheers

  • Hi Hoffiz,

    You're correct, there's not currently an API to peek at the next message in the Mailbox queue. However, would it be possible to pend on a semaphore with the condition that your buffer has sufficient space in it? Then, when that semaphore returns you know you can perform a Mailbox_pend. Let me know if I'm understanding your use case correctly.

    Best,
    Alexander
  • Hi Hoffiz,

    Instead of using the mailbox, you could use a queue, which seems to be a simple buffer with added functionality.
    The greatest benefit would be that you can access any message in the queue without removing it.

    There are several drawbacks though.
    The queue does not copy your data like the Mailbox does. Therefore, you need to manage the data so it's preserved until you don't need it anymore.
    There is no Queue_pend function so you would have to use Event_pend and post for synchronization.

    Look it up and see whether it's worth the extra work to gain what you need.
  • That is what I'm doing right now but to be honest the mailbox might be an overkill for what I'm doing. I'm using a semaphore and a temporary buffer to hold the message, check if there is space and control when I pend the mailbox. I might be able to use a queue like Michael suggested. For now the code works by I fear there is a more elegant way of implementing pulling from the mailbox into a buffer.