[PATCH] Self-contained pthread_spinlock_t for RTEMS

Sebastian Huber sebastian.huber at embedded-brains.de
Thu Nov 17 12:48:44 UTC 2016


This is a Newlib patch. There are some open questions.

Should we allow nesting?

Which degree of error checks vs. performance do we want?

How do we deal with lock profiling?

Is it all right to forbid blocking calls inside the pthread spinlock 
critical section?

Do we want to support trylock (would be very difficult; if someone wants 
this, please show how to implement this)?

On 17/11/16 13:44, Sebastian Huber wrote:
> Turn pthread_spinlock_t into a self-contained object.  On uni-processor
> configurations, interrupts are disabled in the lock/trylock operations
> and the previous interrupt status is restored in the corresponding
> unlock operations.  On SMP configurations, a ticket lock is a acquired
> and released in addition.
>
> See also:
>
> https://devel.rtems.org/ticket/2674
>
> This implementation is simple and efficient.  However, this test case of
> the Linux Test Project would fail due to call of printf() and sleep()
> during spin lock ownership:
>
> https://github.com/linux-test-project/ltp/blob/master/testcases/open_posix_testsuite/conformance/interfaces/pthread_spin_lock/1-2.c
>
> Signed-off-by: Sebastian Huber <sebastian.huber at embedded-brains.de>
> ---
>   newlib/libc/sys/rtems/include/sys/_pthreadtypes.h | 6 +++++-
>   1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/newlib/libc/sys/rtems/include/sys/_pthreadtypes.h b/newlib/libc/sys/rtems/include/sys/_pthreadtypes.h
> index e1a88e9..0f46463 100644
> --- a/newlib/libc/sys/rtems/include/sys/_pthreadtypes.h
> +++ b/newlib/libc/sys/rtems/include/sys/_pthreadtypes.h
> @@ -22,6 +22,7 @@
>   
>   #include <sys/sched.h>
>   #include <sys/cpuset.h>
> +#include <sys/lock.h>
>   
>   /*
>    *  2.5 Primitive System Data Types,  P1003.1c/D10, p. 19.
> @@ -190,7 +191,10 @@ typedef struct {
>   /* POSIX Spin Lock Types */
>   
>   #if defined(_POSIX_SPIN_LOCKS)
> -typedef __uint32_t pthread_spinlock_t;        /* POSIX Spin Lock Object */
> +typedef struct {
> +  struct _Ticket_lock_Control _lock;
> +  __uint32_t                  _interrupt_state;
> +} pthread_spinlock_t;                        /* POSIX Spin Lock Object */
>   #endif /* defined(_POSIX_SPIN_LOCKS) */
>   
>   /* POSIX Reader/Writer Lock Types */

-- 
Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone   : +49 89 189 47 41-16
Fax     : +49 89 189 47 41-09
E-Mail  : sebastian.huber at embedded-brains.de
PGP     : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.




More information about the devel mailing list