about summary refs log tree commit diff
path: root/nptl/pthread_mutex_init.c
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/pthread_mutex_init.c
parent327ae2570744dabf7f065a6b529d16cc22438603 (diff)
downloadglibc-184ee94010786a9e0952aff3af39eba1d72287d3.tar.gz
glibc-184ee94010786a9e0952aff3af39eba1d72287d3.tar.xz
glibc-184ee94010786a9e0952aff3af39eba1d72287d3.zip
NPTL: Conditionalize direct futex syscall uses.
Diffstat (limited to 'nptl/pthread_mutex_init.c')
-rw-r--r--nptl/pthread_mutex_init.c36
1 files changed, 21 insertions, 15 deletions
diff --git a/nptl/pthread_mutex_init.c b/nptl/pthread_mutex_init.c
index 2b3468835c..9f28b8d8dc 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: