aboutsummaryrefslogtreecommitdiff
path: root/nptl/pthread_mutex_unlock.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2005-12-27 01:04:06 +0000
committerUlrich Drepper <drepper@redhat.com>2005-12-27 01:04:06 +0000
commit1bcfb5a5eb1c25b64a329c1edf6bcfb440cdbc93 (patch)
treeefa74fd1d0c2f6fccda616328a7b432ffdc6ba92 /nptl/pthread_mutex_unlock.c
parent08f60b258ec9d9a24275831941a6f559eb26580e (diff)
downloadglibc-1bcfb5a5eb1c25b64a329c1edf6bcfb440cdbc93.tar
glibc-1bcfb5a5eb1c25b64a329c1edf6bcfb440cdbc93.tar.gz
glibc-1bcfb5a5eb1c25b64a329c1edf6bcfb440cdbc93.tar.bz2
glibc-1bcfb5a5eb1c25b64a329c1edf6bcfb440cdbc93.zip
* Versions.def: Add GLIBC_2.4 for libpthread.cvs/fedora-glibc-20051227T1426
Diffstat (limited to 'nptl/pthread_mutex_unlock.c')
-rw-r--r--nptl/pthread_mutex_unlock.c50
1 files changed, 49 insertions, 1 deletions
diff --git a/nptl/pthread_mutex_unlock.c b/nptl/pthread_mutex_unlock.c
index 5f097a596d..babce51a6f 100644
--- a/nptl/pthread_mutex_unlock.c
+++ b/nptl/pthread_mutex_unlock.c
@@ -18,6 +18,7 @@
02111-1307 USA. */
#include <errno.h>
+#include <stdlib.h>
#include "pthreadP.h"
#include <lowlevellock.h>
@@ -28,6 +29,8 @@ __pthread_mutex_unlock_usercnt (mutex, decr)
pthread_mutex_t *mutex;
int decr;
{
+ int newowner = 0;
+
switch (__builtin_expect (mutex->__data.__kind, PTHREAD_MUTEX_TIMED_NP))
{
case PTHREAD_MUTEX_RECURSIVE_NP:
@@ -52,13 +55,58 @@ __pthread_mutex_unlock_usercnt (mutex, decr)
/* Normal mutex. Nothing special to do. */
break;
+ case PTHREAD_MUTEX_ROBUST_PRIVATE_RECURSIVE_NP:
+ /* Recursive mutex. */
+ if (mutex->__data.__owner == -THREAD_GETMEM (THREAD_SELF, tid))
+ {
+ if (--mutex->__data.__count != 0)
+ /* We still hold the mutex. */
+ return ENOTRECOVERABLE;
+
+ goto notrecoverable;
+ }
+
+ if (mutex->__data.__owner != THREAD_GETMEM (THREAD_SELF, tid))
+ return EPERM;
+
+ if (--mutex->__data.__count != 0)
+ /* We still hold the mutex. */
+ return 0;
+
+ goto robust;
+
+ case PTHREAD_MUTEX_ROBUST_PRIVATE_ERRORCHECK_NP:
+ /* Error checking mutex. */
+ if (abs (mutex->__data.__owner) != THREAD_GETMEM (THREAD_SELF, tid)
+ || ! lll_mutex_islocked (mutex->__data.__lock))
+ return EPERM;
+
+ /* FALLTHROUGH */
+
+ case PTHREAD_MUTEX_ROBUST_PRIVATE_NP:
+ case PTHREAD_MUTEX_ROBUST_PRIVATE_ADAPTIVE_NP:
+ /* If the previous owner died and the caller did not succeed in
+ making the state consistent, mark the mutex as unrecoverable
+ and make all waiters. */
+ if (__builtin_expect (mutex->__data.__owner
+ == -THREAD_GETMEM (THREAD_SELF, tid)
+ || (mutex->__data.__owner
+ == PTHREAD_MUTEX_NOTRECOVERABLE), 0))
+ notrecoverable:
+ newowner = PTHREAD_MUTEX_NOTRECOVERABLE;
+
+ robust:
+ /* Remove mutex from the list. */
+ DEQUEUE_MUTEX (mutex);
+ break;
+
default:
/* Correct code cannot set any other type. */
return EINVAL;
}
/* Always reset the owner field. */
- mutex->__data.__owner = 0;
+ mutex->__data.__owner = newowner;
if (decr)
/* One less user. */
--mutex->__data.__nusers;