I have an application where I need to write large being transferred between two tasks: a producer and a consumer. To make it more efficient, I want to abide by the design given in the FreeRTOS Practical Guide and use pointers to the data to populate the queue. The solution I came up seems complicated and I wanted to see if anyone on the forum had a simpler approach. I set the Queue of length 5, so I can potentially put in 5 pointers to my 5 data-sets into the queue before the sending (producer) task will block. I then set up a circular buffer of 5 data-sets (structs) for the data itself. Now, since I want the sending task to block in case the data-sets are full (all 5 places are used up), I thought I’d use a 5-count semaphore to block access to the data-set to allow the sending task to block. (The sending task cannot block on the queue directly because it doesn’t yet have the address of the data-set to populate the queue with). The way this will work, I envision, is that the sending task will acquire a semaphore to access the data-set and then write the new value to one of the 5 spots in the data-set. Assuming that there is a spot available, and the write is successful, the sending task will then write a pointer to the data-set to the queue. The receiving task (consumer) since it is blocked on the queue, will then unblock and will be able to access the data by dereferencing the pointer in the queue assuming the queue is not full. Is this a good way to set this up? Or is there a less complicated way? I’d like your input. Thanks!
What I do is set up two queue, one to send pointers for full buffers from the producer to the consumer, and a second one to send pointers for empty buffers from the consumer to the producer. Your initialization code just needs to fill the empty buffer queue, and off things go.
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.