summaryrefslogtreecommitdiff
path: root/sysdeps/generic/pt-mutex-unlock.c
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps/generic/pt-mutex-unlock.c')
-rw-r--r--sysdeps/generic/pt-mutex-unlock.c42
1 files changed, 34 insertions, 8 deletions
diff --git a/sysdeps/generic/pt-mutex-unlock.c b/sysdeps/generic/pt-mutex-unlock.c
index 2f719d3e..09d70f8f 100644
--- a/sysdeps/generic/pt-mutex-unlock.c
+++ b/sysdeps/generic/pt-mutex-unlock.c
@@ -1,5 +1,5 @@
/* Unlock a mutex. Generic version.
- Copyright (C) 2000,02 Free Software Foundation, Inc.
+ Copyright (C) 2000, 2002, 2008 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -28,15 +28,31 @@ int
__pthread_mutex_unlock (pthread_mutex_t *mutex)
{
struct __pthread *wakeup;
-
+ const struct __pthread_mutexattr *attr = mutex->attr;
+
+ if (attr == __PTHREAD_ERRORCHECK_MUTEXATTR)
+ attr = &__pthread_errorcheck_mutexattr;
+ if (attr == __PTHREAD_RECURSIVE_MUTEXATTR)
+ attr = &__pthread_recursive_mutexattr;
+
__pthread_spin_lock (&mutex->__lock);
- if (mutex->attr)
- switch (mutex->attr->mutex_type)
+ if (! attr || attr->mutex_type == PTHREAD_MUTEX_NORMAL)
+ {
+#if defined(ALWAYS_TRACK_MUTEX_OWNER)
+# ifndef NDEBUG
+ if (_pthread_self ())
+ {
+ assert (mutex->owner);
+ assert (mutex->owner == _pthread_self ());
+ mutex->owner = NULL;
+ }
+# endif
+#endif
+ }
+ else
+ switch (attr->mutex_type)
{
- case PTHREAD_MUTEX_NORMAL:
- break;
-
case PTHREAD_MUTEX_ERRORCHECK:
case PTHREAD_MUTEX_RECURSIVE:
if (mutex->owner != _pthread_self ())
@@ -45,7 +61,7 @@ __pthread_mutex_unlock (pthread_mutex_t *mutex)
return EPERM;
}
- if (mutex->attr->mutex_type == PTHREAD_MUTEX_RECURSIVE)
+ if (attr->mutex_type == PTHREAD_MUTEX_RECURSIVE)
if (--mutex->locks > 0)
{
__pthread_spin_unlock (&mutex->__lock);
@@ -59,6 +75,7 @@ __pthread_mutex_unlock (pthread_mutex_t *mutex)
LOSE;
}
+
if (mutex->__queue == NULL)
{
__pthread_spin_unlock (&mutex->__held);
@@ -69,6 +86,15 @@ __pthread_mutex_unlock (pthread_mutex_t *mutex)
wakeup = mutex->__queue;
__pthread_dequeue (wakeup);
+#ifndef NDEBUG
+# if !defined (ALWAYS_TRACK_MUTEX_OWNER)
+ if (attr && attr->mutex_type != PTHREAD_MUTEX_NORMAL)
+# endif
+ {
+ mutex->owner = wakeup;
+ }
+#endif
+
/* We do not unlock MUTEX->held: we are transferring the ownership
to the thread that we are waking up. */