aboutsummaryrefslogtreecommitdiff
path: root/nptl
diff options
context:
space:
mode:
authorRoland McGrath <roland@hack.frob.com>2014-10-17 14:30:16 -0700
committerRoland McGrath <roland@hack.frob.com>2014-10-17 14:30:16 -0700
commit184ee94010786a9e0952aff3af39eba1d72287d3 (patch)
treeb7f4a680b4340f565951a599a6d86f88e61a1711 /nptl
parent327ae2570744dabf7f065a6b529d16cc22438603 (diff)
downloadglibc-184ee94010786a9e0952aff3af39eba1d72287d3.zip
glibc-184ee94010786a9e0952aff3af39eba1d72287d3.tar.gz
glibc-184ee94010786a9e0952aff3af39eba1d72287d3.tar.bz2
NPTL: Conditionalize direct futex syscall uses.
Diffstat (limited to 'nptl')
-rw-r--r--nptl/nptl-init.c8
-rw-r--r--nptl/pthread_mutex_init.c36
-rw-r--r--nptl/pthread_mutex_lock.c13
-rw-r--r--nptl/pthread_mutex_timedlock.c5
-rw-r--r--nptl/pthread_mutex_trylock.c5
-rw-r--r--nptl/pthread_mutex_unlock.c5
6 files changed, 50 insertions, 22 deletions
diff --git a/nptl/nptl-init.c b/nptl/nptl-init.c
index d8154c4..a39ec9a 100644
--- a/nptl/nptl-init.c
+++ b/nptl/nptl-init.c
@@ -329,7 +329,8 @@ __pthread_initialize_minimal_internal (void)
#endif
set_robust_list_not_avail ();
-#ifndef __ASSUME_PRIVATE_FUTEX
+#ifdef __NR_futex
+# ifndef __ASSUME_PRIVATE_FUTEX
/* Private futexes are always used (at least internally) so that
doing the test once this early is beneficial. */
{
@@ -345,8 +346,8 @@ __pthread_initialize_minimal_internal (void)
know the former are not supported. This also means we know the
kernel will return ENOSYS for unknown operations. */
if (THREAD_GETMEM (pd, header.private_futex) != 0)
-#endif
-#ifndef __ASSUME_FUTEX_CLOCK_REALTIME
+# endif
+# ifndef __ASSUME_FUTEX_CLOCK_REALTIME
{
int word = 0;
/* NB: the syscall actually takes six parameters. The last is the
@@ -361,6 +362,7 @@ __pthread_initialize_minimal_internal (void)
if (INTERNAL_SYSCALL_ERRNO (word, err) != ENOSYS)
__set_futex_clock_realtime ();
}
+# endif
#endif
/* Set initial thread's stack block from 0 up to __libc_stack_end.
diff --git a/nptl/pthread_mutex_init.c b/nptl/pthread_mutex_init.c
index 2b34688..9f28b8d 100644
--- a/nptl/pthread_mutex_init.c
+++ b/nptl/pthread_mutex_init.c
@@ -18,6 +18,7 @@
#include <assert.h>
#include <errno.h>
+#include <stdbool.h>
#include <string.h>
#include <kernel-features.h>
#include "pthreadP.h"
@@ -31,10 +32,26 @@ static const struct pthread_mutexattr default_mutexattr =
};
-#ifndef __ASSUME_FUTEX_LOCK_PI
-static int tpi_supported;
+static bool
+prio_inherit_missing (void)
+{
+#ifdef __NR_futex
+# ifndef __ASSUME_FUTEX_LOCK_PI
+ static int tpi_supported;
+ if (__glibc_unlikely (tpi_supported == 0))
+ {
+ int lock = 0;
+ INTERNAL_SYSCALL_DECL (err);
+ int ret = INTERNAL_SYSCALL (futex, err, 4, &lock, FUTEX_UNLOCK_PI, 0, 0);
+ assert (INTERNAL_SYSCALL_ERROR_P (ret, err));
+ tpi_supported = INTERNAL_SYSCALL_ERRNO (ret, err) == ENOSYS ? -1 : 1;
+ }
+ return __glibc_unlikely (tpi_supported < 0);
+# endif
+ return false;
#endif
-
+ return true;
+}
int
__pthread_mutex_init (mutex, mutexattr)
@@ -58,19 +75,8 @@ __pthread_mutex_init (mutex, mutexattr)
break;
case PTHREAD_PRIO_INHERIT << PTHREAD_MUTEXATTR_PROTOCOL_SHIFT:
-#ifndef __ASSUME_FUTEX_LOCK_PI
- if (__glibc_unlikely (tpi_supported == 0))
- {
- int lock = 0;
- INTERNAL_SYSCALL_DECL (err);
- int ret = INTERNAL_SYSCALL (futex, err, 4, &lock, FUTEX_UNLOCK_PI,
- 0, 0);
- assert (INTERNAL_SYSCALL_ERROR_P (ret, err));
- tpi_supported = INTERNAL_SYSCALL_ERRNO (ret, err) == ENOSYS ? -1 : 1;
- }
- if (__glibc_unlikely (tpi_supported < 0))
+ if (__glibc_unlikely (prio_inherit_missing ()))
return ENOTSUP;
-#endif
break;
default:
diff --git a/nptl/pthread_mutex_lock.c b/nptl/pthread_mutex_lock.c
index d94f4c9..6d4acd4 100644
--- a/nptl/pthread_mutex_lock.c
+++ b/nptl/pthread_mutex_lock.c
@@ -276,6 +276,10 @@ __pthread_mutex_lock_full (pthread_mutex_t *mutex)
THREAD_SETMEM (THREAD_SELF, robust_head.list_op_pending, NULL);
break;
+ /* The PI support requires the Linux futex system call. If that's not
+ available, pthread_mutex_init should never have allowed the type to
+ be set. So it will get the default case for an invalid type. */
+#ifdef __NR_futex
case PTHREAD_MUTEX_PI_RECURSIVE_NP:
case PTHREAD_MUTEX_PI_ERRORCHECK_NP:
case PTHREAD_MUTEX_PI_NORMAL_NP:
@@ -321,9 +325,9 @@ __pthread_mutex_lock_full (pthread_mutex_t *mutex)
}
int newval = id;
-#ifdef NO_INCR
+# ifdef NO_INCR
newval |= FUTEX_WAITERS;
-#endif
+# endif
oldval = atomic_compare_and_exchange_val_acq (&mutex->__data.__lock,
newval, 0);
@@ -377,9 +381,9 @@ __pthread_mutex_lock_full (pthread_mutex_t *mutex)
incremented which is not correct because the old owner
has to be discounted. If we are not supposed to
increment __nusers we actually have to decrement it here. */
-#ifdef NO_INCR
+# ifdef NO_INCR
--mutex->__data.__nusers;
-#endif
+# endif
return EOWNERDEAD;
}
@@ -409,6 +413,7 @@ __pthread_mutex_lock_full (pthread_mutex_t *mutex)
}
}
break;
+#endif /* __NR_futex. */
case PTHREAD_MUTEX_PP_RECURSIVE_NP:
case PTHREAD_MUTEX_PP_ERRORCHECK_NP:
diff --git a/nptl/pthread_mutex_timedlock.c b/nptl/pthread_mutex_timedlock.c
index 57644c3..a840f8e 100644
--- a/nptl/pthread_mutex_timedlock.c
+++ b/nptl/pthread_mutex_timedlock.c
@@ -230,6 +230,10 @@ pthread_mutex_timedlock (mutex, abstime)
THREAD_SETMEM (THREAD_SELF, robust_head.list_op_pending, NULL);
break;
+ /* The PI support requires the Linux futex system call. If that's not
+ available, pthread_mutex_init should never have allowed the type to
+ be set. So it will get the default case for an invalid type. */
+#ifdef __NR_futex
case PTHREAD_MUTEX_PI_RECURSIVE_NP:
case PTHREAD_MUTEX_PI_ERRORCHECK_NP:
case PTHREAD_MUTEX_PI_NORMAL_NP:
@@ -382,6 +386,7 @@ pthread_mutex_timedlock (mutex, abstime)
}
}
break;
+#endif /* __NR_futex. */
case PTHREAD_MUTEX_PP_RECURSIVE_NP:
case PTHREAD_MUTEX_PP_ERRORCHECK_NP:
diff --git a/nptl/pthread_mutex_trylock.c b/nptl/pthread_mutex_trylock.c
index 0867b06..0293d0f 100644
--- a/nptl/pthread_mutex_trylock.c
+++ b/nptl/pthread_mutex_trylock.c
@@ -191,6 +191,10 @@ __pthread_mutex_trylock (mutex)
return 0;
+ /* The PI support requires the Linux futex system call. If that's not
+ available, pthread_mutex_init should never have allowed the type to
+ be set. So it will get the default case for an invalid type. */
+#ifdef __NR_futex
case PTHREAD_MUTEX_PI_RECURSIVE_NP:
case PTHREAD_MUTEX_PI_ERRORCHECK_NP:
case PTHREAD_MUTEX_PI_NORMAL_NP:
@@ -319,6 +323,7 @@ __pthread_mutex_trylock (mutex)
return 0;
}
+#endif /* __NR_futex. */
case PTHREAD_MUTEX_PP_RECURSIVE_NP:
case PTHREAD_MUTEX_PP_ERRORCHECK_NP:
diff --git a/nptl/pthread_mutex_unlock.c b/nptl/pthread_mutex_unlock.c
index 95ae933..8064de0 100644
--- a/nptl/pthread_mutex_unlock.c
+++ b/nptl/pthread_mutex_unlock.c
@@ -158,6 +158,10 @@ __pthread_mutex_unlock_full (pthread_mutex_t *mutex, int decr)
THREAD_SETMEM (THREAD_SELF, robust_head.list_op_pending, NULL);
break;
+ /* The PI support requires the Linux futex system call. If that's not
+ available, pthread_mutex_init should never have allowed the type to
+ be set. So it will get the default case for an invalid type. */
+#ifdef __NR_futex
case PTHREAD_MUTEX_PI_RECURSIVE_NP:
/* Recursive mutex. */
if (mutex->__data.__owner != THREAD_GETMEM (THREAD_SELF, tid))
@@ -245,6 +249,7 @@ __pthread_mutex_unlock_full (pthread_mutex_t *mutex, int decr)
THREAD_SETMEM (THREAD_SELF, robust_head.list_op_pending, NULL);
break;
+#endif /* __NR_futex. */
case PTHREAD_MUTEX_PP_RECURSIVE_NP:
/* Recursive mutex. */