about summary refs log tree commit diff
path: root/nptl
diff options
context:
space:
mode:
Diffstat (limited to 'nptl')
-rw-r--r--nptl/ChangeLog6
-rw-r--r--nptl/sysdeps/pthread/pthread_cond_timedwait.c21
2 files changed, 15 insertions, 12 deletions
diff --git a/nptl/ChangeLog b/nptl/ChangeLog
index 351ff05041..c37d8a3ade 100644
--- a/nptl/ChangeLog
+++ b/nptl/ChangeLog
@@ -1,5 +1,9 @@
 2004-02-13  Ulrich Drepper  <drepper@redhat.com>
 
+	* sysdeps/pthread/pthread_cond_timedwait.c
+	(__pthread_cond_timedwait): Optimize.  Drop internal lock earlier.
+	Reuse code.  Add __builtin_expects.
+
 	* sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S
 	(__pthread_cond_timedwait): Get internal lock in case timeout has
 	passed before the futex syscall.
@@ -35,7 +39,7 @@
 
 2004-01-14  Ulrich Drepper  <drepper@redhat.com>
 
-	* init.c (pthread_funtions): Make array const.
+	* init.c (pthread_functions): Make array const.
 
 2004-01-13  Ulrich Drepper  <drepper@redhat.com>
 
diff --git a/nptl/sysdeps/pthread/pthread_cond_timedwait.c b/nptl/sysdeps/pthread/pthread_cond_timedwait.c
index 9fa2920f85..71e9cf7c8d 100644
--- a/nptl/sysdeps/pthread/pthread_cond_timedwait.c
+++ b/nptl/sysdeps/pthread/pthread_cond_timedwait.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2003 Free Software Foundation, Inc.
+/* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Martin Schwidefsky <schwidefsky@de.ibm.com>, 2003.
 
@@ -98,6 +98,9 @@ __pthread_cond_timedwait (cond, mutex, abstime)
 
   while (1)
     {
+      /* Prepare to wait.  Release the condvar futex.  */
+      lll_mutex_unlock (cond->__data.__lock);
+
       struct timespec rt;
       {
 #ifdef __NR_clock_gettime
@@ -138,19 +141,14 @@ __pthread_cond_timedwait (cond, mutex, abstime)
 	  --rt.tv_sec;
 	}
       /* Did we already time out?  */
-      if (rt.tv_sec < 0)
+      if (__builtin_expect (rt.tv_sec < 0, 0))
 	{
-	  /* Yep.  Adjust the sequence counter.  */
-	  ++cond->__data.__wakeup_seq;
+	  /* We are going to look at shared data again, so get the lock.  */
+	  lll_mutex_lock(cond->__data.__lock);
 
-	  /* The error value.  */
-	  result = ETIMEDOUT;
-	  break;
+	  goto timeout;
 	}
 
-      /* Prepare to wait.  Release the condvar futex.  */
-      lll_mutex_unlock (cond->__data.__lock);
-
       /* Enable asynchronous cancellation.  Required by the standard.  */
       cbuffer.oldtype = __pthread_enable_asynccancel ();
 
@@ -170,8 +168,9 @@ __pthread_cond_timedwait (cond, mutex, abstime)
 	break;
 
       /* Not woken yet.  Maybe the time expired?  */
-      if (err == -ETIMEDOUT)
+      if (__builtin_expect (err == -ETIMEDOUT, 0))
 	{
+	timeout:
 	  /* Yep.  Adjust the counters.  */
 	  ++cond->__data.__wakeup_seq;