about summary refs log tree commit diff
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2003-05-01 23:19:51 +0000
committerUlrich Drepper <drepper@redhat.com>2003-05-01 23:19:51 +0000
commit9a7178d611c8a9b2089cbd8288b623ec3e86da3f (patch)
treeb33e5f3f63e777a1939eebcf23ee7351043861a8
parentcf20f569ae3e9c1893a45b58f5181ed336ca1c4d (diff)
downloadglibc-9a7178d611c8a9b2089cbd8288b623ec3e86da3f.tar.gz
glibc-9a7178d611c8a9b2089cbd8288b623ec3e86da3f.tar.xz
glibc-9a7178d611c8a9b2089cbd8288b623ec3e86da3f.zip
Update.
2003-05-01  Ulrich Drepper  <drepper@redhat.com>

	* sysdeps/i386/tls.h: Define THREAD_ID.
	* sysdeps/ia64/tls.h: Likewise.
	* sysdeps/powerpc/tls.h: Likewise.
	* sysdeps/s390/tls.h: Likewise.
	* sysdeps/sh/tls.h: Likewise.
	* sysdeps/x86_64/tls.h: Likewise.
	* pthread_mutex_lock.c: Use THREAD_ID instead of THREAD_SELF to
	record ownership.
	* pthread_mutex_timedlock.c: Likewise.
	* pthread_mutex_trylock.c: Likewise.
	* pthread_mutex_unlock.c: Likewise.
	* pthread_rwlock_trywrlock.c: Likewise.
	* sysdeps/pthread/pthread_rwlocklock_rdlock.c: Likewise.
	* sysdeps/pthread/pthread_rwlock_timedrdlock.c: Likewise.
	* sysdeps/pthread/pthread_rwlock_timedwrlock.c: Likewise.
	* sysdeps/pthread/pthread_rwlock_wrlock.c: Likewise.

	* sysdeps/pthread/createthread.c (create_thread): Use CLONE_SYSVSEM
	flag.
-rw-r--r--nptl/ChangeLog22
-rw-r--r--nptl/pthread_mutex_lock.c10
-rw-r--r--nptl/pthread_mutex_timedlock.c10
-rw-r--r--nptl/pthread_mutex_trylock.c8
-rw-r--r--nptl/pthread_mutex_unlock.c11
-rw-r--r--nptl/pthread_rwlock_trywrlock.c4
-rw-r--r--nptl/sysdeps/i386/tls.h4
-rw-r--r--nptl/sysdeps/ia64/tls.h4
-rw-r--r--nptl/sysdeps/powerpc/tls.h4
-rw-r--r--nptl/sysdeps/pthread/createthread.c8
-rw-r--r--nptl/sysdeps/pthread/pthread_rwlock_rdlock.c2
-rw-r--r--nptl/sysdeps/pthread/pthread_rwlock_timedrdlock.c2
-rw-r--r--nptl/sysdeps/pthread/pthread_rwlock_timedwrlock.c4
-rw-r--r--nptl/sysdeps/pthread/pthread_rwlock_wrlock.c4
-rw-r--r--nptl/sysdeps/s390/tls.h4
-rw-r--r--nptl/sysdeps/sh/tls.h7
-rw-r--r--nptl/sysdeps/x86_64/tls.h4
17 files changed, 81 insertions, 31 deletions
diff --git a/nptl/ChangeLog b/nptl/ChangeLog
index e627616dcf..777e61e5e0 100644
--- a/nptl/ChangeLog
+++ b/nptl/ChangeLog
@@ -1,3 +1,25 @@
+2003-05-01  Ulrich Drepper  <drepper@redhat.com>
+
+	* sysdeps/i386/tls.h: Define THREAD_ID.
+	* sysdeps/ia64/tls.h: Likewise.
+	* sysdeps/powerpc/tls.h: Likewise.
+	* sysdeps/s390/tls.h: Likewise.
+	* sysdeps/sh/tls.h: Likewise.
+	* sysdeps/x86_64/tls.h: Likewise.
+	* pthread_mutex_lock.c: Use THREAD_ID instead of THREAD_SELF to
+	record ownership.
+	* pthread_mutex_timedlock.c: Likewise.
+	* pthread_mutex_trylock.c: Likewise.
+	* pthread_mutex_unlock.c: Likewise.
+	* pthread_rwlock_trywrlock.c: Likewise.
+	* sysdeps/pthread/pthread_rwlocklock_rdlock.c: Likewise.
+	* sysdeps/pthread/pthread_rwlock_timedrdlock.c: Likewise.
+	* sysdeps/pthread/pthread_rwlock_timedwrlock.c: Likewise.
+	* sysdeps/pthread/pthread_rwlock_wrlock.c: Likewise.
+
+	* sysdeps/pthread/createthread.c (create_thread): Use CLONE_SYSVSEM
+	flag.
+
 2003-04-29  Jakub Jelinek  <jakub@redhat.com>
 
 	* sysdeps/unix/sysv/linux/x86_64/bits/pthreadtypes.h
