aboutsummaryrefslogtreecommitdiff
path: root/htl
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2020-12-13 15:14:40 +0000
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2020-12-16 01:58:33 +0100
commitc8f9421298f5f973b31a7cbbc76e61b06eca03bc (patch)
tree86bf4c058624d76b6e35fd44f1f506c3ad9b3d94 /htl
parent644d98ec4d8405e9b721ecb715483ea1983e116f (diff)
downloadglibc-c8f9421298f5f973b31a7cbbc76e61b06eca03bc.zip
glibc-c8f9421298f5f973b31a7cbbc76e61b06eca03bc.tar.gz
glibc-c8f9421298f5f973b31a7cbbc76e61b06eca03bc.tar.bz2
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.
Diffstat (limited to 'htl')
-rw-r--r--htl/Makefile2
-rw-r--r--htl/pt-internal.h33
2 files changed, 34 insertions, 1 deletions
diff --git a/htl/Makefile b/htl/Makefile
index 326a920..901deae 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 9dffa0e..62204d7 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 */