summaryrefslogtreecommitdiff
path: root/pthread_stop_world.c
diff options
context:
space:
mode:
authorhboehm <hboehm>2008-07-26 02:51:33 +0200
committerIvan Maidanski <ivmai@mail.ru>2011-07-26 19:06:43 +0200
commit68b9f2740e77bfae2b94392140608d952114b199 (patch)
tree492d095c29a2cfc5cbbc4a49b41fa1f5b06bc6ff /pthread_stop_world.c
parent1867d249698c81214418b2cf9752a987abb7b4f2 (diff)
2008-07-25 Hans Boehm <Hans.Boehm@hp.com> (Really mostly Ivan Maidanski)
Ivan's description of the patch follows. Note that a few pieces like the GC_malloc(0) patch, were not applied since an alternate had been previously applied. A few differed stylistically from the rest of the code (mostly casts to void * instead of target type), or were classified as too minor to bother. Note that all of Ivan's static declarations which did not correct outright naming bugs (as a few did), where replaced by STATIC, which is ignored by default. - minor bug fixing (for FreeBSD, for THREAD_LOCAL_ALLOC and for GC_malloc(0)); - addition of missing getter/setter functions for public variables (may be useful if compiled as Win32 DLL); - addition of missing GC_API for some exported functions; - addition of missing "static" declarator for internal functions and variables (where possible); - replacement of all remaining K&R-style definitions with ANSI C ones (__STDC__ macro is not used anymore); - addition of some Win32 macro definitions (that may be missing in the standard headers supplied with a compiler) for GWW_VDB mode; - elimination of most compiler warnings (except for "uninitialized data" warning); - several typos correction; - missing parenthesis addition in macros in some header files of "libatomic_ops" module. My highlights based on reading the patch: * allchblk.c: Remove GC_freehblk_ptr decl. Make free_list_index_of() static. * include/gc.h: Use __int64 on win64, define GC_oom_func, GC_finalizer_notifier_proc, GC_finalizer_notifier_proc, add getter and setters: GC_get_gc_no, GC_get_parallel, GC_set_oom_fn, GC_set_finalize_on_demand, GC_set_java_finalization, GC_set_dont_expand, GC_set_no_dls, GC_set_max_retries, GC_set_dont_precollect, GC_set_finalizer_notifier. Always define GC_win32_free_heap. gc_config_macros.h: Define _REENTRANT after processing GC_THREADS. * include/gc_cpp.h: Improve GC_PLACEMENT_DELETE test, handling of operator new[] for old Windows compilers. * include/gc_inline.h (GC_MALLOC_FAST_GRANS): Add parentheses around arguments. * dbg_mlc.c, malloc.c, misc.c: Add many GC_API specs. * mark.c (GC_mark_and_push_stack): Fix source argument for blacklist printing. * misc.c: Fix log file naming based on environment variable for Windows. Make GC_set_warn_proc and GC_set_free_space_divisor just return current value with 0 argument. Add DONT_USER_USER32_DLL. Add various getters and setters as in gc.h. * os_dep.c: Remove no longer used GC_disable/enable_signals implementations. (GC_get_stack_base): Add pthread_attr_destroy call. No longer set GC_old_bus_handler in DARWIN workaround. * pthread_support.c: GC_register_my_thread must also call GC_init_thread_local.
Diffstat (limited to 'pthread_stop_world.c')
-rw-r--r--pthread_stop_world.c58
1 files changed, 28 insertions, 30 deletions
diff --git a/pthread_stop_world.c b/pthread_stop_world.c
index c542aeb..54ceebf 100644
--- a/pthread_stop_world.c
+++ b/pthread_stop_world.c
@@ -23,7 +23,7 @@
# endif
#endif
-void GC_print_sig_mask()
+void GC_print_sig_mask(void)
{
sigset_t blocked;
int i;
@@ -41,7 +41,7 @@ void GC_print_sig_mask()
/* Remove the signals that we want to allow in thread stopping */
/* handler from a set. */
-void GC_remove_allowed_signals(sigset_t *set)
+STATIC void GC_remove_allowed_signals(sigset_t *set)
{
if (sigdelset(set, SIGINT) != 0
|| sigdelset(set, SIGQUIT) != 0
@@ -113,13 +113,13 @@ sem_t GC_suspend_ack_sem;
sem_t GC_restart_ack_sem;
#endif
-void GC_suspend_handler_inner(ptr_t sig_arg, void *context);
+STATIC void GC_suspend_handler_inner(ptr_t sig_arg, void *context);
#if defined(IA64) || defined(HP_PA) || defined(M68K)
#ifdef SA_SIGINFO
-void GC_suspend_handler(int sig, siginfo_t *info, void *context)
+STATIC void GC_suspend_handler(int sig, siginfo_t *info, void *context)
#else
-void GC_suspend_handler(int sig)
+STATIC void GC_suspend_handler(int sig)
#endif
{
int old_errno = errno;
@@ -130,9 +130,9 @@ void GC_suspend_handler(int sig)
/* We believe that in all other cases the full context is already */
/* in the signal handler frame. */
#ifdef SA_SIGINFO
-void GC_suspend_handler(int sig, siginfo_t *info, void *context)
+STATIC void GC_suspend_handler(int sig, siginfo_t *info, void *context)
#else
-void GC_suspend_handler(int sig)
+STATIC void GC_suspend_handler(int sig)
#endif
{
int old_errno = errno;
@@ -144,18 +144,13 @@ void GC_suspend_handler(int sig)
}
#endif
-void GC_suspend_handler_inner(ptr_t sig_arg, void *context)
+STATIC void GC_suspend_handler_inner(ptr_t sig_arg, void *context)
{
int sig = (int)(word)sig_arg;
int dummy;
pthread_t my_thread = pthread_self();
GC_thread me;
-# ifdef PARALLEL_MARK
- word my_mark_no = GC_mark_no;
- /* Marker can't proceed until we acknowledge. Thus this is */
- /* guaranteed to be the mark_no correspending to our */
- /* suspension, i.e. the marker can't have incremented it yet. */
-# endif
+
AO_t my_stop_count = AO_load(&GC_stop_count);
if (sig != SIG_SUSPEND) ABORT("Bad signal in suspend_handler");
@@ -219,11 +214,8 @@ void GC_suspend_handler_inner(ptr_t sig_arg, void *context)
# endif
}
-void GC_restart_handler(int sig)
+STATIC void GC_restart_handler(int sig)
{
- pthread_t my_thread = pthread_self();
- GC_thread me;
-
if (sig != SIG_THR_RESTART) ABORT("Bad signal in suspend_handler");
# ifdef GC_NETBSD_THREADS_WORKAROUND
@@ -243,6 +235,8 @@ void GC_restart_handler(int sig)
# endif
}
+void GC_thr_init(void);
+
# ifdef IA64
# define IF_IA64(x) x
# else
@@ -250,7 +244,7 @@ void GC_restart_handler(int sig)
# endif
/* We hold allocation lock. Should do exactly the right thing if the */
/* world is stopped. Should not fail if it isn't. */
-void GC_push_all_stacks()
+void GC_push_all_stacks(void)
{
GC_bool found_me = FALSE;
size_t nthreads = 0;
@@ -324,13 +318,15 @@ void GC_push_all_stacks()
/* There seems to be a very rare thread stopping problem. To help us */
/* debug that, we save the ids of the stopping thread. */
+#if DEBUG_THREADS
pthread_t GC_stopping_thread;
int GC_stopping_pid;
+#endif
/* We hold the allocation lock. Suspend all threads that might */
/* still be running. Return the number of suspend signals that */
/* were sent. */
-int GC_suspend_all()
+STATIC int GC_suspend_all(void)
{
int n_live_threads = 0;
int i;
@@ -338,8 +334,10 @@ int GC_suspend_all()
int result;
pthread_t my_thread = pthread_self();
- GC_stopping_thread = my_thread; /* debugging only. */
- GC_stopping_pid = getpid(); /* debugging only. */
+# if DEBUG_THREADS
+ GC_stopping_thread = my_thread;
+ GC_stopping_pid = getpid();
+# endif
for (i = 0; i < THREAD_TABLE_SZ; i++) {
for (p = GC_threads[i]; p != 0; p = p -> next) {
if (!THREAD_EQUAL(p -> id, my_thread)) {
@@ -369,7 +367,7 @@ int GC_suspend_all()
return n_live_threads;
}
-void GC_stop_world()
+void GC_stop_world(void)
{
int i;
int n_live_threads;
@@ -436,15 +434,15 @@ void GC_stop_world()
# ifdef PARALLEL_MARK
GC_release_mark_lock();
# endif
- #if DEBUG_THREADS
+# if DEBUG_THREADS
GC_printf("World stopped from 0x%x\n", (unsigned)pthread_self());
- #endif
- GC_stopping_thread = 0; /* debugging only */
+ GC_stopping_thread = 0;
+# endif
}
/* Caller holds allocation lock, and has held it continuously since */
/* the world stopped. */
-void GC_start_world()
+void GC_start_world(void)
{
pthread_t my_thread = pthread_self();
register int i;
@@ -466,10 +464,10 @@ void GC_start_world()
if (p -> flags & FINISHED) continue;
if (p -> thread_blocked) continue;
n_live_threads++;
- #if DEBUG_THREADS
+# if DEBUG_THREADS
GC_printf("Sending restart signal to 0x%x\n",
(unsigned)(p -> id));
- #endif
+# endif
result = pthread_kill(p -> id, SIG_THR_RESTART);
switch(result) {
@@ -499,7 +497,7 @@ void GC_start_world()
# endif
}
-void GC_stop_init() {
+void GC_stop_init(void) {
struct sigaction act;
if (sem_init(&GC_suspend_ack_sem, 0, 0) != 0)