public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Self-contained pthread_spinlock_t for RTEMS
@ 2016-11-24 10:04 Sebastian Huber
  2016-11-24 15:59 ` Corinna Vinschen
  0 siblings, 1 reply; 2+ messages in thread
From: Sebastian Huber @ 2016-11-24 10:04 UTC (permalink / raw)
  To: newlib; +Cc: Sebastian Huber

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>
---
 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..bd66c68 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 */
-- 
1.8.4.5

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Self-contained pthread_spinlock_t for RTEMS
  2016-11-24 10:04 [PATCH] Self-contained pthread_spinlock_t for RTEMS Sebastian Huber
@ 2016-11-24 15:59 ` Corinna Vinschen
  0 siblings, 0 replies; 2+ messages in thread
From: Corinna Vinschen @ 2016-11-24 15:59 UTC (permalink / raw)
  To: newlib

[-- Attachment #1: Type: text/plain, Size: 839 bytes --]

On Nov 24 10:58, 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

Patch applied.


Thanks,
Corinna

-- 
Corinna Vinschen
Cygwin Maintainer
Red Hat

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-11-24 15:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-24 10:04 [PATCH] Self-contained pthread_spinlock_t for RTEMS Sebastian Huber
2016-11-24 15:59 ` Corinna Vinschen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).