aboutsummaryrefslogtreecommitdiff
path: root/nptl/sem_init.c
diff options
context:
space:
mode:
authorTorvald Riegel <triegel@redhat.com>2014-12-04 14:12:23 +0100
committerTorvald Riegel <triegel@redhat.com>2015-07-10 13:47:09 +0200
commita2f0363f817a58c4d3f439aa515a3b1d73efde36 (patch)
tree6204a1208c1421d573e8c91e4523376a18e1dd60 /nptl/sem_init.c
parent203c1a898dd2e281eae30f3c57ceb8d4a50b00f4 (diff)
downloadglibc-a2f0363f817a58c4d3f439aa515a3b1d73efde36.zip
glibc-a2f0363f817a58c4d3f439aa515a3b1d73efde36.tar.gz
glibc-a2f0363f817a58c4d3f439aa515a3b1d73efde36.tar.bz2
Add and use new glibc-internal futex API.
This adds new functions for futex operations, starting with wait, abstimed_wait, reltimed_wait, wake. They add documentation and error checking according to the current draft of the Linux kernel futex manpage. Waiting with absolute or relative timeouts is split into separate functions. This allows for removing a few cases of code duplication in pthreads code, which uses absolute timeouts; also, it allows us to put platform-specific code to go from an absolute to a relative timeout into the platform-specific futex abstractions.. Futex operations that can be canceled are also split out into separate functions suffixed by "_cancelable". There are separate versions for both Linux and NaCl; while they currently differ only slightly, my expectation is that the separate versions of lowlevellock-futex.h will eventually be merged into futex-internal.h when we get to move the lll_ functions over to the new futex API.
Diffstat (limited to 'nptl/sem_init.c')
-rw-r--r--nptl/sem_init.c27
1 files changed, 10 insertions, 17 deletions
diff --git a/nptl/sem_init.c b/nptl/sem_init.c
index 575b661..bd1b592 100644
--- a/nptl/sem_init.c
+++ b/nptl/sem_init.c
@@ -21,22 +21,7 @@
#include <shlib-compat.h>
#include "semaphoreP.h"
#include <kernel-features.h>
-
-/* Returns FUTEX_PRIVATE if pshared is zero and private futexes are supported;
- returns FUTEX_SHARED otherwise.
- TODO Remove when cleaning up the futex API throughout glibc. */
-static __always_inline int
-futex_private_if_supported (int pshared)
-{
- if (pshared != 0)
- return LLL_SHARED;
-#ifdef __ASSUME_PRIVATE_FUTEX
- return LLL_PRIVATE;
-#else
- return THREAD_GETMEM (THREAD_SELF, header.private_futex)
- ^ FUTEX_PRIVATE_FLAG;
-#endif
-}
+#include <futex-internal.h>
int
@@ -48,6 +33,13 @@ __new_sem_init (sem_t *sem, int pshared, unsigned int value)
__set_errno (EINVAL);
return -1;
}
+ pshared = pshared != 0 ? PTHREAD_PROCESS_SHARED : PTHREAD_PROCESS_PRIVATE;
+ int err = futex_supports_pshared (pshared);
+ if (err != 0)
+ {
+ __set_errno (err);
+ return -1;
+ }
/* Map to the internal type. */
struct new_sem *isem = (struct new_sem *) sem;
@@ -60,7 +52,8 @@ __new_sem_init (sem_t *sem, int pshared, unsigned int value)
isem->nwaiters = 0;
#endif
- isem->private = futex_private_if_supported (pshared);
+ isem->private = (pshared == PTHREAD_PROCESS_PRIVATE
+ ? FUTEX_PRIVATE : FUTEX_SHARED);
return 0;
}