This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Question on when __pthread_lock second parameter shoudl be NULL


On 9 Aug 2000, Juergen Kreileder wrote:

>     Kaz> The problem is that the mutex ownership is being tested for
>     Kaz> all mutex types, even ones that do not record the ownership!
> 
> That is true for the main trunk and was true for glibc-2.1.3 but now
> the glibc-2-1-branch records ownership for fast mutexes.  What was the
> reason for that change?

Ulrich will have to answer that one:

2000-03-16  Ulrich Drepper  <drepper@redhat.com>

        * mutex.c (__pthread_mutex_lock): Always initialize __m_owner.
        (__pthread_mutex_trylock): Likewise.
        (__pthread_mutex_unlock): Always clear __m_owner.

Looks like he was smoothing over bugs elsewhere; i.e. the incorrect checks of
__m_owner that disregard the lock type.  Here is the diff below corresponding
to the above ChangeLog entry.

Ulrich also rolled these changes into the main trunk on the same day. Then he
did one more minor related change on the main trunk, following which he rolled
back the changes, with the comment ``Argh, this was meant only for 2.1''.

===================================================================
RCS file: /cvs/glibc/libc/linuxthreads/mutex.c,v
retrieving revision 1.9.2.1
retrieving revision 1.9.2.2
diff -u -r1.9.2.1 -r1.9.2.2
--- libc/linuxthreads/mutex.c   2000/03/15 07:11:59     1.9.2.1
+++ libc/linuxthreads/mutex.c   2000/03/16 21:29:42     1.9.2.2
@@ -50,6 +50,7 @@
   switch(mutex->__m_kind) {
   case PTHREAD_MUTEX_FAST_NP:
     retcode = __pthread_trylock(&mutex->__m_lock);
+    mutex->__m_owner = thread_self();
     return retcode;
   case PTHREAD_MUTEX_RECURSIVE_NP:
     self = thread_self();
@@ -77,31 +78,29 @@
 
 int __pthread_mutex_lock(pthread_mutex_t * mutex)
 {
-  pthread_descr self;
+  pthread_descr self = thread_self();
 
   switch(mutex->__m_kind) {
   case PTHREAD_MUTEX_FAST_NP:
     __pthread_lock(&mutex->__m_lock, NULL);
-    return 0;
+    break;
   case PTHREAD_MUTEX_RECURSIVE_NP:
-    self = thread_self();
     if (mutex->__m_owner == self) {
       mutex->__m_count++;
       return 0;
     }
     __pthread_lock(&mutex->__m_lock, self);
-    mutex->__m_owner = self;
     mutex->__m_count = 0;
-    return 0;
+    break;
   case PTHREAD_MUTEX_ERRORCHECK_NP:
-    self = thread_self();
     if (mutex->__m_owner == self) return EDEADLK;
     __pthread_lock(&mutex->__m_lock, self);
-    mutex->__m_owner = self;
-    return 0;
+    break;
   default:
     return EINVAL;
   }
+  mutex->__m_owner = self;
+  return 0;
 }
 strong_alias (__pthread_mutex_lock, pthread_mutex_lock)
 
@@ -110,6 +109,7 @@
   switch (mutex->__m_kind) {
   case PTHREAD_MUTEX_FAST_NP:
     __pthread_unlock(&mutex->__m_lock);
+    mutex->__m_owner = NULL;
     return 0;
   case PTHREAD_MUTEX_RECURSIVE_NP:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]