[PATCH] rtems: Fix no protocol mutex release

Pavel Pisa ppisa4lists at pikron.com
Sat Jun 4 09:57:37 UTC 2016


Hello Sebastian and others,

generally, I am highly thankfull for all that hard work done to bring
RTEMS to multicore SoC era and all that with attempt to keep RTEMS
API compatible with existing applications.

On Friday 03 of June 2016 15:26:15 Sebastian Huber wrote:
> On 03/06/16 15:24, Joel Sherrill wrote:
> > Binary semaphores with no protocol can be used for condition
> > synchronization. This was described way back by Dijkstra. Usually the
> > binary semaphore starts locked, a thread will then block upon an
> > attempt to lock it. An ISO or other thread can release or flush to
> > announce the condition.
>
> This is a simple binary semaphore in RTEMS (RTEMS_SIMPLE_BINARY_SEMAPHORE).
>
> This patch is about binary semaphores (RTEMS_BINARY_SEMAPHORE).

But if the RTEMS API is getting touched then in this regard I rise
again my opinion that semaphores and mutexes should be strictly separated.
This would prevent confusion and help to static code analyze tools etc.

The RTEMS_BINARY_SEMAPHORE has been near to mutex in the past but now
it is strictly a mutex (if I am correct). But when application programmer
ports, intend to use, binary semaphore, they have to know that binary 
semaphore is RTEMS_SIMPLE_BINARY_SEMAPHORE in the RTEMS world.
Before proposed patches intuitive use has not been ideal but at least
does not lead to direct breakage.

One option is to left only single API (rtems_semaphore_*) and define
RTEMS_MUTEX_SEMAPHORE instead of RTEMS_BINARY_SEMAPHORE. But there is
problem left to catch incorrect assumptions what is mutex
and what semaphore in functions/subsystems files which do not directly
include corresponding semaphore initialization and its kind.
And confusion would not be prevented.
That is why I suggest to separate set of SCORE and corresponding
RTEMS directives for mutexes

  rtems_mutex_*

This helps to static code analysis and incorrect use cases catching
(for example by Coccinelle http://coccinelle.lip6.fr ).
There should be some wrapper which allows to use semaphores
directives as mutexes during code transition period/one or two
releases but new applications and mainline RTEMS code should
switch to use rtems_mutex_.

Best wishes,

                 Pavel


More information about the devel mailing list