embeddedvxworks

How can a task wait on multiple vxworks Queues?


We have a vxWorks design which requires one task to process messages from two message queues, Q1 & Q2.

We would like to wait on both Queues and whichever gets a message, process the message from the queue.

We want to avoid either polling the queues or using a timeout value which could cause the other queue to fill up.

Is there a way to do this?


Solution

  • 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
                 }
             }
         }
     }