summary refs log tree commit diff
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2006-07-01 07:31:09 +0000
committerUlrich Drepper <drepper@redhat.com>2006-07-01 07:31:09 +0000
commitf3be81a91cdd1b42c47e4d8501dd96d0f1666520 (patch)
tree4ad4148cace87d6859d64572be37ee6ba96fc5b8
parent361a3706e1a353d587127eab967a229c20177808 (diff)
downloadglibc-f3be81a91cdd1b42c47e4d8501dd96d0f1666520.tar.gz
glibc-f3be81a91cdd1b42c47e4d8501dd96d0f1666520.tar.xz
glibc-f3be81a91cdd1b42c47e4d8501dd96d0f1666520.zip
* pthread_mutex_init.c (__pthread_mutex_init): Move some
	computations to compile time.
-rw-r--r--nptl/ChangeLog5
-rw-r--r--nptl/pthread_mutex_init.c37
2 files changed, 31 insertions, 11 deletions
diff --git a/nptl/ChangeLog b/nptl/ChangeLog
index 907c1b910a..701b429e7c 100644
--- a/nptl/ChangeLog
+++ b/nptl/ChangeLog
@@ -1,3 +1,8 @@
+2006-07-01  Ulrich Drepper  <drepper@redhat.com>
+
+	* pthread_mutex_init.c (__pthread_mutex_init): Move some
+	computations to compile time.
+
 2006-06-04  Ulrich Drepper  <drepper@redhat.com>
 
 	* sysdeps/pthread/pthread.h: Add pthread_equal inline version.
diff --git a/nptl/pthread_mutex_init.c b/nptl/pthread_mutex_init.c
index c25e4035e5..6ffa30d5c0 100644
--- a/nptl/pthread_mutex_init.c
+++ b/nptl/pthread_mutex_init.c
@@ -41,11 +41,25 @@ __pthread_mutex_init (mutex, mutexattr)
   imutexattr = (const struct pthread_mutexattr *) mutexattr ?: &default_attr;
 
   /* Sanity checks.  */
-  // XXX For now we don't support priority inherited or priority protected
-  // XXX mutexes.
-  if ((imutexattr->mutexkind & PTHREAD_MUTEXATTR_PROTOCOL_MASK)
-      != (PTHREAD_PRIO_NONE << PTHREAD_MUTEXATTR_PROTOCOL_SHIFT))
-    return ENOTSUP;
+  // XXX For now we don't support priority protected mutexes.
+  switch (__builtin_expect (imutexattr->mutexkind
+			    & PTHREAD_MUTEXATTR_PROTOCOL_MASK,
+			    PTHREAD_PRIO_NONE
+			    << PTHREAD_MUTEXATTR_PROTOCOL_SHIFT))
+    {
+    case PTHREAD_PRIO_NONE << PTHREAD_MUTEXATTR_PROTOCOL_SHIFT:
+      break;
+
+    case PTHREAD_PRIO_INHERIT << PTHREAD_MUTEXATTR_PROTOCOL_SHIFT:
+#ifndef __ASSUME_SET_ROBUST_LIST
+      if (__set_robust_list_avail < 0)
+	return ENOTSUP;
+#endif
+      break;
+
+    default:
+      return ENOTSUP;
+    }
 
   /* Clear the whole variable.  */
   memset (mutex, '\0', __SIZEOF_PTHREAD_MUTEX_T);
@@ -64,14 +78,14 @@ __pthread_mutex_init (mutex, mutexattr)
       mutex->__data.__kind |= PTHREAD_MUTEX_ROBUST_NORMAL_NP;
     }
 
-  switch ((imutexattr->mutexkind & PTHREAD_MUTEXATTR_PROTOCOL_MASK)
-	  >> PTHREAD_MUTEXATTR_PROTOCOL_SHIFT)
+  switch (imutexattr->mutexkind & PTHREAD_MUTEXATTR_PROTOCOL_MASK)
     {
-    case PTHREAD_PRIO_INHERIT:
-      mutex->__data.__kind |= PTHREAD_MUTEX_PRIO_INHERIT_PRIVATE_NP;
+    case PTHREAD_PRIO_INHERIT << PTHREAD_MUTEXATTR_PROTOCOL_SHIFT:
+      mutex->__data.__kind |= PTHREAD_MUTEX_PRIO_INHERIT_NP;
       break;
-    case PTHREAD_PRIO_PROTECT:
-      mutex->__data.__kind |= PTHREAD_MUTEX_PRIO_PROTECT_PRIVATE_NP;
+
+    case PTHREAD_PRIO_PROTECT << PTHREAD_MUTEXATTR_PROTOCOL_SHIFT:
+      mutex->__data.__kind |= PTHREAD_MUTEX_PRIO_PROTECT_NP;
       if (PTHREAD_MUTEX_PRIO_CEILING_MASK
 	  == PTHREAD_MUTEXATTR_PRIO_CEILING_MASK)
 	mutex->__data.__kind |= (imutexattr->mutexkind
@@ -82,6 +96,7 @@ __pthread_mutex_init (mutex, mutexattr)
 				 >> PTHREAD_MUTEXATTR_PRIO_CEILING_SHIFT)
 				<< PTHREAD_MUTEX_PRIO_CEILING_SHIFT;
       break;
+
     default:
       break;
     }