MTK平台源码学习笔记之-------(queue.c)的学习

1、MTK环形消息队列的大小的定义:
#if defined(__MMI_DUAL_SIM_MASTER__)
#define CIRCQ_NO_OF_NODES 130
#else
#define CIRCQ_NO_OF_NODES 65 

#endif

可见,MTK平台在

单卡时,环形消息队列的大小为65,

双卡时,环形消息队列的大小为130。


2、消息的队列的结构的定义:

typedef struct ilm_struct {
   module_type       src_mod_id;
   module_type       dest_mod_id;
   sap_type          sap_id;
   msg_type          msg_id;
   local_para_struct *local_para_ptr;
   peer_buff_struct  *peer_buff_ptr;
} ilm_struct;
#define MYQUEUE         ilm_struct
MYQUEUE circq_array[CIRCQ_NO_OF_NODES];

circq_array极为消息队列的数组。


3、环形消息队列的几个标志位:

U8 circq_read = 0, circq_write = 0, circq_messages = 0, max_circq_messages = 0;

circq_read 队列的标志位

circq_write队列的标志位

circq_messages   队列中的元素个数

max_circq_messages  队列中的元素个数的最大值


4、 读和写消息队列

U8 OslReadCircularQ(void *msgPtr)
{
    MMI_TRACE(MMI_FW_TRC_G6_FRM_DETAIL, TRC_MMI_FRM_QUEUE_READ_CQ, circq_messages);
    if (circq_messages == 0)
    {
        return 0;
    }
    memcpy(msgPtr, circq_array + circq_read, sizeof(MYQUEUE));
    if (++circq_read == CIRCQ_NO_OF_NODES)
    {
        circq_read = 0;
    }
    --circq_messages;
    return 1;
}


U8 OslWriteCircularQ(void *msgPtr)

{
    MMI_TRACE(MMI_FW_TRC_G6_FRM_DETAIL, TRC_MMI_FRM_QUEUE_WRITE_CQ, circq_messages, ((MYQUEUE *)msgPtr)->msg_id);
    if (circq_messages == CIRCQ_NO_OF_NODES)
    {
        MMI_ASSERT(0);
        return 0;
    }
    memcpy(circq_array + circq_write, msgPtr, sizeof(MYQUEUE));
    if (++circq_write == CIRCQ_NO_OF_NODES)
    {
        circq_write = 0;
    }
    ++circq_messages;
    if (max_circq_messages < circq_messages)
    {
        max_circq_messages = circq_messages;
    }
    return 1;
}

不错的环形队列的读和写的算法的实现,该好好看看。

5、寻找队列中上一个  刚写入的消息元素

U8 OslLookUpLastCircularQMsg(void *msgPtr)
{
    if (circq_messages > 0)
    {
        if (circq_write == 0)
        {
            last_read_index = CIRCQ_NO_OF_NODES;  // 如果要写的标志位为0,那么是数组最后一个;
        }
        else
        {
            last_read_index = circq_write - 1;
        }
        memcpy(msgPtr, circq_array + last_read_index, sizeof(MYQUEUE));
        return 1;
    }
    else
    {
        memset(msgPtr, 0, sizeof(MYQUEUE));
        return 0;
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值