|
求助:想给Protothreads加个消息队列,同一个消息控制块(具体消息内容不同)不能重复发送,
重复发送要么覆盖,要么成死结。
typedef struct _Object
{
struct _Object *next;
}_Object_t;
typedef struct _MSG
{ struct _MSG *next;
uint8 data;
}MSG_t;
typedef struct _MSGQ
{
MSG_t * msg;
}MSGQ_t;
void MSG_Post(MSGQ_t *p_msg_queue, MSG_t *p_msg);
MSG_t * MSG_Pend(MSGQ_t *p_msg_queue);
void _AppendObject(void *pQueue, void *pObject) //Object加到队列Queue尾部
{
_Object_t * q = (_Object_t *)pQueue, *p = (_Object_t *)pObject;
while(q->next)
{
q=q->next;
}
q->next=p;
p->next = NULL;
}
void *_RemoveFirstObject(void *pQueue) //取出队列Queue头部
{
_Object_t *p,*q=(_Object_t *)pQueue;
if(q->next) //如果队列有数据
{
if(p=q->next) //如果队列还有下一个数据
{
q->next=p; //下一个数据为队列头部
}
else //如果队列无下一个数据
{
q->next=NULL; //队列为空
}
return p; //返回第一个数据
}
else //如果队列没有数据
{
return NULL; //返回空指针
}
}
void MSG_Post(MSGQ_t *p_msg_queue, MSG_t *p_msg)
{
_AppendObject(p_msg_queue,p_msg);
}
MSG_t * MSG_Pend(MSGQ_t *p_msg_queue)
{
return (MSG_t *)_RemoveFirstObject(p_msg_queue); } |
阿莫论坛20周年了!感谢大家的支持与爱护!!
一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。
|