diff --git a/nptl/pthread_mutex_lock.c b/nptl/pthread_mutex_lock.c
index 5040232cf0..f70445acfc 100644
--- a/nptl/pthread_mutex_lock.c
+++ b/nptl/pthread_mutex_lock.c
@@ -26,14 +26,14 @@ int
 __pthread_mutex_lock (mutex)
      pthread_mutex_t *mutex;
 {
-  struct pthread *pd = THREAD_SELF;
+  struct pthread *id = THREAD_ID;
 
   switch (__builtin_expect (mutex->__data.__kind, PTHREAD_MUTEX_TIMED_NP))
     {
       /* Recursive mutex.  */
     case PTHREAD_MUTEX_RECURSIVE_NP:
       /* Check whether we already hold the mutex.  */
-      if (mutex->__data.__owner == pd)
+      if (mutex->__data.__owner == id)
 	{
 	  /* Just bump the counter.  */
 	  if (__builtin_expect (mutex->__data.__count + 1 == 0, 0))
@@ -48,7 +48,7 @@ __pthread_mutex_lock (mutex)
 	  lll_mutex_lock (mutex->__data.__lock);
 
 	  /* Record the ownership.  */
-	  mutex->__data.__owner = pd;
+	  mutex->__data.__owner = id;
 	  mutex->__data.__count = 1;
 	}
       break;
@@ -56,7 +56,7 @@ __pthread_mutex_lock (mutex)
       /* Error checking mutex.  */
     case PTHREAD_MUTEX_ERRORCHECK_NP:
       /* Check whether we already hold the mutex.  */
-      if (mutex->__data.__owner == pd)
+      if (mutex->__data.__owner == id)
 	return EDEADLK;
 
       /* FALLTHROUGH */
@@ -68,7 +68,7 @@ __pthread_mutex_lock (mutex)
       /* Normal mutex.  */
       lll_mutex_lock (mutex->__data.__lock);
       /* Record the ownership.  */
-      mutex->__data.__owner = pd;
+      mutex->__data.__owner = id;
       break;
     }
 
diff --git a/nptl/pthread_mutex_timedlock.c b/nptl/pthread_mutex_timedlock.c
index a63b2048db..f24f91dd3c 100644
--- a/nptl/pthread_mutex_timedlock.c
+++ b/nptl/pthread_mutex_timedlock.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2002 Free Software Foundation, Inc.
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
 
@@ -27,7 +27,7 @@ pthread_mutex_timedlock (mutex, abstime)
      pthread_mutex_t *mutex;
      const struct timespec *abstime;
 {
-  struct pthread *pd = THREAD_SELF;
+  struct pthread *id = THREAD_ID;
   int result = 0;
 
   /* We must not check ABSTIME here.  If the thread does not block
@@ -38,7 +38,7 @@ pthread_mutex_timedlock (mutex, abstime)
       /* Recursive mutex.  */
     case PTHREAD_MUTEX_RECURSIVE_NP:
       /* Check whether we already hold the mutex.  */
-      if (mutex->__data.__owner == pd)
+      if (mutex->__data.__owner == id)
 	{
 	  /* Just bump the counter.  */
 	  if (__builtin_expect (mutex->__data.__count + 1 == 0, 0))
@@ -65,7 +65,7 @@ pthread_mutex_timedlock (mutex, abstime)
       /* Error checking mutex.  */
     case PTHREAD_MUTEX_ERRORCHECK_NP:
       /* Check whether we already hold the mutex.  */
-      if (mutex->__data.__owner == pd)
+      if (mutex->__data.__owner == id)
 	return EDEADLK;
 
       /* FALLTHROUGH */
@@ -81,7 +81,7 @@ pthread_mutex_timedlock (mutex, abstime)
 
   if (result == 0)
     /* Record the ownership.  */
-    mutex->__data.__owner = pd;
+    mutex->__data.__owner = id;
 
  out:
   return result;
diff --git a/nptl/pthread_mutex_trylock.c b/nptl/pthread_mutex_trylock.c
index 394a9cba9b..c61d7d5852 100644
--- a/nptl/pthread_mutex_trylock.c
+++ b/nptl/pthread_mutex_trylock.c
@@ -26,14 +26,14 @@ int
 __pthread_mutex_trylock (mutex)
      pthread_mutex_t *mutex;
 {
-  struct pthread *pd = THREAD_SELF;
+  struct pthread *id = THREAD_ID;
 
   switch (__builtin_expect (mutex->__data.__kind, PTHREAD_MUTEX_TIMED_NP))
     {
       /* Recursive mutex.  */
     case PTHREAD_MUTEX_RECURSIVE_NP:
       /* Check whether we already hold the mutex.  */
-      if (mutex->__data.__owner == pd)
+      if (mutex->__data.__owner == id)
 	{
 	  /* Just bump the counter.  */
 	  if (__builtin_expect (mutex->__data.__count + 1 == 0, 0))
@@ -47,7 +47,7 @@ __pthread_mutex_trylock (mutex)
       if (lll_mutex_trylock (mutex->__data.__lock) == 0)
 	{
 	  /* Record the ownership.  */
-	  mutex->__data.__owner = pd;
+	  mutex->__data.__owner = id;
 	  mutex->__data.__count = 1;
 	  return 0;
 	}
@@ -63,7 +63,7 @@ __pthread_mutex_trylock (mutex)
       if (lll_mutex_trylock (mutex->__data.__lock) == 0)
 	{
 	  /* Record the ownership.  */
-	  mutex->__data.__owner = pd;
+	  mutex->__data.__owner = id;
 
 	  return 0;
 	}
diff --git a/nptl/pthread_mutex_unlock.c b/nptl/pthread_mutex_unlock.c
index 3595585a84..975127d2b2 100644
--- a/nptl/pthread_mutex_unlock.c
+++ b/nptl/pthread_mutex_unlock.c
@@ -30,23 +30,19 @@ __pthread_mutex_unlock (mutex)
     {
     case PTHREAD_MUTEX_RECURSIVE_NP:
       /* Recursive mutex.  */
-      if (mutex->__data.__owner != THREAD_SELF)
+      if (mutex->__data.__owner != THREAD_ID)
 	return EPERM;
 
       if (--mutex->__data.__count != 0)
 	/* We still hold the mutex.  */
 	return 0;
-
-      mutex->__data.__owner = NULL;
       break;
 
     case PTHREAD_MUTEX_ERRORCHECK_NP:
       /* Error checking mutex.  */
-      if (mutex->__data.__owner != THREAD_SELF
+      if (mutex->__data.__owner != THREAD_ID
 	  || ! lll_mutex_islocked (mutex->__data.__lock))
 	return EPERM;
-
-      mutex->__data.__owner = NULL;
       break;
 
     default:
@@ -57,6 +53,9 @@ __pthread_mutex_unlock (mutex)
       break;
     }
 
+  /* Always reset the owner field.  */
+  mutex->__data.__owner = NULL;
+
   /* Unlock.  */
   lll_mutex_unlock (mutex->__data.__lock);
 
diff --git a/nptl/pthread_rwlock_trywrlock.c b/nptl/pthread_rwlock_trywrlock.c
index 32fcbba8c5..755af37330 100644
--- a/nptl/pthread_rwlock_trywrlock.c
+++ b/nptl/pthread_rwlock_trywrlock.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2002 Free Software Foundation, Inc.
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
 
@@ -32,7 +32,7 @@ __pthread_rwlock_trywrlock (rwlock)
 
   if (rwlock->__data.__writer == 0 && rwlock->__data.__nr_readers == 0)
     {
-      rwlock->__data.__writer = (pthread_t) THREAD_SELF;
+      rwlock->__data.__writer = (pthread_t) THREAD_ID;
       result = 0;
     }
 
diff --git a/nptl/sysdeps/i386/tls.h b/nptl/sysdeps/i386/tls.h
index 7ee2bcac19..03757bb4c7 100644
--- a/nptl/sysdeps/i386/tls.h
+++ b/nptl/sysdeps/i386/tls.h
@@ -251,6 +251,10 @@ union user_desc_init
 	  : "i" (offsetof (struct pthread, header.self)));			      \
      __self;})
 
+/* Identifier for the current thread.  THREAD_SELF is usable but
+   sometimes more expensive than necessary.  It is fine here.  */
+# define THREAD_ID THREAD_SELF
+
 
 /* Read member of the thread descriptor directly.  */
 # define THREAD_GETMEM(descr, member) \
diff --git a/nptl/sysdeps/ia64/tls.h b/nptl/sysdeps/ia64/tls.h
index 8a13a59d30..5ce74737a7 100644
--- a/nptl/sysdeps/ia64/tls.h
+++ b/nptl/sysdeps/ia64/tls.h
@@ -113,6 +113,10 @@ register struct pthread *__thread_self __asm__("r13");
 /* Return the thread descriptor for the current thread.  */
 # define THREAD_SELF (__thread_self - 1)
 
+/* Identifier for the current thread.  THREAD_SELF is usable but
+   sometimes more expensive than necessary as in this case.  */
+# define THREAD_ID __thread_self
+
 /* Access to data in the thread descriptor is easy.  */
 #define THREAD_GETMEM(descr, member) \
   descr->member
diff --git a/nptl/sysdeps/powerpc/tls.h b/nptl/sysdeps/powerpc/tls.h
index 6573bb6b04..70aff09e24 100644
--- a/nptl/sysdeps/powerpc/tls.h
+++ b/nptl/sysdeps/powerpc/tls.h
@@ -129,6 +129,10 @@ register void *__thread_register __asm__ ("r13");
     ((struct pthread *) (__thread_register \
 			 - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE))
 
+/* Identifier for the current thread.  THREAD_SELF is usable but
+   sometimes more expensive than necessary as in this case.  */
+# define THREAD_ID __thread_register
+
 /* Read member of the thread descriptor directly.  */
 # define THREAD_GETMEM(descr, member) ((void)(descr), (THREAD_SELF)->member)
 
diff --git a/nptl/sysdeps/pthread/createthread.c b/nptl/sysdeps/pthread/createthread.c
index 9d00e4e135..ea1213896e 100644
--- a/nptl/sysdeps/pthread/createthread.c
+++ b/nptl/sysdeps/pthread/createthread.c
@@ -78,8 +78,9 @@ create_thread (struct pthread *pd, STACK_VARIABLES_PARMS)
 	  if (ARCH_CLONE (start_thread_debug, STACK_VARIABLES_ARGS,
 			  CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGNAL |
 			  CLONE_SETTLS | CLONE_PARENT_SETTID |
-			  CLONE_CHILD_CLEARTID | CLONE_DETACHED | 0,
-			  pd, &pd->tid, TLS_VALUE, &pd->tid) == -1)
+			  CLONE_CHILD_CLEARTID | CLONE_DETACHED |
+			  CLONE_SYSVSEM | 0, pd, &pd->tid, TLS_VALUE,
+			  &pd->tid) == -1)
 	    /* Failed.  */
 	    return errno;
 
@@ -151,7 +152,8 @@ create_thread (struct pthread *pd, STACK_VARIABLES_PARMS)
   if (ARCH_CLONE (start_thread, STACK_VARIABLES_ARGS,
 		  CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGNAL |
 		  CLONE_SETTLS | CLONE_PARENT_SETTID | CLONE_CHILD_CLEARTID |
-		  CLONE_DETACHED | 0, pd, &pd->tid, TLS_VALUE, &pd->tid) == -1)
+		  CLONE_DETACHED | CLONE_SYSVSEM | 0, pd, &pd->tid, TLS_VALUE,
+		  &pd->tid) == -1)
     /* Failed.  */
     return errno;
 
