* m4/ac_pthreads_implementation.m4: New file.
authortwisti <none@none>
Thu, 31 May 2007 23:05:51 +0000 (23:05 +0000)
committertwisti <none@none>
Thu, 31 May 2007 23:05:51 +0000 (23:05 +0000)
* m4/threads.m4 (AC_CHECK_ENABLE_THREADS): Call
AC_CHECK_PTHREADS_IMPLEMENTATION for posix and linux.

* configure.ac (AC_CHECK_HEADERS): Added stdlib.h.
(AC_CHECK_FUNCS): Added confstr, strstr.

* src/vm/signal.c (signal_init) [!PTHREADS_IS_LINUXTHREADS]: Only
block the signals if we are not on LinuxThreads.
(signal_thread): Set state accordingly.

* src/vm/vm.c (vm_create) [!PTHREADS_IS_LINUXTHREADS]: Only start
signal-thread if we are not on LinuxThreads.

configure.ac
m4/ac_pthreads_implementation.m4 [new file with mode: 0644]
m4/threads.m4
src/vm/signal.c
src/vm/vm.c

index 139aff4e00ae8e8a09eb83beee15512f7210f949..932e74ebae6da8cb135fe4fc80489b91b8e530c3 100644 (file)
@@ -22,7 +22,7 @@ dnl along with this program; if not, write to the Free Software
 dnl Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 dnl 02110-1301, USA.
 dnl 
-dnl $Id: configure.ac 7966 2007-05-25 12:41:03Z pm $
+dnl $Id: configure.ac 7996 2007-05-31 23:05:51Z twisti $
 
 dnl Process this file with autoconf to produce a configure script.
 
@@ -215,6 +215,7 @@ AC_HEADER_STDC
 
 dnl keep them alpha-sorted!
 AC_CHECK_HEADERS([fcntl.h])
+AC_CHECK_HEADERS([stdlib.h])
 AC_CHECK_HEADERS([string.h])
 AC_CHECK_HEADERS([time.h])
 AC_CHECK_HEADERS([unistd.h])
@@ -250,6 +251,7 @@ AC_FUNC_MMAP
 
 dnl keep them alpha-sorted!
 AC_CHECK_FUNCS([calloc])
+AC_CHECK_FUNCS([confstr])
 AC_CHECK_FUNCS([getpagesize])
 AC_CHECK_FUNCS([free])
 AC_CHECK_FUNCS([getcwd])
@@ -262,6 +264,7 @@ AC_CHECK_FUNCS([mmap])
 AC_CHECK_FUNCS([mprotect])
 AC_CHECK_FUNCS([scandir])
 AC_CHECK_FUNCS([strdup])
+AC_CHECK_FUNCS([strstr])
 AC_CHECK_FUNCS([time])
 
 
diff --git a/m4/ac_pthreads_implementation.m4 b/m4/ac_pthreads_implementation.m4
new file mode 100644 (file)
index 0000000..c8cf76d
--- /dev/null
@@ -0,0 +1,68 @@
+dnl m4/ac_pthreads_implementation.m4
+dnl
+dnl Copyright (C) 2007 R. Grafl, A. Krall, C. Kruegel,
+dnl C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
+dnl E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
+dnl J. Wenninger, Institut f. Computersprachen - TU Wien
+dnl 
+dnl This file is part of CACAO.
+dnl 
+dnl This program is free software; you can redistribute it and/or
+dnl modify it under the terms of the GNU General Public License as
+dnl published by the Free Software Foundation; either version 2, or (at
+dnl your option) any later version.
+dnl 
+dnl This program is distributed in the hope that it will be useful, but
+dnl WITHOUT ANY WARRANTY; without even the implied warranty of
+dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+dnl General Public License for more details.
+dnl 
+dnl You should have received a copy of the GNU General Public License
+dnl along with this program; if not, write to the Free Software
+dnl Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+dnl 02110-1301, USA.
+dnl 
+dnl $Id: configure.ac 7228 2007-01-19 01:13:48Z edwin $
+
+
+dnl checks if the pthreads implementation is NPTL or LinuxThreads
+
+AC_DEFUN([AC_CHECK_PTHREADS_IMPLEMENTATION],
+[
+  AC_MSG_CHECKING(pthread implementation)
+  AC_TRY_RUN(
+[
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+int main(void)
+{
+  char *pathbuf;
+  size_t n;
+
+  /* _CS_GNU_LIBPTHREAD_VERSION (GNU C library only; since glibc 2.3.2) */
+  /* If the glibc is a pre-2.3.2 version, the compilation fails and we
+     fall back to linuxthreads. */
+
+  n = confstr(_CS_GNU_LIBPTHREAD_VERSION, NULL, (size_t) 0);
+
+  pathbuf = malloc(n);
+  if ((pathbuf = malloc(n)) == NULL) abort();
+  (void) confstr(_CS_GNU_LIBPTHREAD_VERSION, pathbuf, n);
+
+  if (strstr(pathbuf, "linuxthreads") != NULL)
+     return 1;
+
+  return 0;
+}
+],
+[
+  AC_MSG_RESULT(NPTL)
+  AC_DEFINE(PTHREADS_IS_NPTL, 1, [NPTL pthreads implementation])
+],
+[
+  AC_MSG_RESULT(linuxthreads)
+  AC_DEFINE(PTHREADS_IS_LINUXTHREADS, 1, [LinuxThreads pthread implementation])
+])
+])
index 9b2e404a01323f7365115dfc2e653e31a9f56ac8..9dcdf44c6318b91ec2b6347c3dc835125cece04d 100644 (file)
@@ -59,6 +59,13 @@ case "${ENABLE_THREADS}" in
         AC_DEFINE([ENABLE_THREADS], 1, [enable threads])
         AC_CHECK_LIB(pthread, main)
 
