summaryrefslogtreecommitdiff
path: root/pthread_support.c
diff options
context:
space:
mode:
authorivmai <ivmai>2011-01-07 10:51:40 +0100
committerIvan Maidanski <ivmai@mail.ru>2011-07-26 19:06:55 +0200
commitb8246c8e27304fdb00a8ef5461d2e40dc21f70c3 (patch)
treefafcaf7afdd6fdb3064c832b1e4bdc0cda6bb4a9 /pthread_support.c
parentbddc75fb8c2e9f59797c9f6fd25aaed3b1778fd8 (diff)
2011-01-07 Ivan Maidanski <ivmai@mail.ru>
* .cvsignore: Add more auto-generated files. * include/private/.cvsignore: Ditto. * darwin_stop_world.c (GC_mach_handler_thread, GC_use_mach_handler_thread, GC_darwin_register_mach_handler_thread): Define only if MPROTECT_VDB. * darwin_stop_world.c (GC_suspend_thread_list): Use GC_mach_handler_thread and GC_use_mach_handler_thread only if MPROTECT_VDB. * darwin_stop_world.c (GC_stop_world): Reset GC_mach_threads_count only if defined (i.e. unless GC_NO_THREADS_DISCOVERY). * misc.c (GC_init): Fix comment for GWW_VDB. * os_dep.c (GC_mprotect_state_t): Reformat the code. * os_dep.c (DARWIN_EXC_STATE, DARWIN_EXC_STATE_COUNT, DARWIN_EXC_STATE_T, DARWIN_EXC_STATE_DAR): New macros. * os_dep.c (catch_exception_raise): Use DARWIN_EXC_STATE, DARWIN_EXC_STATE_COUNT, DARWIN_EXC_STATE_T, DARWIN_EXC_STATE_DAR; reformat the comment. * pthread_support.c (GC_thr_init): Define "dummy" local variable only unless GC_DARWIN_THREADS; reformat the code. * include/private/gcconfig.h (MPROTECT_VDB): Define for Darwin even in the single-threaded mode; define for iPhone/iPad. * include/private/gcconfig.h (IA64): Remove unnecessary "ifdef" around "undef". * include/private/gcconfig.h (HEURISTIC1): Remove unused for Cygwin. * include/private/gcconfig.h (STACKBOTTOM): Use fixed address for Darwin/arm (instead of HEURISTIC1). * include/private/gcconfig.h (GET_MEM): Reformat the code.
Diffstat (limited to 'pthread_support.c')
-rw-r--r--pthread_support.c205
1 files changed, 103 insertions, 102 deletions
diff --git a/pthread_support.c b/pthread_support.c
index 26460a7..37e5d95 100644
--- a/pthread_support.c
+++ b/pthread_support.c
@@ -856,119 +856,120 @@ STATIC void GC_fork_child_proc(void)
/* We hold the allocation lock. */
GC_INNER void GC_thr_init(void)
{
+# ifndef GC_DARWIN_THREADS
int dummy;
+# endif
+ if (GC_thr_initialized) return;
+ GC_thr_initialized = TRUE;
- if (GC_thr_initialized) return;
- GC_thr_initialized = TRUE;
-
-# ifdef HANDLE_FORK
- /* Prepare for a possible fork. */
- pthread_atfork(GC_fork_prepare_proc, GC_fork_parent_proc,
- GC_fork_child_proc);
-# endif /* HANDLE_FORK */
-# if defined(INCLUDE_LINUX_THREAD_DESCR)
- /* Explicitly register the region including the address */
- /* of a thread local variable. This should include thread */
- /* locals for the main thread, except for those allocated */
- /* in response to dlopen calls. */
- {
- ptr_t thread_local_addr = (ptr_t)(&GC_dummy_thread_local);
- ptr_t main_thread_start, main_thread_end;
- if (!GC_enclosing_mapping(thread_local_addr, &main_thread_start,
- &main_thread_end)) {
- ABORT("Failed to find mapping for main thread thread locals");
- }
- GC_add_roots_inner(main_thread_start, main_thread_end, FALSE);
- }
-# endif
- /* Add the initial thread, so we can stop it. */
+# ifdef HANDLE_FORK
+ /* Prepare for a possible fork. */
+ pthread_atfork(GC_fork_prepare_proc, GC_fork_parent_proc,
+ GC_fork_child_proc);
+# endif
+# ifdef INCLUDE_LINUX_THREAD_DESCR
+ /* Explicitly register the region including the address */
+ /* of a thread local variable. This should include thread */
+ /* locals for the main thread, except for those allocated */
+ /* in response to dlopen calls. */
{
- GC_thread t = GC_new_thread(pthread_self());
-# ifdef GC_DARWIN_THREADS
- t -> stop_info.mach_thread = mach_thread_self();
-# else
- t -> stop_info.stack_ptr = (ptr_t)(&dummy);
-# endif
- t -> flags = DETACHED | MAIN_THREAD;
+ ptr_t thread_local_addr = (ptr_t)(&GC_dummy_thread_local);
+ ptr_t main_thread_start, main_thread_end;
+ if (!GC_enclosing_mapping(thread_local_addr, &main_thread_start,
+ &main_thread_end)) {
+ ABORT("Failed to find mapping for main thread thread locals");
+ }
+ GC_add_roots_inner(main_thread_start, main_thread_end, FALSE);
}
-
-# ifndef GC_DARWIN_THREADS
- GC_stop_init();
+# endif
+ /* Add the initial thread, so we can stop it. */
+ {
+ GC_thread t = GC_new_thread(pthread_self());
+# ifdef GC_DARWIN_THREADS
+ t -> stop_info.mach_thread = mach_thread_self();
+# else
+ t -> stop_info.stack_ptr = (ptr_t)(&dummy);
# endif
+ t -> flags = DETACHED | MAIN_THREAD;
+ }
- /* Set GC_nprocs. */
- {
- char * nprocs_string = GETENV("GC_NPROCS");
- GC_nprocs = -1;
- if (nprocs_string != NULL) GC_nprocs = atoi(nprocs_string);
- }
- if (GC_nprocs <= 0) {
-# if defined(GC_HPUX_THREADS)
- GC_nprocs = pthread_num_processors_np();
-# endif
-# if defined(GC_OSF1_THREADS) || defined(GC_AIX_THREADS) \
- || defined(GC_SOLARIS_THREADS) || defined(GC_GNU_THREADS)
- GC_nprocs = sysconf(_SC_NPROCESSORS_ONLN);
- if (GC_nprocs <= 0) GC_nprocs = 1;
-# endif
-# if defined(GC_IRIX_THREADS)
- GC_nprocs = sysconf(_SC_NPROC_ONLN);
- if (GC_nprocs <= 0) GC_nprocs = 1;
-# endif
-# if defined(GC_DARWIN_THREADS) || defined(GC_FREEBSD_THREADS) \
- || defined(GC_NETBSD_THREADS) || defined(GC_OPENBSD_THREADS)
- GC_nprocs = get_ncpu();
-# endif
-# if defined(GC_LINUX_THREADS) || defined(GC_DGUX386_THREADS)
- GC_nprocs = GC_get_nprocs();
-# endif
- }
- if (GC_nprocs <= 0) {
- WARN("GC_get_nprocs() returned %" GC_PRIdPTR "\n", GC_nprocs);
- GC_nprocs = 2;
-# ifdef PARALLEL_MARK
- GC_markers = 1;
-# endif
- } else {
-# ifdef PARALLEL_MARK
- {
- char * markers_string = GETENV("GC_MARKERS");
- if (markers_string != NULL) {
- GC_markers = atoi(markers_string);
- if (GC_markers > MAX_MARKERS) {
- WARN("Limiting number of mark threads\n", 0);
- GC_markers = MAX_MARKERS;
- }
- } else {
- GC_markers = GC_nprocs;
- if (GC_markers >= MAX_MARKERS)
- GC_markers = MAX_MARKERS; /* silently limit GC_markers value */
- }
- }
-# endif
- }
+# ifndef GC_DARWIN_THREADS
+ GC_stop_init();
+# endif
+
+ /* Set GC_nprocs. */
+ {
+ char * nprocs_string = GETENV("GC_NPROCS");
+ GC_nprocs = -1;
+ if (nprocs_string != NULL) GC_nprocs = atoi(nprocs_string);
+ }
+ if (GC_nprocs <= 0) {
+# if defined(GC_HPUX_THREADS)
+ GC_nprocs = pthread_num_processors_np();
+# endif
+# if defined(GC_OSF1_THREADS) || defined(GC_AIX_THREADS) \
+ || defined(GC_SOLARIS_THREADS) || defined(GC_GNU_THREADS)
+ GC_nprocs = sysconf(_SC_NPROCESSORS_ONLN);
+ if (GC_nprocs <= 0) GC_nprocs = 1;
+# endif
+# if defined(GC_IRIX_THREADS)
+ GC_nprocs = sysconf(_SC_NPROC_ONLN);
+ if (GC_nprocs <= 0) GC_nprocs = 1;
+# endif
+# if defined(GC_DARWIN_THREADS) || defined(GC_FREEBSD_THREADS) \
+ || defined(GC_NETBSD_THREADS) || defined(GC_OPENBSD_THREADS)
+ GC_nprocs = get_ncpu();
+# endif
+# if defined(GC_LINUX_THREADS) || defined(GC_DGUX386_THREADS)
+ GC_nprocs = GC_get_nprocs();
+# endif
+ }
+ if (GC_nprocs <= 0) {
+ WARN("GC_get_nprocs() returned %" GC_PRIdPTR "\n", GC_nprocs);
+ GC_nprocs = 2;
# ifdef PARALLEL_MARK
+ GC_markers = 1;
+# endif
+ } else {
+# ifdef PARALLEL_MARK
+ {
+ char * markers_string = GETENV("GC_MARKERS");
+ if (markers_string != NULL) {
+ GC_markers = atoi(markers_string);
+ if (GC_markers > MAX_MARKERS) {
+ WARN("Limiting number of mark threads\n", 0);
+ GC_markers = MAX_MARKERS;
+ }
+ } else {
+ GC_markers = GC_nprocs;
+ if (GC_markers >= MAX_MARKERS)
+ GC_markers = MAX_MARKERS; /* silently limit GC_markers value */
+ }
+ }
+# endif
+ }
+# ifdef PARALLEL_MARK
+ if (GC_print_stats) {
+ GC_log_printf("Number of processors = %ld, "
+ "number of marker threads = %ld\n", GC_nprocs, GC_markers);
+ }
+ if (GC_markers <= 1) {
+ GC_parallel = FALSE;
if (GC_print_stats) {
- GC_log_printf("Number of processors = %ld, "
- "number of marker threads = %ld\n", GC_nprocs, GC_markers);
- }
- if (GC_markers <= 1) {
- GC_parallel = FALSE;
- if (GC_print_stats) {
- GC_log_printf(
- "Single marker thread, turning off parallel marking\n");
- }
- } else {
- GC_parallel = TRUE;
- /* Disable true incremental collection, but generational is OK. */
- GC_time_limit = GC_TIME_UNLIMITED;
+ GC_log_printf("Single marker thread, turning off parallel marking\n");
}
- /* If we are using a parallel marker, actually start helper threads. */
- if (GC_parallel) start_mark_threads();
-# endif
+ } else {
+ GC_parallel = TRUE;
+ /* Disable true incremental collection, but generational is OK. */
+ GC_time_limit = GC_TIME_UNLIMITED;
+ }
+ /* If we are using a parallel marker, actually start helper threads. */
+ if (GC_parallel) {
+ start_mark_threads();
+ }
+# endif
}
-
/* Perform all initializations, including those that */
/* may require allocation. */
/* Called without allocation lock. */