Skip to content

Commit

Permalink
Do not use else-if construction where else part is commented out
Browse files Browse the repository at this point in the history
(refactoring)

Issue #364 (bdwgc).

Otherwise such else-if construction is formatted differently by
different clang-format versions.

* pthread_support.c [CAN_HANDLE_FORK] (GC_setup_atfork): Always follow
commented out "else" with a block (instead of /* else */ if).
* pthread_support.c [GC_PTHREADS] (GC_register_my_thread): Likewise.
* reclaim.c (GC_reclaim_generic): Likewise.
* pthread_support.c [GC_ASSERTIONS && GC_WIN32_THREADS
&& !USE_PTHREAD_LOCKS] (NUMERIC_THREAD_ID): Add extra parentheses
before 2nd cast.
  • Loading branch information
ivmai committed Oct 2, 2024
1 parent 18d1872 commit 2936975
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 26 deletions.
43 changes: 24 additions & 19 deletions pthread_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -1556,8 +1556,10 @@ GC_INNER void GC_wait_for_gc_completion(GC_bool wait_for_all)
GC_handle_fork = 1;
} else
# endif
/* else */ if (GC_handle_fork != -1)
ABORT("pthread_atfork failed");
/* else */ {
if (GC_handle_fork != -1)
ABORT("pthread_atfork failed");
}
}
}

Expand Down Expand Up @@ -2352,24 +2354,26 @@ GC_API int GC_CALL GC_register_my_thread(const struct GC_stack_base *sb)
# endif
} else
# ifdef GC_PTHREADS
/* else */ if (KNOWN_FINISHED(me)) {
/* This code is executed when a thread is registered from the */
/* client thread key destructor. */
# ifdef NACL
GC_nacl_initialize_gc_thread(me);
# endif
# ifdef GC_DARWIN_THREADS
/* Reinitialize mach_thread to avoid thread_suspend fail */
/* with MACH_SEND_INVALID_DEST error. */
me -> mach_thread = mach_thread_self();
# endif
GC_record_stack_base(me -> crtn, sb);
me -> flags &= (unsigned char)~FINISHED; /* but not DETACHED */
} else
# endif
/* else */ {
/* else */ {
if (KNOWN_FINISHED(me)) {
/* This code is executed when a thread is registered from the */
/* client thread key destructor. */
# ifdef NACL
GC_nacl_initialize_gc_thread(me);
# endif
# ifdef GC_DARWIN_THREADS
/* Reinitialize mach_thread to avoid thread_suspend fail */
/* with MACH_SEND_INVALID_DEST error. */
me -> mach_thread = mach_thread_self();
# endif
GC_record_stack_base(me -> crtn, sb);
me -> flags &= (unsigned char)~FINISHED; /* but not DETACHED */
} else
# endif
/* else */ {
UNLOCK();
return GC_DUPLICATE;
}
}

# ifdef THREAD_LOCAL_ALLOC
Expand Down Expand Up @@ -2880,7 +2884,8 @@ GC_API int GC_CALL GC_register_my_thread(const struct GC_stack_base *sb)
# if defined(GC_ASSERTIONS) && defined(GC_WIN32_THREADS) \
&& !defined(USE_PTHREAD_LOCKS)
/* Id is not guaranteed to be unique. */
# define NUMERIC_THREAD_ID(id) (unsigned long)(word)GC_PTHREAD_PTRVAL(id)
# define NUMERIC_THREAD_ID(id) \
(unsigned long)((word)GC_PTHREAD_PTRVAL(id))
# endif

# ifdef GC_ASSERTIONS
Expand Down
16 changes: 9 additions & 7 deletions reclaim.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,13 +312,15 @@ GC_INNER ptr_t GC_reclaim_generic(struct hblk *hbp, hdr *hhdr, size_t sz,
result = GC_disclaim_and_reclaim(hbp, hhdr, sz, list, pcount);
} else
# endif
/* else */ if (init || GC_debugging_started) {
result = GC_reclaim_clear(hbp, hhdr, sz, list, pcount);
} else {
# ifndef AO_HAVE_load
GC_ASSERT(IS_PTRFREE(hhdr));
# endif
result = GC_reclaim_uninit(hbp, hhdr, sz, list, pcount);
/* else */ {
if (init || GC_debugging_started) {
result = GC_reclaim_clear(hbp, hhdr, sz, list, pcount);
} else {
# ifndef AO_HAVE_load
GC_ASSERT(IS_PTRFREE(hhdr));
# endif
result = GC_reclaim_uninit(hbp, hhdr, sz, list, pcount);
}
}
if (IS_UNCOLLECTABLE(hhdr -> hb_obj_kind)) GC_set_hdr_marks(hhdr);
return result;
Expand Down

0 comments on commit 2936975

Please sign in to comment.