Queues & threads

ta8086 wrote on Tuesday, October 15, 2013:

I have 2 questions:

  1. Is it safe to use functions *FromISR outside of interrupt routine i.e. in normal task which can be switchedin the middle of FromISR API? I need xQueueIsQueueFullFromISR but it does not have normal API.

  2. I have this situation:

  • thread 1 which is frequently blocked with xQueueSelectFromSet;
  • thread 2 adds data in a queue with xQueueSend( …, portMAX_DELAY );
  • the queue is joined to queue set above;

Is there a chance to get dead lock if thread 1 is blocked, the corresponding queue is full and xQueueSend hang without unblocking thread 1? In other words - when the queue is full and thread blocked for some reason, will the xQueueSend unblock the thread and continue waiting for empty element in queue?

rtel wrote on Wednesday, October 16, 2013:

Whether or not you can use the “FromISR” functions outside of interrupts is somewhat dependent on the port. It is something I do myself as an optimisation sometimes, but generally I would not advise it to people who are not advanced users. If you are using a recent version of FreeRTOS on a Cortex-M device, you should be ok.

FreeRTOS V7.5.3 has a new API function uxQueueSpacesAvailable() which returns the number of spaces in the queue. That will do what you want I think.

You should not get deadlocks in your scenario - but be sure to follow the instructions on using queue sets with regards to ensuring the queue size of the queue set is at least equal to the sum of the sizes (that is, the maximum number of items that can be held within) of the queues added to the set.