views:

1212

answers:

3

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?

A: 
Benoit
I have a nagging feeling that this can allow a lo msg to be processed before a hi one, but don't know VxWorks so can't prove it. What happens if, while you're processing a lo msg, another lo msg and then a hi msg are added to your queues?
Steve Jessop
I guess as long as you get a combined EV01 + EV02 event it's fine, and there are only natural races. Is that what VxWorks does?
Steve Jessop
The example given wouldn't exactly match the spec, as you could do a lo msg when there are still hi msg left. You need to add a loop to process the hi msgs. That's what I meant by "drain" the queue.
Benoit
Seems like you answering your own questions!?
JayG
@JayG See http://stackoverflow.com/questions/86634/so-frequent-question-asker-and-answerer These are all questions that came from classes I teach.
Benoit
+3  A: 

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
             }
         }
     }
 }
JayG
A: 

hi, I want to know how can I implement mechanism in VxWorks where all priority messages will go into priority message queues and other messages will go to normal message queue. When messages will process it should first proccess all messages from prioriy queue first and then it should process normal queue.

please let me know