一个任务如何等待多个vxworks队列? [英] How can a task wait on multiple vxworks Queues?

查看:181
本文介绍了一个任务如何等待多个vxworks队列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个vxWorks设计,需要一个任务来处理通过两个消息队列发送的高优先级消息和低优先级消息。

给定优先级的消息必须按照FIFO顺序进行处理。



例如,按照接收的顺序处理所有高优先级消息,然后处理低优先级消息。如果没有高优先级消息,则立即处理低优先级消息。



有没有办法?

解决方案

如果使用命名管道(pipeDevCreate(),write(),read())而不是消息队列,则可以使用select()阻止,直到有消息任一管。



无论何时select()触发器,都会处理高优先级管道中的所有邮件。然后,您从低优先级管道处理单个消息。然后再次调用select(循环)。



示例代码片段:

  //初始化:创建高优先级和命名管道
pipeDrv(); //初始化管道驱动
int fdHi = pipeDevCreate(/ pipe / high,numMsgs,msgSize);
int fdLo = pipeDevCreate(/ pipe / low,numMsgs,msgSize);

...

//消息发送线程:向管道添加消息
write(fdHi,buf,sizeof(buf));

...

//消息处理线程:select loop
fd_set rdFdSet;

while(1)
{
FD_ZERO(& rdFdSet);
FD_SET(fdHi,& rdFdSet);
FD_SET(fdLo,& rdFdSet;

if(select(FD_SETSIZE,& rdFdSet,NULL,NULL,NULL)!= ERROR)
{
if (FD_ISSET(fdHi,& rdFdSet))
{
//处理所有高优先级消息
while(read(fdHi,buf,size)> 0)
{
//处理高优先级
}
}

如果(FD_ISSET(fdLo,& rdFdSet))
{
//处理一个低优先级消息
if(read(fdLo,buf,size)> 0)
{
//进程低优先级
}
}
}
}


We have a vxWorks design which requires one task to process both high and low priority messages sent over two message queues.
The messages for a given priority have to be processed in FIFO order.

For example, process all the high priority messages in the order they were received, then process the low priority messages. If there is no high priority message, then process the low priority message immediately.

Is there a way to do this?

解决方案

If you use named pipes (pipeDevCreate(), write(), read()) instead of message queues, you can use select() to block until there are messages in either pipe.

Whenever select() triggers, you process all messages in the high priority pipe. Then you process a single message from the low priority pipe. Then call select again (loop).

Example Code snippets:

 // Initialization: Create high and low priority named pipes
 pipeDrv(); //initialize pipe driver
 int fdHi = pipeDevCreate("/pipe/high",numMsgs,msgSize);
 int fdLo = pipeDevCreate("/pipe/low",numMsgs,msgSize);

 ...

 // Message sending thread: Add messages to pipe
 write(fdHi, buf, sizeof(buf));

 ...

 // Message processing Thread: select loop
 fd_set rdFdSet;

 while(1)
 {
     FD_ZERO(&rdFdSet);
     FD_SET(fdHi, &rdFdSet);
     FD_SET(fdLo, &rdFdSet;

     if (select(FD_SETSIZE, &rdFdSet, NULL, NULL, NULL) != ERROR)
     {
         if (FD_ISSET(fdHi, &rdFdSet))
         {
             // process all high-priority messages
             while(read(fdHi,buf,size) > 0)
             {
                 //process high-priority
             }
         }

         if (FD_ISSET(fdLo, &rdFdSet))
         {
             // process a single low priority message
             if (read(fdLo,buf,size) > 0)
             {
                 // process low priority
             }
         }
     }
 }

这篇关于一个任务如何等待多个vxworks队列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