From c8f9421298f5f973b31a7cbbc76e61b06eca03bc Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sun, 13 Dec 2020 15:14:40 +0000 Subject: htl: Add pshared semaphore support The implementation is extremely similar to the nptl implementation, but with slight differences in the futex interface. This fixes some of BZ 25521. --- htl/Makefile | 2 +- htl/pt-internal.h | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) (limited to 'htl') diff --git a/htl/Makefile b/htl/Makefile index 326a920fb3..901deae5f9 100644 --- a/htl/Makefile +++ b/htl/Makefile @@ -130,7 +130,7 @@ libpthread-routines := pt-attr pt-attr-destroy pt-attr-getdetachstate \ \ sem-close sem-destroy sem-getvalue sem-init sem-open \ sem-post sem-timedwait sem-trywait sem-unlink \ - sem-wait \ + sem-wait sem-waitfast \ \ shm-directory \ \ diff --git a/htl/pt-internal.h b/htl/pt-internal.h index 9dffa0e32e..62204d79e5 100644 --- a/htl/pt-internal.h +++ b/htl/pt-internal.h @@ -331,4 +331,37 @@ extern const struct __pthread_rwlockattr __pthread_default_rwlockattr; /* Default condition attributes. */ extern const struct __pthread_condattr __pthread_default_condattr; +/* Semaphore encoding. + See nptl implementation for the details. */ +struct new_sem +{ +#if __HAVE_64B_ATOMICS + /* The data field holds both value (in the least-significant 32 bits) and + nwaiters. */ +# if __BYTE_ORDER == __LITTLE_ENDIAN +# define SEM_VALUE_OFFSET 0 +# elif __BYTE_ORDER == __BIG_ENDIAN +# define SEM_VALUE_OFFSET 1 +# else +# error Unsupported byte order. +# endif +# define SEM_NWAITERS_SHIFT 32 +# define SEM_VALUE_MASK (~(unsigned int)0) + uint64_t data; + int pshared; +#define __SEMAPHORE_INITIALIZER(value, pshared) \ + { (value), (pshared) } +#else +# define SEM_VALUE_SHIFT 1 +# define SEM_NWAITERS_MASK ((unsigned int)1) + unsigned int value; + unsigned int nwaiters; + int pshared; +#define __SEMAPHORE_INITIALIZER(value, pshared) \ + { (value) << SEM_VALUE_SHIFT, 0, (pshared) } +#endif +}; + +extern int __sem_waitfast (struct new_sem *isem, int definitive_result); + #endif /* pt-internal.h */ -- cgit v1.2.3-70-g09d2