summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJamey Sharp <jamey@minilop.net>2006-11-21 22:01:39 -0800
committerJamey Sharp <jamey@minilop.net>2006-11-21 22:01:39 -0800
commit5d98a6e665f62127a884fdc5534163ece807aba1 (patch)
tree8778e62f90237e984a1f1bde0821c223e32a0ad6
Library that provides pthread stubs that are missing from your platform libc.
-rw-r--r--.gitignore31
-rw-r--r--COPYING21
-rw-r--r--Makefile.am7
-rwxr-xr-xautogen.sh3
-rw-r--r--configure.ac40
-rw-r--r--pthread-stubs.pc.in8
-rw-r--r--stubs.c141
7 files changed, 251 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..9e32f24
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,31 @@
+.deps
+aclocal.m4
+autom4te.cache
+compile
+depcomp
+install-sh
+libtool
+ltmain.sh
+missing
+mkinstalldirs
+config.guess
+config.h
+config.h.in
+config.log
+config.status
+config.sub
+configure
+configure.lineno
+.deps
+.dirstamp
+.libs
+*.lo
+*.loT
+*.la
+Makefile
+Makefile.in
+stamp-h1
+*.o
+*.pc
+*.tar.bz2
+*.tar.gz
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..00a238e
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,21 @@
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the "Software"),
+to deal in the Software without restriction, including without limitation
+the rights to use, copy, modify, merge, publish, distribute, sublicense,
+and/or sell copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the names of the authors or their
+institutions shall not be used in advertising or otherwise to promote the
+sale, use or other dealings in this Software without prior written
+authorization from the authors.
diff --git a/Makefile.am b/Makefile.am
new file mode 100644
index 0000000..e1e1ec8
--- /dev/null
+++ b/Makefile.am
@@ -0,0 +1,7 @@
+pkgconfigdir = $(libdir)/pkgconfig
+pkgconfig_DATA = pthread-stubs.pc
+
+if BUILD_LIB
+lib_LTLIBRARIES = libpthread-stubs.la
+libpthread_stubs_la_SOURCES = stubs.c
+endif
diff --git a/autogen.sh b/autogen.sh
new file mode 100755
index 0000000..d68a142
--- /dev/null
+++ b/autogen.sh
@@ -0,0 +1,3 @@
+#! /bin/sh
+autoreconf -v --install || exit 1
+./configure "$@"
diff --git a/configure.ac b/configure.ac
new file mode 100644
index 0000000..c08f62d
--- /dev/null
+++ b/configure.ac
@@ -0,0 +1,40 @@
+AC_INIT([libpthread-stubs],
+ 0.1,
+ [xcb@lists.freedesktop.org])
+AC_CONFIG_SRCDIR([pthread-stubs.pc.in])
+AM_INIT_AUTOMAKE([foreign dist-bzip2])
+
+AC_CONFIG_HEADERS([config.h])
+
+AC_PROG_LIBTOOL
+AC_PROG_CC
+
+
+dnl Detection code for compilers supporting the __attribute__((weak, alias))
+dnl feature. Original code present in unieject's repository
+dnl Diego Pettenò <flameeyes@gentoo.org>
+ac_save_CFLAGS="$CFLAGS"
+CFLAGS="$CFLAGS -Werror"
+AC_CACHE_CHECK([if compiler supports __attribute__((weak, alias))],
+ [cc_cv_attribute_alias],
+ [AC_COMPILE_IFELSE([
+ void other_function(void *foo) { }
+ void some_function(void *foo) __attribute__((weak, alias("other_function")));
+ ],
+ [cc_cv_attribute_alias=yes],
+ [cc_cv_attribute_alias=no])
+ ])
+CFLAGS="$ac_save_CFLAGS"
+if test "x$cc_cv_attribute_alias" = "xyes"; then
+ AC_DEFINE([SUPPORT_ATTRIBUTE_ALIAS], 1, [Define this if the compiler supports the alias attribute])
+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],
+ [], [PKG_CONFIG_LIBS='-L${libdir} -lpthread-stubs'])
+AC_SUBST([PKG_CONFIG_LIBS])
+AM_CONDITIONAL(BUILD_LIB, test x$PKG_CONFIG_LIBS != x)
+
+AC_CONFIG_FILES([Makefile pthread-stubs.pc])
+AC_OUTPUT
diff --git a/pthread-stubs.pc.in b/pthread-stubs.pc.in
new file mode 100644
index 0000000..6900598
--- /dev/null
+++ b/pthread-stubs.pc.in
@@ -0,0 +1,8 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+
+Name: pthread stubs
+Description: Stubs missing from libc for standard pthread functions
+Version: @PACKAGE_VERSION@
+Libs: @PKG_CONFIG_LIBS@
diff --git a/stubs.c b/stubs.c
new file mode 100644
index 0000000..d267fa6
--- /dev/null
+++ b/stubs.c
@@ -0,0 +1,141 @@
+/* Copyright (C) 2006 Diego Pettenò
+ * Inspired by libX11 code copyright (c) 1995 David E. Wexelblat.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Except as contained in this notice, the names of the authors or their
+ * institutions shall not be used in advertising or otherwise to promote the
+ * sale, use or other dealings in this Software without prior written
+ * authorization from the authors.
+ */
+
+#include <pthread.h>
+#include "config.h"
+
+#ifndef HAVE_PTHREAD_SELF
+#define NEED_ZERO_STUB
+# ifdef SUPPORT_ATTRIBUTE_ALIAS
+int pthread_self() __attribute__ ((weak, alias ("__pthread_zero_stub")));
+# else
+# pragma weak pthread_self = __pthread_zero_stub
+# endif
+#endif
+
+#ifndef HAVE_PTHREAD_MUTEX_INIT
+#define NEED_ZERO_STUB
+# ifdef SUPPORT_ATTRIBUTE_ALIAS
+int pthread_mutex_init() __attribute__ ((weak, alias ("__pthread_zero_stub")));
+# else
+# pragma weak pthread_mutex_init = __pthread_zero_stub
+# endif
+#endif
+
+#ifndef HAVE_PTHREAD_MUTEX_DESTROY
+#define NEED_ZERO_STUB
+# ifdef SUPPORT_ATTRIBUTE_ALIAS
+int pthread_mutex_destroy() __attribute__ ((weak, alias ("__pthread_zero_stub")));
+# else
+# pragma weak pthread_mutex_destroy = __pthread_zero_stub
+# endif
+#endif
+
+#ifndef HAVE_PTHREAD_MUTEX_LOCK
+#define NEED_ZERO_STUB
+# ifdef SUPPORT_ATTRIBUTE_ALIAS
+int pthread_mutex_lock() __attribute__ ((weak, alias ("__pthread_zero_stub")));
+# else
+# pragma weak pthread_mutex_lock = __pthread_zero_stub
+# endif
+#endif
+
+#ifndef HAVE_PTHREAD_MUTEX_UNLOCK
+#define NEED_ZERO_STUB
+# ifdef SUPPORT_ATTRIBUTE_ALIAS
+int pthread_mutex_unlock() __attribute__ ((weak, alias ("__pthread_zero_stub")));
+# else
+# pragma weak pthread_mutex_unlock = __pthread_zero_stub
+# endif
+#endif
+
+#ifndef HAVE_PTHREAD_COND_INIT
+#define NEED_ZERO_STUB
+# ifdef SUPPORT_ATTRIBUTE_ALIAS
+int pthread_cond_init() __attribute__ ((weak, alias ("__pthread_zero_stub")));
+# else
+# pragma weak pthread_cond_init = __pthread_zero_stub
+# endif
+#endif
+
+#ifndef HAVE_PTHREAD_COND_DESTROY
+#define NEED_ZERO_STUB
+# ifdef SUPPORT_ATTRIBUTE_ALIAS
+int pthread_cond_destroy() __attribute__ ((weak, alias ("__pthread_zero_stub")));
+# else
+# pragma weak pthread_cond_destroy = __pthread_zero_stub
+# endif
+#endif
+
+#ifndef HAVE_PTHREAD_COND_WAIT
+#define NEED_ZERO_STUB
+# ifdef SUPPORT_ATTRIBUTE_ALIAS
+int pthread_cond_wait() __attribute__ ((weak, alias ("__pthread_zero_stub")));
+# else
+# pragma weak pthread_cond_wait = __pthread_zero_stub
+# endif
+#endif
+
+#ifndef HAVE_PTHREAD_COND_SIGNAL
+#define NEED_ZERO_STUB
+# ifdef SUPPORT_ATTRIBUTE_ALIAS
+int pthread_cond_signal() __attribute__ ((weak, alias ("__pthread_zero_stub")));
+# else
+# pragma weak pthread_cond_signal = __pthread_zero_stub
+# endif
+#endif
+
+#ifndef HAVE_PTHREAD_COND_BROADCAST
+#define NEED_ZERO_STUB
+# ifdef SUPPORT_ATTRIBUTE_ALIAS
+int pthread_cond_broadcast() __attribute__ ((weak, alias ("__pthread_zero_stub")));
+# else
+# pragma weak pthread_cond_broadcast = __pthread_zero_stub
+# endif
+#endif
+
+#ifndef HAVE_PTHREAD_EQUAL
+#define NEED_EQUAL_STUB
+# ifdef SUPPORT_ATTRIBUTE_ALIAS
+int pthread_equal() __attribute__ ((weak, alias ("__pthread_equal_stub")));
+# else
+# pragma weak pthread_equal = __pthread_equal_stub
+# endif
+#endif
+
+#ifdef NEED_ZERO_STUB
+static int __pthread_zero_stub()
+{
+ return 0;
+}
+#endif
+
+#ifdef NEED_EQUAL_STUB
+static int __pthread_equal_stub(pthread_t t1, pthread_t t2)
+{
+ return (t1 == t2);
+}
+#endif