@@ -31,6 +31,7 @@ ComQueue ::QueueConfigurationTable ::QueueConfigurationTable() {
3131ComQueue ::ComQueue (const char * const compName)
3232 : ComQueueComponentBase(compName),
3333 m_state(WAITING ),
34+ m_buffer_state(OWNED ),
3435 m_allocationId(static_cast <FwEnumStoreType>(-1 )),
3536 m_allocator(nullptr ),
3637 m_allocation(nullptr ) {
@@ -191,6 +192,8 @@ void ComQueue::run_handler(const FwIndexType portNum, U32 context) {
191192
192193void ComQueue ::dataReturnIn_handler (FwIndexType portNum, Fw::Buffer& data, const ComCfg::FrameContext& context) {
193194 static_assert (std::numeric_limits<FwIndexType>::is_signed, " FwIndexType must be signed" );
195+ FW_ASSERT (this ->m_buffer_state == UNOWNED );
196+ this ->m_buffer_state = OWNED ;
194197 // For the buffer queues, the index of the queue is portNum offset by COM_PORT_COUNT since
195198 // the first COM_PORT_COUNT queues are for ComBuffer. So we have for buffer queues:
196199 // queueNum = portNum + COM_PORT_COUNT
@@ -259,7 +262,8 @@ void ComQueue::sendComBuffer(Fw::ComBuffer& comBuffer, FwIndexType queueIndex) {
259262 FW_ASSERT (status == Fw::FW_SERIALIZE_OK , static_cast <FwAssertArgType>(status));
260263 context.set_apid (static_cast <ComCfg::Apid::T>(descriptor));
261264 context.set_comQueueIndex (queueIndex);
262-
265+ FW_ASSERT (this ->m_buffer_state == OWNED );
266+ this ->m_buffer_state = UNOWNED ;
263267 this ->dataOut_out (0 , outBuffer, context);
264268 // Set state to WAITING for the status to come back
265269 this ->m_state = WAITING ;
@@ -276,7 +280,8 @@ void ComQueue::sendBuffer(Fw::Buffer& buffer, FwIndexType queueIndex) {
276280 FW_ASSERT (status == Fw::FW_SERIALIZE_OK , static_cast <FwAssertArgType>(status));
277281 context.set_apid (static_cast <ComCfg::Apid::T>(descriptor));
278282 context.set_comQueueIndex (queueIndex);
279-
283+ FW_ASSERT (this ->m_buffer_state == OWNED );
284+ this ->m_buffer_state = UNOWNED ;
280285 this ->dataOut_out (0 , buffer, context);
281286 // Set state to WAITING for the status to come back
282287 this ->m_state = WAITING ;
@@ -301,12 +306,19 @@ void ComQueue::processQueue() {
301306
302307 // Send out the message based on the type
303308 if (entry.index < COM_PORT_COUNT ) {
304- Fw::ComBuffer comBuffer;
305- queue.dequeue (reinterpret_cast <U8 *>(&comBuffer), sizeof (comBuffer));
306- this ->sendComBuffer (comBuffer, entry.index );
309+ // Dequeue is reading the whole persisted Fw::ComBuffer object from the queue's storage.
310+ // thus it takes an address to the object to fill and the size of the actual object.
311+ FW_ASSERT (this ->m_buffer_state == OWNED );
312+ auto dequeue_status =
313+ queue.dequeue (reinterpret_cast <U8 *>(&this ->m_dequeued_com_buffer ), sizeof (this ->m_dequeued_com_buffer ));
314+ FW_ASSERT (dequeue_status == Fw::SerializeStatus::FW_SERIALIZE_OK ,
315+ static_cast <FwAssertArgType>(dequeue_status));
316+ this ->sendComBuffer (this ->m_dequeued_com_buffer , entry.index );
307317 } else {
308318 Fw::Buffer buffer;
309- queue.dequeue (reinterpret_cast <U8 *>(&buffer), sizeof (buffer));
319+ auto dequeue_status = queue.dequeue (reinterpret_cast <U8 *>(&buffer), sizeof (buffer));
320+ FW_ASSERT (dequeue_status == Fw::SerializeStatus::FW_SERIALIZE_OK ,
321+ static_cast <FwAssertArgType>(dequeue_status));
310322 this ->sendBuffer (buffer, entry.index );
311323 }
312324
0 commit comments