瀏覽代碼

fix:队列创建的最大消息数不符合预期

wdfk-prog 1 年之前
父節點
當前提交
945da7e057
共有 1 個文件被更改,包括 4 次插入1 次删除
  1. 4 1
      cmsis_rtthread.c

+ 4 - 1
cmsis_rtthread.c

@@ -2058,7 +2058,10 @@ osMessageQueueId_t osMessageQueueNew(uint32_t msg_count, uint32_t msg_size, cons
 
     if ((RT_NULL == attr) || (RT_NULL == attr->mq_mem))
     {
-        mq_size = (msg_size + sizeof(struct rt_messagequeue)) * msg_count;
+        register rt_size_t msg_align_size;
+        /* get correct message size */
+        msg_align_size = RT_ALIGN(msg_size, RT_ALIGN_SIZE);
+        mq_size = (msg_align_size + sizeof(struct rt_mq_message)) * msg_count;
         mq_addr = rt_malloc(mq_size);
 
         if (RT_NULL == mq_addr)