It's really need cRxLock and cTxLock in Queue struct?

ctc8631 wrote on Monday, June 05, 2017:

Hello, I’m keep learning FreeRTOS source code,
But in queue.c, I’m not really understand why need cRxLock and cTxLock,
I know that in send or receive function it can lock rx and tx when it check the timeout,
and in this situation the ISR event will record in cRxLock and cTxLock,
after checking timeout, it will check Lock value and release lock.

But I think the check timeout is not really long, why just put check into critical section,
then there is no need to use cRxLock and cTxLock and save release lock which is not short execute

I think maybe there is a key to design Lock, can anyone give me some hint, thanks

rtel wrote on Monday, June 05, 2017:

As I recall the rx and tx locks are used to allow queues to be used from
tasks and interrupts at the same time. If a queue is locked then an
interrupt using the queue knows it can modify some data structures but
not others - the structures it can’t modify are then modified from the
task level when the queue is unlocked. So:

  1. A task locks a queue and starts accessing it.
  2. An interrupt uses the queue, but noticing it is locked, does not
    complete the queue operation.
  3. When the task unlocks the queue it notices an interrupt also accessed
    the queue and completes the operation the interrupts started.