+        dnl check for pthread implementation
+        case "${OS_DIR}" in
+            linux )
+                AC_CHECK_PTHREADS_IMPLEMENTATION
+                ;;
+        esac
+
         ARCH_CFLAGS="$ARCH_CFLAGS -D_REENTRANT"
 
         dnl we changed ARCH_CFLAGS, set CFLAGS again
index 9d30609f71e4d7cfffef920b9856f36e3527f2cd..7f9dcbaf08ca48ea06b1580757acacf087611381 100644 (file)
@@ -22,7 +22,7 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: signal.c 7995 2007-05-31 22:45:19Z twisti $
+   $Id: signal.c 7996 2007-05-31 23:05:51Z twisti $
 
 */
 
@@ -92,6 +92,9 @@ bool signal_init(void)
 
        assert(OFFSET(java_bytearray, data) > EXCEPTION_HARDWARE_PATCHER);
 
+#if !defined(PTHREADS_IS_LINUXTHREADS)
+       /* XXX Remove this #ifdef with exact-GC. */
+
        /* Block the following signals (SIGINT for <ctrl>-c, SIGQUIT for
           <ctrl>-\).  We enable them later in signal_thread, but only for
           this thread. */
@@ -109,6 +112,7 @@ bool signal_init(void)
 
        if (sigprocmask(SIG_BLOCK, &mask, NULL) != 0)
                vm_abort("signal_init: sigprocmask failed: %s", strerror(errno));
+#endif
 
 #if defined(ENABLE_GC_BOEHM)
        /* Allocate something so the garbage collector's signal handlers
@@ -201,8 +205,11 @@ bool signal_init(void)
 
 static void signal_thread(void)
 {
-       sigset_t mask;
-       int      sig;
+       threadobject *t;
+       sigset_t      mask;
+       int           sig;
+
+       t = THREADOBJECT;
 
        if (sigemptyset(&mask) != 0)
                vm_abort("signal_thread: sigemptyset failed: %s", strerror(errno));
@@ -223,10 +230,14 @@ static void signal_thread(void)
                   but it seems to make problems with Boehm-GC.  We should
                   revisit this code with our new exact-GC. */
 
+               threads_thread_state_waiting(t);
+
 /*             if (sigwait(&mask, &sig) != 0) */
 /*                     vm_abort("signal_thread: sigwait failed: %s", strerror(errno)); */
                (void) sigwait(&mask, &sig);
 
+               threads_thread_state_runnable(t);
+
                switch (sig) {
                case SIGINT:
                        /* exit the vm properly */
index f4e2c48c4402f67558b65fd7f3b3014fdf1c244d..c4284a05409870bf97cd79d9893b5abdc499fdc8 100644 (file)
@@ -1638,10 +1638,14 @@ bool vm_create(JavaVMInitArgs *vm_args)
        if (!recompile_init())
                vm_abort("vm_create: recompile_init failed");
 
+#if !defined(PTHREADS_IS_LINUXTHREADS)
+       /* XXX Remove this #ifdef with exact-GC. */
+
        /* start the signal handler thread */
 
        if (!signal_start_thread())
                vm_abort("vm_create: signal_start_thread failed");
+#endif
 
        /* finally, start the finalizer thread */