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

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] linuxthreads bits/libc-lock.h fix


Hi!

dlopening libpthread.so in linuxthreads build might result in deadlock
randomly, because most of the __libc_lock* macros used __libc_maybe_call2
macro (and thus __libc_pthread_functions), but __libc_lock_init_recursive
was forgotten and used weak variables directly.
I think it is better to initialize it inline anyway, as done
in the following patch.
Still, e.g. locking some mutex, then dlopening libpthread.so and then
unlocking that mutex might cause problems (but that's something
linuxthreads never handled well). TODO for later.

2003-01-15  Jakub Jelinek  <jakub@redhat.com>

	* sysdeps/pthread/bits/libc-lock.h (__libc_lock_init,
	__libc_lock_init_recursive): Initialize fields directly.

--- libc/linuxthreads/sysdeps/pthread/bits/libc-lock.h.jj	2003-01-03 01:36:33.000000000 +0100
+++ libc/linuxthreads/sysdeps/pthread/bits/libc-lock.h	2003-01-14 23:08:30.000000000 +0100
@@ -116,12 +116,33 @@ typedef pthread_key_t __libc_key_t;
 
 /* Initialize the named lock variable, leaving it in a consistent, unlocked
    state.  */
+#if defined _LIBC && !defined NOT_IN_libc && defined SHARED
+#define __libc_lock_init(NAME) \
+  ({									      \
+    (NAME).__m_count = 0;						      \
+    (NAME).__m_owner = NULL;						      \
+    (NAME).__m_kind = PTHREAD_MUTEX_TIMED_NP;				      \
+    (NAME).__m_lock.__status = 0;					      \
+    (NAME).__m_lock.__spinlock = __LT_SPINLOCK_INIT;			      \
+    0; })
+#else
 #define __libc_lock_init(NAME) \
   (__libc_maybe_call2 (pthread_mutex_init, (&(NAME), NULL), 0))
+#endif
 #define __libc_rwlock_init(NAME) \
   (__libc_maybe_call (__pthread_rwlock_init, (&(NAME), NULL), 0));
 
 /* Same as last but this time we initialize a recursive mutex.  */
+#if defined _LIBC && !defined NOT_IN_libc && defined SHARED
+#define __libc_lock_init_recursive(NAME) \
+  ({									      \
+    (NAME).mutex.__m_count = 0;						      \
+    (NAME).mutex.__m_owner = NULL;					      \
+    (NAME).mutex.__m_kind = PTHREAD_MUTEX_RECURSIVE_NP;			      \
+    (NAME).mutex.__m_lock.__status = 0;					      \
+    (NAME).mutex.__m_lock.__spinlock = __LT_SPINLOCK_INIT;		      \
+    0; })
+#else
 #define __libc_lock_init_recursive(NAME) \
   do {									      \
     if (__pthread_mutex_init != NULL)					      \
@@ -133,6 +154,7 @@ typedef pthread_key_t __libc_key_t;
 	__pthread_mutexattr_destroy (&__attr);				      \
       }									      \
   } while (0);
+#endif
 #define __rtld_lock_init_recursive(NAME) \
   __libc_lock_init_recursive (NAME)
 

	Jakub


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