diff options
author | Ivan Maidanski <ivmai@mail.ru> | 2022-09-30 07:51:42 +0300 |
---|---|---|
committer | Ivan Maidanski <ivmai@mail.ru> | 2022-09-30 07:51:42 +0300 |
commit | 48a01ee1c93817eb1dfc772f77ac4abbd5fa0a56 (patch) | |
tree | 061d35ae13e4fe45ecee815325ec7d13063525cc /darwin_stop_world.c | |
parent | 6a584e0afb6f7ed74d6b8d57b198b65427403d3a (diff) | |
download | bdwgc-48a01ee1c93817eb1dfc772f77ac4abbd5fa0a56.tar.gz |
Consistent naming of GC_thread local variables
(refactoring)
Also, change "while" to "for" statement to iterate over GC_threads.
* darwin_stop_world.c (GC_stack_range_for): Add pfound_me argument;
update comment; set *pfound_me to TRUE if thread is my_thread.
* win32_threads.c (GC_push_stack_for): Likewise.
* darwin_stop_world.c (GC_push_all_stacks): Do not define listcount
local variable if DARWIN_DONT_PARSE_STACK.
* darwin_stop_world.c (GC_push_all_stacks): Pass &found_me to
GC_stack_range_for (instead of setting it to TRUE directly).
* win32_threads.c (GC_push_all_stacks): Likewise.
* darwin_stop_world.c [DARWIN_DONT_PARSE_STACK] (GC_push_all_stacks):
Do not initialize act_list and listcount local variables.
* pthread_stop_world.c [!NACL && !GC_OPENBSD_UTHREADS
&& THREAD_SANITIZER] (GC_lookup_thread_async): Change while statement
to for one.
* pthread_support.c [DEBUG_THREADS] (GC_count_threads): Likewise.
* pthread_support.c (GC_lookup_thread): Likewise.
* win32_threads.c (GC_lookup_thread_inner, GC_delete_thread): Likewise.
* pthread_stop_world.c (GC_push_all_stacks): Define and use is_self
local variable.
* win32_threads.c (GC_push_stack_for): Likewise.
* pthread_support.c [DEBUG_THREADS] (GC_count_threads): Rename th
local variable to p.
* win32_threads.c (GC_Thread_Rep.thread_blocked_sp,
GC_lookup_pthread): Refine comment.
* win32_threads.c (GC_new_thread, GC_delete_thread): Rename id
argument to thread_id.
* win32_threads.c (GC_lookup_pthread): Remove GC_lookup_pthread label.
* win32_threads.c (GC_lookup_thread_inner): Reformat comment.
* win32_threads.c [!GC_NO_THREADS_DISCOVERY] (GC_lookup_thread_inner):
Define and use t local variable.
* win32_threads.c (GC_stop_world, GC_start_world, GC_push_all_stacks,
GC_get_next_stack): Rename t to p local variable.
* win32_threads.c [!GC_NO_THREADS_DISCOVERY] (GC_stop_world): Change
type of t local from GC_vthread to GC_thread.
Diffstat (limited to 'darwin_stop_world.c')
-rw-r--r-- | darwin_stop_world.c | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/darwin_stop_world.c b/darwin_stop_world.c index b27a7627..91f9109a 100644 --- a/darwin_stop_world.c +++ b/darwin_stop_world.c @@ -136,19 +136,21 @@ GC_API void GC_CALL GC_use_threads_discovery(void) #endif /* Evaluates the stack range for a given thread. Returns the lower */ -/* bound and sets *phi to the upper one. */ +/* bound and sets *phi to the upper one. Sets *pfound_me to TRUE if */ +/* this is current thread, otherwise the value is not changed. */ STATIC ptr_t GC_stack_range_for(ptr_t *phi, thread_act_t thread, GC_thread p, mach_port_t my_thread, ptr_t *paltstack_lo, - ptr_t *paltstack_hi) + ptr_t *paltstack_hi, GC_bool *pfound_me) { ptr_t lo; + if (thread == my_thread) { GC_ASSERT(NULL == p || (p -> flags & DO_BLOCKING) == 0); lo = GC_approx_sp(); # ifndef DARWIN_DONT_PARSE_STACK *phi = GC_FindTopOfStack(0); # endif - + *pfound_me = TRUE; } else if (p != NULL && (p -> flags & DO_BLOCKING) != 0) { lo = p->stop_info.stack_ptr; # ifndef DARWIN_DONT_PARSE_STACK @@ -352,7 +354,6 @@ GC_INNER void GC_push_all_stacks(void) GC_bool found_me = FALSE; int nthreads = 0; word total_size = 0; - mach_msg_type_number_t listcount = (mach_msg_type_number_t)THREAD_TABLE_SZ; GC_ASSERT(I_HOLD_LOCK()); GC_ASSERT(GC_thr_initialized); @@ -361,7 +362,8 @@ GC_INNER void GC_push_all_stacks(void) if (GC_query_task_threads) { int i; kern_return_t kern_result; - thread_act_array_t act_list = 0; + thread_act_array_t act_list; + mach_msg_type_number_t listcount; /* Obtain the list of the threads from the kernel. */ kern_result = task_threads(my_task, &act_list, &listcount); @@ -371,7 +373,7 @@ GC_INNER void GC_push_all_stacks(void) for (i = 0; i < (int)listcount; i++) { thread_act_t thread = act_list[i]; ptr_t lo = GC_stack_range_for(&hi, thread, NULL, my_thread, - &altstack_lo, &altstack_hi); + &altstack_lo, &altstack_hi, &found_me); if (lo) { GC_ASSERT((word)lo <= (word)hi); @@ -380,8 +382,6 @@ GC_INNER void GC_push_all_stacks(void) } /* TODO: Handle altstack */ nthreads++; - if (thread == my_thread) - found_me = TRUE; mach_port_deallocate(my_task, thread); } /* for (i=0; ...) */ @@ -392,14 +392,14 @@ GC_INNER void GC_push_all_stacks(void) /* else */ { int i; - for (i = 0; i < (int)listcount; i++) { + for (i = 0; i < THREAD_TABLE_SZ; i++) { GC_thread p; - for (p = GC_threads[i]; p != NULL; p = p->next) - if ((p->flags & FINISHED) == 0) { + for (p = GC_threads[i]; p != NULL; p = p -> next) + if ((p -> flags & FINISHED) == 0) { thread_act_t thread = (thread_act_t)p->stop_info.mach_thread; ptr_t lo = GC_stack_range_for(&hi, thread, p, my_thread, - &altstack_lo, &altstack_hi); + &altstack_lo, &altstack_hi, &found_me); if (lo) { GC_ASSERT((word)lo <= (word)hi); @@ -411,8 +411,6 @@ GC_INNER void GC_push_all_stacks(void) GC_push_all_stack(altstack_lo, altstack_hi); } nthreads++; - if (thread == my_thread) - found_me = TRUE; } } /* for (i=0; ...) */ } @@ -620,7 +618,7 @@ GC_INNER void GC_stop_world(void) for (i = 0; i < THREAD_TABLE_SZ; i++) { GC_thread p; - for (p = GC_threads[i]; p != NULL; p = p->next) { + for (p = GC_threads[i]; p != NULL; p = p -> next) { if ((p -> flags & (FINISHED | DO_BLOCKING)) == 0 && p -> stop_info.mach_thread != my_thread) { GC_acquire_dirty_lock(); @@ -755,7 +753,8 @@ GC_INNER void GC_start_world(void) for (i = 0; i < THREAD_TABLE_SZ; i++) { GC_thread p; - for (p = GC_threads[i]; p != NULL; p = p->next) { + + for (p = GC_threads[i]; p != NULL; p = p -> next) { if ((p -> flags & (FINISHED | DO_BLOCKING)) == 0 && p -> stop_info.mach_thread != my_thread) GC_thread_resume(p->stop_info.mach_thread); |