2011-04-26 Ivan Maidanski <ivmai@mail.ru>
authorivmai <ivmai>
Tue, 26 Apr 2011 21:09:41 +0000 (21:09 +0000)
committerIvan Maidanski <ivmai@mail.ru>
Tue, 26 Jul 2011 17:06:58 +0000 (21:06 +0400)
* .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
ChangeLog
include/private/gc_priv.h
os_dep.c
pthread_stop_world.c
pthread_support.c
tests/initsecondarythread.c

index d1ce9d2..c064b43 100644 (file)
@@ -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
index a8b064c..250bc36 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,21 @@
 2011-04-26  Ivan Maidanski  <ivmai@mail.ru>
 
+       * .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  <ivmai@mail.ru>
+
        * alloc.c: Don't include sys/types.h for ArmCC.
        * dyn_load.c: Ditto.
        * os_dep.c: Ditto.
index 9e34c76..2b7113e 100644 (file)
@@ -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               */
index a3e7a28..39ca438 100644 (file)
--- 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 <sys/types.h>
 # include <sys/sysctl.h>
 
-  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
index af0c62e..d7680e4 100644 (file)
@@ -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
 
index 2feeac3..575ac9d 100644 (file)
@@ -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();
index feed560..f89252e 100644 (file)
 
 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;
 }