From: twisti Date: Thu, 31 May 2007 23:05:51 +0000 (+0000) Subject: * m4/ac_pthreads_implementation.m4: New file. X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=a1ff8a777c32e9412dfed467d4b6a05ff95baf09;p=cacao.git * m4/ac_pthreads_implementation.m4: New file. * 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. --- diff --git a/configure.ac b/configure.ac index 139aff4e0..932e74eba 100644 --- a/configure.ac +++ b/configure.ac @@ -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 index 000000000..c8cf76d62 --- /dev/null +++ b/m4/ac_pthreads_implementation.m4 @@ -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 +#include +#include + +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]) +]) +]) diff --git a/m4/threads.m4 b/m4/threads.m4 index 9b2e404a0..9dcdf44c6 100644 --- a/m4/threads.m4 +++ b/m4/threads.m4 @@ -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 diff --git a/src/vm/signal.c b/src/vm/signal.c index 9d30609f7..7f9dcbaf0 100644 --- a/src/vm/signal.c +++ b/src/vm/signal.c @@ -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 -c, SIGQUIT for -\). 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 */ diff --git a/src/vm/vm.c b/src/vm/vm.c index f4e2c48c4..c4284a054 100644 --- a/src/vm/vm.c +++ b/src/vm/vm.c @@ -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 */