summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Thibault <sthibault@debian.org>2009-10-10 19:49:42 -0700
committerJamey Sharp <jamey@minilop.net>2009-10-10 19:49:42 -0700
commit3d1b1395786d58f34fb2b74c8bcad7c6b71a0578 (patch)
treea879e813d75617d509023cb584bf873bbffa75c9
parent92a29c56c3d8c8b8fee3e35dff168bf1668ad34f (diff)
Add additional pthread_* stubs and abort() on pthread_cond_*wait.
Here is a patch that adds only pthread_condattr_init/destroy, pthread_cond_timedwait, pthread_exit, and makes both cond_*wait abort instead of just returning 0. Jamey Sharp gave rationale for cond_wait aborting: > In hindsight, I'm concerned about the fact that we provide > pthread_cond_wait as a stub returning 0. If it's ever called in a > single-threaded application, that function should probably call abort(). > The real implementation would be guaranteed to hang in that > circumstance, after all. In XCB, we need this to be available as a stub, > but I can prove that it won't be called unless there are really multiple > threads. Further discussion leading to this patch was in the thread here: http://lists.freedesktop.org/archives/xcb/2009-October/005110.html Signed-off-by: Jamey Sharp <jamey@minilop.net>
-rw-r--r--configure.ac2
-rw-r--r--stubs.c57
2 files changed, 55 insertions, 4 deletions
diff --git a/configure.ac b/configure.ac
index 74cd088..df0c322 100644
--- a/configure.ac
+++ b/configure.ac
@@ -31,7 +31,7 @@ fi
PKG_CONFIG_LIBS=
-AC_CHECK_FUNCS([pthread_self pthread_mutex_init pthread_mutex_destroy pthread_mutex_lock pthread_mutex_unlock pthread_cond_init pthread_cond_destroy pthread_cond_wait pthread_cond_signal pthread_cond_broadcast pthread_equal],
+AC_CHECK_FUNCS([pthread_self pthread_mutex_init pthread_mutex_destroy pthread_mutex_lock pthread_mutex_unlock pthread_cond_init pthread_cond_destroy pthread_condattr_init pthread_condattr_destroy pthread_cond_wait pthread_cond_timedwait pthread_cond_signal pthread_cond_broadcast pthread_equal pthread_exit],
[], [PKG_CONFIG_LIBS='-L${libdir} -lpthread-stubs'])
AC_SUBST([PKG_CONFIG_LIBS])
AM_CONDITIONAL(BUILD_LIB, test "x$PKG_CONFIG_LIBS" != x)
diff --git a/stubs.c b/stubs.c
index d267fa6..b63e2d1 100644
--- a/stubs.c
+++ b/stubs.c
@@ -25,6 +25,7 @@
*/
#include <pthread.h>
+#include <stdlib.h>
#include "config.h"
#ifndef HAVE_PTHREAD_SELF
@@ -90,12 +91,39 @@ int pthread_cond_destroy() __attribute__ ((weak, alias ("__pthread_zero_stub")))
# endif
#endif
-#ifndef HAVE_PTHREAD_COND_WAIT
+#ifndef HAVE_PTHREAD_CONDATTR_INIT
+#define NEED_ZERO_STUB
+# ifdef SUPPORT_ATTRIBUTE_ALIAS
+int pthread_condattr_init() __attribute__ ((weak, alias ("__pthread_zero_stub")));
+# else
+# pragma weak pthread_condattr_init = __pthread_zero_stub
+# endif
+#endif
+
+#ifndef HAVE_PTHREAD_CONDATTR_DESTROY
#define NEED_ZERO_STUB
# ifdef SUPPORT_ATTRIBUTE_ALIAS
-int pthread_cond_wait() __attribute__ ((weak, alias ("__pthread_zero_stub")));
+int pthread_condattr_destroy() __attribute__ ((weak, alias ("__pthread_zero_stub")));
+# else
+# pragma weak pthread_condattr_destroy = __pthread_zero_stub
+# endif
+#endif
+
+#ifndef HAVE_PTHREAD_COND_WAIT
+#define NEED_ABORT_STUB
+# ifdef SUPPORT_ATTRIBUTE_ALIAS
+int pthread_cond_wait() __attribute__ ((weak, alias ("__pthread_abort_stub")));
# else
-# pragma weak pthread_cond_wait = __pthread_zero_stub
+# pragma weak pthread_cond_wait = __pthread_abort_stub
+# endif
+#endif
+
+#ifndef HAVE_PTHREAD_COND_TIMEDWAIT
+#define NEED_ABORT_STUB
+# ifdef SUPPORT_ATTRIBUTE_ALIAS
+int pthread_cond_timedwait() __attribute__ ((weak, alias ("__pthread_abort_stub")));
+# else
+# pragma weak pthread_cond_timedwait = __pthread_abort_stub
# endif
#endif
@@ -126,6 +154,15 @@ int pthread_equal() __attribute__ ((weak, alias ("__pthread_equal_stub")));
# endif
#endif
+#ifndef HAVE_PTHREAD_EXIT
+#define NEED_EXIT_STUB
+# ifdef SUPPORT_ATTRIBUTE_ALIAS
+int pthread_exit() __attribute__ ((weak, alias ("__pthread_exit_stub")));
+# else
+# pragma weak pthread_exit = __pthread_exit_stub
+# endif
+#endif
+
#ifdef NEED_ZERO_STUB
static int __pthread_zero_stub()
{
@@ -133,9 +170,23 @@ static int __pthread_zero_stub()
}
#endif
+#ifdef NEED_ABORT_STUB
+static int __pthread_abort_stub()
+{
+ abort();
+}
+#endif
+
#ifdef NEED_EQUAL_STUB
static int __pthread_equal_stub(pthread_t t1, pthread_t t2)
{
return (t1 == t2);
}
#endif
+
+#ifdef NEED_EXIT_STUB
+static void __pthread_exit_stub(void *ret)
+{
+ exit(EXIT_SUCCESS);
+}
+#endif