[Xcb] [PATCH] Add pthread_setcancelstate

Rémi Denis-Courmont remi at remlab.net
Thu Jan 7 12:36:20 PST 2010


---
 configure.ac |    2 +-
 stubs.c      |   26 ++++++++++++++++++++++++++
 2 files changed, 27 insertions(+), 1 deletions(-)

diff --git a/configure.ac b/configure.ac
index 3a12a1a..a905aab 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_condattr_init pthread_condattr_destroy pthread_cond_wait pthread_cond_timedwait pthread_cond_signal pthread_cond_broadcast pthread_equal pthread_exit],
+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 pthread_setcancelstate],
 	       [], [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 962833d..331f9e9 100644
--- a/stubs.c
+++ b/stubs.c
@@ -26,6 +26,7 @@
 
 #include <pthread.h>
 #include <stdlib.h>
+#include <errno.h>
 #include "config.h"
 
 #ifndef HAVE_PTHREAD_SELF
@@ -163,6 +164,15 @@ void pthread_exit() __attribute__ ((weak, alias ("__pthread_exit_stub")));
 # endif
 #endif
 
+#ifndef HAVE_PTHREAD_SETCANCELSTATE
+#define NEED_SETCANCELSTATE_STUB
+# ifdef SUPPORT_ATTRIBUTE_ALIAS
+int pthread_setcanceltate() __attribute__ ((weak, alias ("__pthread_setcancelstate_stube")));
+# else
+#  pragma weak pthread_setcancelstate = __pthread_setcancelstate_stub
+# endif
+#endif
+
 #ifdef NEED_ZERO_STUB
 static int __pthread_zero_stub()
 {
@@ -190,3 +200,19 @@ static void __pthread_exit_stub(void *ret)
     exit(EXIT_SUCCESS);
 }
 #endif
+
+#ifdef NEED_SETCANCELSTATE_STUB
+static int __pthread_setcancelstate_stub(int new_state, int *old_state)
+{
+    static int cur_state = PTHREAD_CANCEL_ENABLE;
+
+    if (new_state != PTHREAD_CANCEL_ENABLE
+     && new_state != PTHREAD_CANCEL_DISABLE)
+        return EINVAL;
+
+    if (old_state != NULL)
+        *old_state = cur_state;
+    cur_state = new_state;
+    return 0;
+}
+#endif
-- 
1.6.6



More information about the Xcb mailing list