diff --git a/nptl/sysdeps/pthread/pthread_rwlock_rdlock.c b/nptl/sysdeps/pthread/pthread_rwlock_rdlock.c
index 197af9c970..7fb93df1de 100644
--- a/nptl/sysdeps/pthread/pthread_rwlock_rdlock.c
+++ b/nptl/sysdeps/pthread/pthread_rwlock_rdlock.c
@@ -57,7 +57,7 @@ __pthread_rwlock_rdlock (rwlock)
 	 a deadlock situation we recognize and report.  */
       if (rwlock->__data.__writer != 0
 	  && __builtin_expect (rwlock->__data.__writer
-			       == (pthread_t) THREAD_SELF, 0))
+			       == (pthread_t) THREAD_ID, 0))
 	{
 	  result = EDEADLK;
 	  break;
diff --git a/nptl/sysdeps/pthread/pthread_rwlock_timedrdlock.c b/nptl/sysdeps/pthread/pthread_rwlock_timedrdlock.c
index 9c1815570f..d5a75ba3b2 100644
--- a/nptl/sysdeps/pthread/pthread_rwlock_timedrdlock.c
+++ b/nptl/sysdeps/pthread/pthread_rwlock_timedrdlock.c
@@ -60,7 +60,7 @@ pthread_rwlock_timedrdlock (rwlock, abstime)
 	 a deadlock situation we recognize and report.  */
       if (rwlock->__data.__writer != 0
 	  && __builtin_expect (rwlock->__data.__writer
-			       == (pthread_t) THREAD_SELF, 0))
+			       == (pthread_t) THREAD_ID, 0))
 	{
 	  result = EDEADLK;
 	  break;
diff --git a/nptl/sysdeps/pthread/pthread_rwlock_timedwrlock.c b/nptl/sysdeps/pthread/pthread_rwlock_timedwrlock.c
index e4d08ea657..52308aff91 100644
--- a/nptl/sysdeps/pthread/pthread_rwlock_timedwrlock.c
+++ b/nptl/sysdeps/pthread/pthread_rwlock_timedwrlock.c
@@ -43,7 +43,7 @@ pthread_rwlock_timedwrlock (rwlock, abstime)
       if (rwlock->__data.__writer == 0 && rwlock->__data.__nr_readers == 0)
 	{
 	  /* Mark self as writer.  */
-	  rwlock->__data.__writer = (pthread_t) THREAD_SELF;
+	  rwlock->__data.__writer = (pthread_t) THREAD_ID;
 	  break;
 	}
 
@@ -51,7 +51,7 @@ pthread_rwlock_timedwrlock (rwlock, abstime)
 	 a deadlock situation we recognize and report.  */
       if (rwlock->__data.__writer != 0
 	  && __builtin_expect (rwlock->__data.__writer
-			       == (pthread_t) THREAD_SELF, 0))
+			       == (pthread_t) THREAD_ID, 0))
 	{
 	  result = EDEADLK;
 	  break;
diff --git a/nptl/sysdeps/pthread/pthread_rwlock_wrlock.c b/nptl/sysdeps/pthread/pthread_rwlock_wrlock.c
index 03c37a1933..171a14adb1 100644
--- a/nptl/sysdeps/pthread/pthread_rwlock_wrlock.c
+++ b/nptl/sysdeps/pthread/pthread_rwlock_wrlock.c
@@ -40,7 +40,7 @@ __pthread_rwlock_wrlock (rwlock)
       if (rwlock->__data.__writer == 0 && rwlock->__data.__nr_readers == 0)
 	{
 	  /* Mark self as writer.  */
-	  rwlock->__data.__writer = (pthread_t) THREAD_SELF;
+	  rwlock->__data.__writer = (pthread_t) THREAD_ID;
 	  break;
 	}
 
@@ -48,7 +48,7 @@ __pthread_rwlock_wrlock (rwlock)
 	 a deadlock situation we recognize and report.  */
       if (rwlock->__data.__writer != 0
 	  && __builtin_expect (rwlock->__data.__writer
-			       == (pthread_t) THREAD_SELF, 0))
+			       == (pthread_t) THREAD_ID, 0))
 	{
 	  result = EDEADLK;
 	  break;
diff --git a/nptl/sysdeps/s390/tls.h b/nptl/sysdeps/s390/tls.h
index 06237ae15b..89e51ff228 100644
--- a/nptl/sysdeps/s390/tls.h
+++ b/nptl/sysdeps/s390/tls.h
@@ -137,6 +137,10 @@ typedef struct
 /* Return the thread descriptor for the current thread.  */
 # define THREAD_SELF ((struct pthread *) __builtin_thread_pointer ())
 
+/* Identifier for the current thread.  THREAD_SELF is usable but
+   sometimes more expensive than necessary.  It is fine here.  */
+# define THREAD_ID THREAD_SELF
+
 /* Access to data in the thread descriptor is easy.  */
 #define THREAD_GETMEM(descr, member) \
   descr->member
diff --git a/nptl/sysdeps/sh/tls.h b/nptl/sysdeps/sh/tls.h
index 1e27b987e0..a6cefa0b31 100644
--- a/nptl/sysdeps/sh/tls.h
+++ b/nptl/sysdeps/sh/tls.h
@@ -117,6 +117,13 @@ typedef struct
      __asm ("stc gbr,%0" : "=r" (__self));				      \
      __self - 1;})
 
+/* Identifier for the current thread.  THREAD_SELF is usable but
+   sometimes more expensive than necessary as in this case.  */
+# define THREAD_ID \
+  ({ struct pthread *__self;						      \
+     __asm ("stc gbr,%0" : "=r" (__self));				      \
+     __self;})
+
 /* Read member of the thread descriptor directly.  */
 # define THREAD_GETMEM(descr, member) (descr->member)
 
diff --git a/nptl/sysdeps/x86_64/tls.h b/nptl/sysdeps/x86_64/tls.h
index ab13f25431..074eb64a8c 100644
--- a/nptl/sysdeps/x86_64/tls.h
+++ b/nptl/sysdeps/x86_64/tls.h
@@ -159,6 +159,10 @@ typedef struct
 	  : "i" (offsetof (struct pthread, header.self)));	 	      \
      __self;})
 
+/* Identifier for the current thread.  THREAD_SELF is usable but
+   sometimes more expensive than necessary.  It is fine here.  */
+# define THREAD_ID THREAD_SELF
+
 
 /* Read member of the thread descriptor directly.  */
 # define THREAD_GETMEM(descr, member) \