problem when pthread_* functions are invoked from dynamiclibrary

Mike Frysinger vapier at gentoo.org
Tue Dec 6 01:24:17 UTC 2005


On Mon, Dec 05, 2005 at 10:07:40AM +0100, Joakim Tjernlund wrote:
> looks good, but a few minor changes should be made:
> extern int weak pthread_mutex_init();
> int hidden __pthread_mutex_init() {
>  	if (pthread_mutex_init == NULL)
>  		return 0;
>  	pthread_mutex_init();
>  }
> 
> Then the __ versions in linuxthreads should be made hidden. That way we
> wont export any __ functions and it will match glibc better.

done, attached ... this one should be usuable with latest svn ...
-mike
-------------- next part --------------
Index: libc/misc/pthread/weaks.c
===================================================================
--- libc/misc/pthread/weaks.c	(revision 12672)
+++ libc/misc/pthread/weaks.c	(working copy)
@@ -21,7 +21,10 @@
 #include <errno.h>
 #include <limits.h>
 #include <stdlib.h>
+#include <features.h>
 
+#ifdef __UCLIBC_HAS_THREADS__
+
 /**********************************************************************/
 /* Weaks for application/library use.
  *
@@ -43,10 +46,26 @@
  * and which I left in for documentation.
  */
 
+#define FORWARD2(name, rettype, decl, params, defaction) \
+extern rettype weak_function name decl; \
+rettype attribute_hidden \
+__##name decl \
+{ \
+	if (name == NULL) \
+		defaction; \
+	return name params; \
+}
+#define FORWARD(name, decl, params, defretval) \
+	FORWARD2(name, int, decl, params, return defretval)
+#define FORWARD0(name, decl, params) FORWARD(name, decl, params, 0)
+#define FORWARD1(name, decl, params) FORWARD(name, decl, params, 1)
+
+
+
+/*
 static int __pthread_return_0 __P ((void));
 static int __pthread_return_0 (void) { return 0; }
 
-/*
 weak_alias (__pthread_return_0, pthread_attr_destroy)
 weak_alias (__pthread_return_0, pthread_attr_getdetachstate)
 weak_alias (__pthread_return_0, pthread_attr_getinheritsched)
@@ -111,11 +130,26 @@
 }
 */
 
+
 /**********************************************************************/
 /* Weaks used internally by the C library. */
-weak_alias (__pthread_return_0, __pthread_mutex_init)
-weak_alias (__pthread_return_0, __pthread_mutex_lock)
-weak_alias (__pthread_return_0, __pthread_mutex_trylock)
-weak_alias (__pthread_return_0, __pthread_mutex_unlock)
 
+FORWARD0(pthread_mutex_init,
+        (pthread_mutex_t *mutex, const pthread_mutexattr_t *mutexattr),
+        (mutex, mutexattr))
+
+FORWARD0(pthread_mutex_lock,
+        (pthread_mutex_t *mutex),
+        (mutex))
+
+FORWARD0(pthread_mutex_trylock,
+        (pthread_mutex_t *mutex),
+        (mutex))
+
+FORWARD0(pthread_mutex_unlock,
+        (pthread_mutex_t *mutex),
+        (mutex))
+
 /**********************************************************************/
+
+#endif /* __UCLIBC_HAS_THREADS__ */
Index: libc/sysdeps/linux/common/bits/uClibc_pthread.h
===================================================================
--- libc/sysdeps/linux/common/bits/uClibc_pthread.h	(revision 12672)
+++ libc/sysdeps/linux/common/bits/uClibc_pthread.h	(working copy)
@@ -24,17 +24,14 @@
 #define _UCLIBC_PTHREAD_H
 
 #ifndef _PTHREAD_H
-#error Always include <pthread.h> rather than <bits/uClibc_pthread.h>
+# error "Always include <pthread.h> rather than <bits/uClibc_pthread.h>"
 #endif
 
 extern int __pthread_mutex_init (pthread_mutex_t *__restrict __mutex,
 								 __const pthread_mutexattr_t *__restrict
-								 __mutex_attr) __THROW;
+								 __mutex_attr) attribute_hidden;
+extern int __pthread_mutex_trylock (pthread_mutex_t *__mutex) attribute_hidden;
+extern int __pthread_mutex_lock (pthread_mutex_t *__mutex) attribute_hidden;
+extern int __pthread_mutex_unlock (pthread_mutex_t *__mutex) attribute_hidden;
 
-extern int __pthread_mutex_trylock (pthread_mutex_t *__mutex) __THROW;
-
-extern int __pthread_mutex_lock (pthread_mutex_t *__mutex) __THROW;
-
-extern int __pthread_mutex_unlock (pthread_mutex_t *__mutex) __THROW;
-
 #endif


More information about the uClibc mailing list