From 55c48e217fac1f752c19c36895f634beb2ba0dae Mon Sep 17 00:00:00 2001 From: ivmai Date: Tue, 26 Apr 2011 21:09:41 +0000 Subject: [PATCH] 2011-04-26 Ivan Maidanski * .cvsignore (initsecondarythread, test_cpp): Add. * os_dep.c (GC_linux_stack_base): Rename to GC_linux_main_stack_base. * os_dep.c (GC_freebsd_stack_base): Rename to GC_freebsd_main_stack_base; adjust error message. * pthread_stop_world.c (GC_stop_init): Use GC_SEM_INIT_PSHARED as an argument for sem_init(). * pthread_support.c (pthread_create): Ditto. * pthread_support.c (pthread_create): Abort in case sem_init() fails. * include/private/gc_priv.h (GC_SEM_INIT_PSHARED): Define. * tests/initsecondarythread.c: Include gcconfig.h; call GC_INIT from main() if it should be done from the primordial thread only. --- .cvsignore | 2 ++ ChangeLog | 16 ++++++++++++++++ include/private/gc_priv.h | 4 ++++ os_dep.c | 12 +++++------- pthread_stop_world.c | 7 ++++--- pthread_support.c | 4 +++- tests/initsecondarythread.c | 28 ++++++++++++++++++++-------- 7 files changed, 54 insertions(+), 19 deletions(-) diff --git a/.cvsignore b/.cvsignore index d1ce9d2..c064b43 100644 --- a/.cvsignore +++ b/.cvsignore @@ -6,6 +6,7 @@ config.log config.status gctest hugetest +initsecondarythread leaktest libcord.la libgc.la @@ -15,3 +16,4 @@ middletest smashtest staticrootstest threadleaktest +test_cpp diff --git a/ChangeLog b/ChangeLog index a8b064c..250bc36 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,21 @@ 2011-04-26 Ivan Maidanski + * .cvsignore (initsecondarythread, test_cpp): Add. + * os_dep.c (GC_linux_stack_base): Rename to + GC_linux_main_stack_base. + * os_dep.c (GC_freebsd_stack_base): Rename to + GC_freebsd_main_stack_base; adjust error message. + * pthread_stop_world.c (GC_stop_init): Use GC_SEM_INIT_PSHARED + as an argument for sem_init(). + * pthread_support.c (pthread_create): Ditto. + * pthread_support.c (pthread_create): Abort in case sem_init() + fails. + * include/private/gc_priv.h (GC_SEM_INIT_PSHARED): Define. + * tests/initsecondarythread.c: Include gcconfig.h; call GC_INIT + from main() if it should be done from the primordial thread only. + +2011-04-26 Ivan Maidanski + * alloc.c: Don't include sys/types.h for ArmCC. * dyn_load.c: Ditto. * os_dep.c: Ditto. diff --git a/include/private/gc_priv.h b/include/private/gc_priv.h index 9e34c76..2b7113e 100644 --- a/include/private/gc_priv.h +++ b/include/private/gc_priv.h @@ -2097,6 +2097,10 @@ GC_EXTERN signed_word GC_bytes_found; # endif #endif /* GC_PTHREADS && !SIG_SUSPEND */ +#if defined(GC_PTHREADS) && !defined(GC_SEM_INIT_PSHARED) +# define GC_SEM_INIT_PSHARED 0 +#endif + /* Some macros for setjmp that works across signal handlers */ /* were possible, and a couple of routines to facilitate */ /* catching accesses to bad addresses when that's */ diff --git a/os_dep.c b/os_dep.c index a3e7a28..39ca438 100644 --- a/os_dep.c +++ b/os_dep.c @@ -1038,7 +1038,7 @@ GC_INNER word GC_page_size = 0; } # endif /* IA64 */ - STATIC ptr_t GC_linux_stack_base(void) + STATIC ptr_t GC_linux_main_stack_base(void) { /* We read the stack base value from /proc/self/stat. We do this */ /* using direct I/O system calls in order to avoid calling malloc */ @@ -1124,15 +1124,13 @@ GC_INNER word GC_page_size = 0; # include # include - STATIC ptr_t GC_freebsd_stack_base(void) + STATIC ptr_t GC_freebsd_main_stack_base(void) { int nm[2] = {CTL_KERN, KERN_USRSTACK}; ptr_t base; size_t len = sizeof(ptr_t); int r = sysctl(nm, 2, &base, &len, NULL, 0); - - if (r) ABORT("Error getting stack base"); - + if (r) ABORT("Error getting main stack base"); return base; } #endif /* FREEBSD_STACKBOTTOM */ @@ -1192,10 +1190,10 @@ GC_INNER word GC_page_size = 0; # endif # endif /* HEURISTIC1 */ # ifdef LINUX_STACKBOTTOM - result = GC_linux_stack_base(); + result = GC_linux_main_stack_base(); # endif # ifdef FREEBSD_STACKBOTTOM - result = GC_freebsd_stack_base(); + result = GC_freebsd_main_stack_base(); # endif # ifdef HEURISTIC2 # ifdef STACK_GROWS_DOWN diff --git a/pthread_stop_world.c b/pthread_stop_world.c index af0c62e..d7680e4 100644 --- a/pthread_stop_world.c +++ b/pthread_stop_world.c @@ -129,7 +129,8 @@ STATIC volatile AO_t GC_world_is_stopped = FALSE; */ #ifndef SIG_THR_RESTART -# if defined(GC_HPUX_THREADS) || defined(GC_OSF1_THREADS) || defined(GC_NETBSD_THREADS) +# if defined(GC_HPUX_THREADS) || defined(GC_OSF1_THREADS) \ + || defined(GC_NETBSD_THREADS) # ifdef _SIGRTMIN # define SIG_THR_RESTART _SIGRTMIN + 5 # else @@ -794,10 +795,10 @@ GC_INNER void GC_stop_init(void) # if !defined(GC_OPENBSD_THREADS) && !defined(NACL) struct sigaction act; - if (sem_init(&GC_suspend_ack_sem, 0, 0) != 0) + if (sem_init(&GC_suspend_ack_sem, GC_SEM_INIT_PSHARED, 0) != 0) ABORT("sem_init failed"); # ifdef GC_NETBSD_THREADS_WORKAROUND - if (sem_init(&GC_restart_ack_sem, 0, 0) != 0) + if (sem_init(&GC_restart_ack_sem, GC_SEM_INIT_PSHARED, 0) != 0) ABORT("sem_init failed"); # endif diff --git a/pthread_support.c b/pthread_support.c index 2feeac3..575ac9d 100644 --- a/pthread_support.c +++ b/pthread_support.c @@ -1482,7 +1482,9 @@ GC_API int WRAP_FUNC(pthread_create)(pthread_t *new_thread, (si = (struct start_info *) (*GC_get_oom_fn())(sizeof(struct start_info))) == 0) return(ENOMEM); - sem_init(&(si -> registered), 0, 0); + if (sem_init(&(si -> registered), GC_SEM_INIT_PSHARED, 0) != 0) + ABORT("sem_init failed"); + si -> start_routine = start_routine; si -> arg = arg; LOCK(); diff --git a/tests/initsecondarythread.c b/tests/initsecondarythread.c index feed560..f89252e 100644 --- a/tests/initsecondarythread.c +++ b/tests/initsecondarythread.c @@ -28,16 +28,28 @@ static void *thread(void *arg) { - GC_INIT (); - GC_MALLOC (123); - GC_MALLOC (12345); - return NULL; + GC_INIT(); + GC_MALLOC(123); + GC_MALLOC(12345); + return NULL; } +#include "private/gcconfig.h" + int main(void) { - pthread_t t; - pthread_create (&t, NULL, thread, NULL); - pthread_join (t, NULL); - return 0; + pthread_t t; +# if !(defined(BEOS) || defined(MSWIN32) || defined(MSWINCE) \ + || defined(CYGWIN32) || defined(GC_OPENBSD_THREADS) \ + || (defined(DARWIN) && !defined(NO_PTHREAD_GET_STACKADDR_NP)) \ + || (defined(LINUX) && !defined(NACL)) \ + || (defined(GC_SOLARIS_THREADS) && !defined(_STRICT_STDC)) \ + || (!defined(STACKBOTTOM) && (defined(HEURISTIC1) \ + || (!defined(LINUX_STACKBOTTOM) && !defined(FREEBSD_STACKBOTTOM))))) + /* GC_INIT() must be called from main thread only. */ + GC_INIT(); +# endif + pthread_create (&t, NULL, thread, NULL); + pthread_join (t, NULL); + return 0; } -- 2.7.4