summary refs log tree commit diff
path: root/nptl/pthread_mutex_unlock.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2003-06-22 23:55:27 +0000
committerUlrich Drepper <drepper@redhat.com>2003-06-22 23:55:27 +0000
commit6162364368b2092b2bd7b1ba26366ba9a841787a (patch)
tree484fb1a48e0bed5865f53b53e012475efec09fc5 /nptl/pthread_mutex_unlock.c
parentb758b9cb108f37e65278f4488fad083300022ba7 (diff)
downloadglibc-6162364368b2092b2bd7b1ba26366ba9a841787a.tar.gz
glibc-6162364368b2092b2bd7b1ba26366ba9a841787a.tar.xz
glibc-6162364368b2092b2bd7b1ba26366ba9a841787a.zip
Update.
2003-06-22  Ulrich Drepper  <drepper@redhat.com>

	* pthreadP.h (__pthread_mutex_init_internal): Mark hidden.
	(__pthread_mutex_lock_internal): Likewise.
	(__pthread_mutex_unlock_internal): Likewise.
	(__pthread_mutex_unlock_usercnt): Declare.
	* pthread_mutex_destroy.c: Always fail if used in any way.
	* pthread_mutex_init.c: Update comment.
	* pthread_mutex_lock.c: If NO_INCR is not defined adjust __nusers.
	* pthread_mutex_timedlock.c: Adjust __nusers.
	* pthread_mutex_trylock.c: Adjust __nusers.
	* pthread_mutex_unlock.c: Old code is in __pthread_mutex_unlock_usercnt
	and public interfaces are wrapper with pass additional parameter.
	__pthread_mutex_unlock_usercnt does not adjust __nusers if second
	parameter zero.
	* tst-mutex8.c: New file.
	* Makefile (tests): Add tst-mutex8.
	* sysdeps/pthread/pthread_cond_timedwait.c: Call
	__pthread_mutex_unlock_usercnt.
	* sysdeps/pthread/pthread_cond_wait.c: Likewise.
	* sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S: Likewise.
	* sysdeps/unix/sysv/linux/i386/i486/pthread_cond_wait.S: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S: Likewise.
	* sysdeps/unix/sysv/linux/pthread_mutex_cond_lock.c: Define NO_INCR.
	* sysdeps/unix/sysv/linux/i386/bits/pthreadtypes.h (pthread_mutex_t):
	Add __nusers.
	* sysdeps/unix/sysv/linux/ia64/bits/pthreadtypes.h: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/bits/pthreadtypes.h: Likewise.
	* sysdeps/unix/sysv/linux/s390/bits/pthreadtypes.h: Likewise.
	* sysdeps/unix/sysv/linux/sh/bits/pthreadtypes.h: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/bits/pthreadtypes.h: Likewise.

	* pthread_mutex_lock.c: Don't store THREAD_ID in __owner, use TID.
	* pthread_mutex_timedlock.c: Likewise.
	* pthread_mutex_trylock.c: Adjust __nusers.
	* pthread_mutex_unlock.c: Compare with TID not THREAD_ID.
	* tst-mutex9.c: New file.
	* Makefile (tests): Add tst-mutex9.
	* sysdeps/i386/tls.h: Remove THREAD_ID definition.
	* 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.
	* sysdeps/unix/sysv/linux/i386/bits/pthreadtypes.h (pthread_mutex_t):
	Change type of __owner.
	* sysdeps/unix/sysv/linux/ia64/bits/pthreadtypes.h: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/bits/pthreadtypes.h: Likewise.
	* sysdeps/unix/sysv/linux/s390/bits/pthreadtypes.h: Likewise.
	* sysdeps/unix/sysv/linux/sh/bits/pthreadtypes.h: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/bits/pthreadtypes.h: Likewise.
Diffstat (limited to 'nptl/pthread_mutex_unlock.c')
-rw-r--r--nptl/pthread_mutex_unlock.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/nptl/pthread_mutex_unlock.c b/nptl/pthread_mutex_unlock.c
index 975127d2b2..56b1cd4a9a 100644
--- a/nptl/pthread_mutex_unlock.c
+++ b/nptl/pthread_mutex_unlock.c
@@ -23,14 +23,16 @@
 
 
 int
-__pthread_mutex_unlock (mutex)
+internal_function
+__pthread_mutex_unlock_usercnt (mutex, decr)
      pthread_mutex_t *mutex;
+     bool decr;
 {
   switch (__builtin_expect (mutex->__data.__kind, PTHREAD_MUTEX_TIMED_NP))
     {
     case PTHREAD_MUTEX_RECURSIVE_NP:
       /* Recursive mutex.  */
-      if (mutex->__data.__owner != THREAD_ID)
+      if (mutex->__data.__owner != THREAD_GETMEM (THREAD_SELF, tid))
 	return EPERM;
 
       if (--mutex->__data.__count != 0)
@@ -40,7 +42,7 @@ __pthread_mutex_unlock (mutex)
 
     case PTHREAD_MUTEX_ERRORCHECK_NP:
       /* Error checking mutex.  */
-      if (mutex->__data.__owner != THREAD_ID
+      if (mutex->__data.__owner != THREAD_GETMEM (THREAD_SELF, tid)
 	  || ! lll_mutex_islocked (mutex->__data.__lock))
 	return EPERM;
       break;
@@ -54,12 +56,23 @@ __pthread_mutex_unlock (mutex)
     }
 
   /* Always reset the owner field.  */
-  mutex->__data.__owner = NULL;
+  mutex->__data.__owner = 0;
+  if (decr)
+    /* One less user.  */
+    --mutex->__data.__nusers;
 
   /* Unlock.  */
   lll_mutex_unlock (mutex->__data.__lock);
 
   return 0;
 }
+
+
+int
+__pthread_mutex_unlock (mutex)
+     pthread_mutex_t *mutex;
+{
+  return __pthread_mutex_unlock_usercnt (mutex, true);
+}
 strong_alias (__pthread_mutex_unlock, pthread_mutex_unlock)
 strong_alias (__pthread_mutex_unlock, __pthread_mutex_unlock_internal)