summaryrefslogtreecommitdiff
path: root/win32_threads.c
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2022-05-11 08:07:05 +0300
committerIvan Maidanski <ivmai@mail.ru>2022-05-11 12:01:20 +0300
commit8f72b3545c60e79b18b9cfc18ff6b72270da653e (patch)
tree7216d509546d8cd1987b6be180ce970e42a6e6e6 /win32_threads.c
parent970cf9d5e32f7023eb9acb082f241593bcc9a5bd (diff)
downloadbdwgc-8f72b3545c60e79b18b9cfc18ff6b72270da653e.tar.gz
Replace comments about GC is held or not with relevant assertions
(refactoring) * alloc.c (GC_default_stop_func): Refine comment about the allocation lock. * alloc.c (GC_finish_collection): Remove comment that the allocation lock is held because the assertion about it already exists. * finalize.c (GC_grow_table, GC_mark_fo, GC_finalize): Likewise. * finalize.c [!GC_MOVE_DISAPPEARING_LINK_NOT_NEEDED] (GC_move_disappearing_link_inner): Likewise. * mark.c (GC_mark_some_inner): Likewise. * mark.c [PARALLEL_MARK] (GC_do_parallel_mark): Likewise. * os_dep.c [OPENBSD && GC_OPENBSD_UTHREADS] (GC_find_limit_openbsd, GC_skip_hole_openbsd): Likewise. * os_dep.c [NEED_FIND_LIMIT || USE_PROC_FOR_LIBRARIES && THREADS] (GC_find_limit_with_bound): Likewise. * os_dep.c (GC_register_data_segments): Likewise. * os_dep.c [MPROTECT_VDB || PROC_VDB || SOFT_VDB] (GC_dirty_init): Likewise. * pthread_stop_world.c (GC_start_world): Likewise. * pthread_support.c (GC_new_thread): Likewise. * thread_local_alloc.c (return_freelists): Likewise. * win32_threads.c (GC_new_thread, GC_lookup_thread_inner, GC_delete_gc_thread_no_free): Likewise. * blacklst.c (GC_promote_black_lists): Remove comment that the allocation lock is held, and add the corresponding assertion to the beginning of the function. * blacklst.c [!PARALLEL_MARK] (GC_add_to_black_list_normal, GC_add_to_black_list_stack): Likewise. * darwin_stop_world.c (GC_stop_world, GC_start_world): Likewise. * mark_rts.c (GC_remove_root_at_pos, GC_remove_roots_inner, GC_exclude_static_roots_inner): Likewise. * pthread_stop_world.c (GC_push_all_stacks, GC_suspend_all): Likewise. * pthread_support.c (GC_check_finalizer_nested): Likewise. * thread_local_alloc.c (GC_destroy_thread_local): Likewise. * win32_threads.c (GC_check_finalizer_nested, GC_push_all_stacks): Likewise. * blacklst.c (GC_is_black_listed): Refine comment about the allocation lock. * darwin_stop_world.c (GC_push_all_stacks): Add assertion that the lock is held on entrance. * gcj_mlc.c (maybe_finalize): Likewise. * malloc.c [THREADS] (GC_free_inner): Likewise. * dyn_load.c (GC_dyld_image_add, GC_dyld_image_remove, GC_init_dyld): Remove comment the allocation lock should not be held, and add the corresponding assertion to the beginning of the function. * finalize.c (GC_invoke_finalizers): Likewise. * mark.c [PARALLEL_MARK] (GC_help_marker): Likewise. * pthread_support.c (GC_init_parallel): Likewise. * win32_threads.c (GC_lookup_pthread, GC_init_parallel): Likewise. * finalize.c (GC_finalize_all): Remove comment that the lock is not held on entrance. * gcj_mlc.c (GC_init_gcj_malloc): Likewise. * typd_mlc.c (GC_add_ext_descriptor): Likewise. * include/gc/javaxfc.h (GC_finalize_all): Add comment the function acquires the allocation lock. * mallocx.c (GC_generic_malloc_many): Adjust comment about GC lock. * new_hblk.c (GC_build_fl): Likewise. * pthread_support.c (GC_new_thread): Move the assertion about the allocation lock closer to the beginning of the function. * win32_threads.c (GC_new_thread): Likewise.
Diffstat (limited to 'win32_threads.c')
-rw-r--r--win32_threads.c29
1 files changed, 14 insertions, 15 deletions
diff --git a/win32_threads.c b/win32_threads.c
index 01929b9a..80b8c637 100644
--- a/win32_threads.c
+++ b/win32_threads.c
@@ -360,19 +360,18 @@ static struct GC_Thread_Rep first_thread;
static GC_bool first_thread_used = FALSE;
/* Add a thread to GC_threads. We assume it wasn't already there. */
-/* Caller holds allocation lock. */
/* Unlike the pthreads version, the id field is set by the caller. */
STATIC GC_thread GC_new_thread(DWORD id)
{
int hv = THREAD_TABLE_INDEX(id);
GC_thread result;
+ GC_ASSERT(I_HOLD_LOCK());
# ifdef DEBUG_THREADS
GC_log_printf("Creating thread 0x%lx\n", (long)id);
if (GC_threads[hv] != NULL)
GC_log_printf("Hash collision at GC_threads[%d]\n", hv);
# endif
- GC_ASSERT(I_HOLD_LOCK());
if (!EXPECT(first_thread_used, TRUE)) {
result = &first_thread;
first_thread_used = TRUE;
@@ -543,8 +542,6 @@ GC_INLINE LONG GC_get_max_thread_index(void)
/* without a lock, but should be called in contexts in which the */
/* requested thread cannot be asynchronously deleted, e.g. from the */
/* thread itself. */
-/* This version assumes that either GC_win32_dll_threads is set, or */
-/* we hold the allocator lock. */
/* Also used (for assertion checking only) from thread_local_alloc.c. */
STATIC GC_thread GC_lookup_thread_inner(DWORD thread_id)
{
@@ -564,9 +561,10 @@ STATIC GC_thread GC_lookup_thread_inner(DWORD thread_id)
} else
# endif
/* else */ {
- GC_thread p = GC_threads[THREAD_TABLE_INDEX(thread_id)];
+ GC_thread p;
GC_ASSERT(I_HOLD_LOCK());
+ p = GC_threads[THREAD_TABLE_INDEX(thread_id)];
while (p != NULL && p -> id != thread_id)
p = p -> tm.next;
return p;
@@ -594,9 +592,11 @@ STATIC GC_thread GC_lookup_thread_inner(DWORD thread_id)
/* GC_check_finalizer_nested() is the same as in pthread_support.c. */
GC_INNER unsigned char *GC_check_finalizer_nested(void)
{
- GC_thread me = GC_lookup_thread_inner(GetCurrentThreadId());
+ GC_thread me;
unsigned nesting_level;
+ GC_ASSERT(I_HOLD_LOCK());
+ me = GC_lookup_thread_inner(GetCurrentThreadId());
CHECK_LOOKUP_MY_THREAD(me);
nesting_level = me->finalizer_nested;
if (nesting_level) {
@@ -677,9 +677,7 @@ GC_API void GC_CALL GC_register_altstack(void *stack GC_ATTR_UNUSED,
/* been notified, then there may be more than one thread */
/* in the table with the same win32 id. */
/* This is OK, but we need a way to delete a specific one. */
-/* Assumes we hold the allocation lock unless */
-/* GC_win32_dll_threads is set. Does not actually free */
-/* GC_thread entry (only unlinks it). */
+/* Does not actually free GC_thread entry, only unlinks it. */
/* If GC_win32_dll_threads is set it should be called from the */
/* thread being deleted. */
STATIC void GC_delete_gc_thread_no_free(GC_vthread t)
@@ -727,8 +725,7 @@ STATIC void GC_delete_gc_thread_no_free(GC_vthread t)
}
/* Delete a thread from GC_threads. We assume it is there. */
-/* (The code intentionally traps if it wasn't.) Assumes we */
-/* hold the allocation lock unless GC_win32_dll_threads is set. */
+/* (The code intentionally traps if it wasn't.) */
/* If GC_win32_dll_threads is set then it should be called from */
/* the thread being deleted. It is also safe to delete the */
/* main thread (unless GC_win32_dll_threads). */
@@ -1068,9 +1065,9 @@ GC_API void * GC_CALL GC_get_my_stackbottom(struct GC_stack_base *sb)
/* We assume that this is only called for pthread ids that */
/* have not yet terminated or are still joinable, and */
/* cannot be concurrently terminated. */
- /* Assumes we do NOT hold the allocation lock. */
STATIC GC_thread GC_lookup_pthread(pthread_t id)
{
+ GC_ASSERT(I_DONT_HOLD_LOCK());
# ifndef GC_NO_THREADS_DISCOVERY
if (GC_win32_dll_threads) {
int i;
@@ -1806,8 +1803,8 @@ STATIC word GC_push_stack_for(GC_thread thread, DWORD me)
return thread->stack_base - sp; /* stack grows down */
}
-/* We hold allocation lock. Should do exactly the right thing if the */
-/* world is stopped. Should not fail if it isn't. */
+/* Should do exactly the right thing if the world is stopped; should */
+/* not fail if it is not. */
GC_INNER void GC_push_all_stacks(void)
{
DWORD thread_id = GetCurrentThreadId();
@@ -1816,6 +1813,8 @@ GC_INNER void GC_push_all_stacks(void)
unsigned nthreads = 0;
# endif
word total_size = 0;
+
+ GC_ASSERT(I_HOLD_LOCK());
# ifndef GC_NO_THREADS_DISCOVERY
if (GC_win32_dll_threads) {
int i;
@@ -3205,7 +3204,6 @@ GC_INNER void GC_thr_init(void)
/* Perform all initializations, including those that */
/* may require allocation. */
-/* Called without allocation lock. */
/* Must be called before a second thread is created. */
GC_INNER void GC_init_parallel(void)
{
@@ -3214,6 +3212,7 @@ GC_INNER void GC_init_parallel(void)
DCL_LOCK_STATE;
# endif
+ GC_ASSERT(I_DONT_HOLD_LOCK());
if (parallel_initialized) return;
parallel_initialized = TRUE;
/* GC_init() calls us back, so set flag first. */