Waiting for multiple events

Mogens Dybæk Christensen MogensD.Christensen at man.eu
Wed Nov 30 09:04:07 UTC 2011


I think we will go for a solution with message ques. They are better supported in RTEMS (accessible from interrupt) than in RTXC.

But just to conclude an interesting discussion, here are some details about the old implementation.

First, the wrapper is written in C++. It exists for target and for logical testing on PC. krnl_WaitableObject is the base class of krnl_Semaphore, krnl_Queue and krnl_Timer. So they can be combined in a wait list. Here is a snippet from the Doxygen documentation:

/**
 * The krnl_WaitList can be used for waiting for multiple waitable objects
 * (i.e. objects of classes derived from krnl_WaitableObject).
 *
 * The krnl_WaitList constructor takes a single argument, namely the maximum
 * number of krnl_WaitableObject objects that should be waited for.
 *
 * To wait for multiple objects, each of these must be registered with the list
 * using the registerObject() function.
 *
 * When properly instantiated and initialised with registerObject() calls, the
 * wait list has a member function wait() that waits indefinitely for one of the
 * registered waitable objects to be signalled. The function returns the
 * krnl_WaitId of the waitable object that was actually signalled.
 *
 * krnl_WaitList usage example:
 *
 * <pre>
 *    krnl_Semaphore * semaphorePtrOne;
 *    krnl_Semaphore * semaphorePtrTwo;
 *
 *    void main(void)
 *    {
 *       krnl_WaitList waitList(2);
 *       waitList.registerObject(semaphorePtrOne);
 *       waitList.registerObject(semaphorePtrTwo);
 *
 *       for(;;)
 *       {
 *          krnl_WaitId event=waitList.wait();
 *
 *          if(event==semaphorePtrOne->getWaitId())
 *          {
 *             // do something when semaphorePtrOne is signalled
 *          }
 *          else if(event==semaphorePtrTwo->getWaitId())
 *          {
 *             // do something when semaphorePtrTwo is signalled
 *          }
 *          else
 *          {
 *             // panic!
 *          }
 *       }
 *   }
 * </pre>
 *

Internally krnl_WaitableObject has a RTXC semaphore, and the krnl_WaitList::wait() function is implemented using the RTXC call

      SEMA semaId=KS_waitm(d_rtxcSemaIdList);

KS_waitm takes a null terminated list of semaphores to wait for! That is where the film breaks.

As I said above, I think this pattern should be replaced with using message queue. I have done that with other real time kernels. Unfortunately, I don't think we can reproduce the footprint of krnl_WaitList, so existing source can compile unmodified. - You cannot win every time.  :)




From: Peter Dufault [mailto:dufault at hda.com]
Sent: 29. november 2011 16:36
To: Mogens Dybæk Christensen
Cc: rtems-users at rtems.org
Subject: Re: Waiting for multiple events


On Nov 29, 2011, at 10:32 , Mogens Dybæk Christensen wrote:


That will require manual modification of approx. 25 source files, so it is possible. The original idea was just to replace the OS wrapper, but the footprint seems too different.



Can you describe the interface you want to wrap?  I googled RTXC but the "semaphore list" interface wasn't clear.  Maybe someone can then suggest a POSIXY or RTEMS way of wrapping it.

Peter
-----------------
Peter Dufault
HD Associates, Inc.      Software and System Engineering

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/users/attachments/20111130/a0c51439/attachment.html>


More information about the users mailing list