Open
Description
Description of defect
From the API documentation get
is deprecated and it is better to use try_get
. However, get
really pops from the queue, while try_get
seems only read the message without popping it out. This is either a bug or the documentation should be fixed.
Target(s) affected by this defect ?
AMA3B1KK-KBR-B0
Toolchain(s) (name and version) displaying this defect ?
gcc version 10.2.1 20201103 (release) (xPack GNU Arm Embedded GCC, 64-bit)
What version of Mbed-os are you using (tag or sha) ?
mbed-os-6.9.0
What version(s) of tools are you using. List all that apply (E.g. mbed-cli)
Tools that comes with Mbed Studio 1.4.0
How is this defect reproduced ?
This code of using 'get':
Note: _msgs_thread
is the thread to parse the messages in queue. msgs_queues
is just a struct of queues.
_msgs_thread.start([this,msgs_queues] {
Queue<message_t, 4> * _msgs;
_msgs = &(msgs_queues->led);
while(1)
{
message_t ** msg_tmp;
osEvent evt = _msgs->get();
if(evt.status == osEventMessage)
{
message_t * recived_msg = (message_t *)evt.value.p;
if(recived_msg->reciverID == 0x01)
{
mbed_event_queue()->call(this, &LedService::alertLED, recived_msg->cmd[0]);
}
}
}
});
This is the code of using try_get
:
_msgs_thread.start([this,msgs_queues] {
Queue<message_t, 4> * _msgs;
_msgs = &(msgs_queues->led);
while(1)
{
MemoryPool<message_t, 1> mpool;
message_t ** msg_tmp;
osEvent evt = _msgs->get();
if(_msgs->try_get(msg_tmp))
if(evt.status == osEventMessage)
{
message_t * recived_msg = *msg_tmp;
if(recived_msg->reciverID == 0x01)
{
mbed_event_queue()->call(this, &LedService::alertLED, recived_msg->cmd[0]);
mpool.free(recived_msg);
}
}
}
});