Optimize message dropping computation using oldest_msg
@@ -432,6 +432,12 @@ static inline error_return_t MsgAlloc_ClearMsgSpace(void *from, void *to)
mem_stat->msg_drop_number++;
}
}
+ // check if there is a msg in the space we need
+ // Start by checking if the oldest message is out of scope
+ if (((uint32_t)oldest_msg >= (uint32_t)from) && ((uint32_t)oldest_msg <= (uint32_t)to))
+ {
+ // We have to drop some messages for sure
+ mem_stat->buffer_occupation_ratio = 100;
while (((uint32_t)luos_tasks[0].msg_pt >= (uint32_t)from) && ((uint32_t)luos_tasks[0].msg_pt <= (uint32_t)to) && (luos_tasks_stack_id > 0))
{
// This message is in the space we want to use, clear the task
@@ -439,6 +445,7 @@ static inline error_return_t MsgAlloc_ClearMsgSpace(void *from, void *to)
if (mem_stat->msg_drop_number < 0xFF)
{
mem_stat->msg_drop_number++;
+ mem_stat->buffer_occupation_ratio = 100;
}
}
// check if there is no msg between from and to on msg_tasks
@@ -449,6 +456,7 @@ static inline error_return_t MsgAlloc_ClearMsgSpace(void *from, void *to)
if (mem_stat->msg_drop_number < 0xFF)
{
mem_stat->msg_drop_number++;
+ mem_stat->buffer_occupation_ratio = 100;
}
}
// check if there is no msg between from and to on tx_tasks
@@ -459,6 +467,8 @@ static inline error_return_t MsgAlloc_ClearMsgSpace(void *from, void *to)
if (mem_stat->msg_drop_number < 0xFF)
{
mem_stat->msg_drop_number++;
+ mem_stat->buffer_occupation_ratio = 100;
+ }
}
}
// if we go here there is no reason to continue because newest messages can't overlap the memory zone.
