2014-10-17 Roland McGrath <roland@hack.frob.com>
+ * nptl/nptl-init.c (__pthread_initialize_minimal_internal):
+ Conditionalize FUTEX_PRIVATE_FLAG and FUTEX_CLOCK_REALTIME probes
+ on [__NR_futex].
+ * nptl/pthread_mutex_init.c (prio_inherit_missing): New function,
+ broken out of ...
+ (__pthread_mutex_init): ... here. Call it.
+ * nptl/pthread_mutex_lock.c (__pthread_mutex_lock_full):
+ Conditionalize PI cases on [__NR_futex].
+ * nptl/pthread_mutex_timedlock.c (pthread_mutex_timedlock): Likewise.
+ * nptl/pthread_mutex_trylock.c (__pthread_mutex_trylock): Likewise.
+ * nptl/pthread_mutex_unlock.c (__pthread_mutex_unlock_full): Likewise.
+
* nptl/nptl-init.c (sighandler_setxid, __xidcmd): Make definitions
conditional on [SIGSETXID].
(sigcancel_handler): Make definition conditional on [SIGCANCEL].
#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. */
{
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
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.
#include <assert.h>
#include <errno.h>
+#include <stdbool.h>
#include <string.h>
#include <kernel-features.h>
#include "pthreadP.h"
};
-#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)
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:
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:
}
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);
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;
}
}
}
break;
+#endif /* __NR_futex. */
case PTHREAD_MUTEX_PP_RECURSIVE_NP:
case PTHREAD_MUTEX_PP_ERRORCHECK_NP:
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:
}
}
break;
+#endif /* __NR_futex. */
case PTHREAD_MUTEX_PP_RECURSIVE_NP:
case PTHREAD_MUTEX_PP_ERRORCHECK_NP:
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:
return 0;
}
+#endif /* __NR_futex. */
case PTHREAD_MUTEX_PP_RECURSIVE_NP:
case PTHREAD_MUTEX_PP_ERRORCHECK_NP:
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))
THREAD_SETMEM (THREAD_SELF, robust_head.list_op_pending, NULL);
break;
+#endif /* __NR_futex. */
case PTHREAD_MUTEX_PP_RECURSIVE_NP:
/* Recursive mutex. */