Self-contained pthread_spinlock_t for RTEMS

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@embedded-brains.de>
This commit is contained in:
Sebastian Huber 2016-11-24 10:58:35 +01:00 committed by Corinna Vinschen
parent 1c54541172
commit 724e21493a
1 changed files with 5 additions and 1 deletions

View File

@ -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 */