Skip to content

Commit

Permalink
introduce safepoint_waiter
Browse files Browse the repository at this point in the history
  • Loading branch information
d-netto committed Feb 4, 2025
1 parent 1fff8cc commit 2ded1c0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ NOINLINE uintptr_t gc_get_stack_ptr(void)

#define should_timeout() 0

uv_thread_t safepoint_waiter;

void jl_gc_wait_for_the_world(jl_ptls_t* gc_all_tls_states, int gc_n_threads)
{
JL_TIMING(GC, GC_Stop);
Expand All @@ -234,6 +236,7 @@ void jl_gc_wait_for_the_world(jl_ptls_t* gc_all_tls_states, int gc_n_threads)
TracyCZoneColor(ctx, 0x696969);
#endif
assert(gc_n_threads);
safepoint_waiter = uv_thread_self();
if (gc_n_threads > 1)
jl_wake_libuv();
for (int i = 0; i < gc_n_threads; i++) {
Expand Down
3 changes: 2 additions & 1 deletion src/jl_uv.c
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,7 @@ STATIC_INLINE void write_to_safe_crash_log(char *buf) JL_NOTSAFEPOINT
}

extern int jl_inside_heartbeat_thread(void);
extern uv_thread_t safepoint_waiter;

JL_DLLEXPORT void jl_safe_printf(const char *fmt, ...)
{
Expand All @@ -774,7 +775,7 @@ JL_DLLEXPORT void jl_safe_printf(const char *fmt, ...)
// order is important here: we want to ensure that the threading infra
// has been initialized before we start trying to print to the
// safe crash log file
if (jl_sig_fd != 0 && (jl_inside_signal_handler() || jl_inside_heartbeat_thread())) {
if (jl_sig_fd != 0 && (jl_inside_signal_handler() || jl_inside_heartbeat_thread() || safepoint_waiter == uv_thread_self())) {
write_to_safe_crash_log(buf);
}
if (write(STDERR_FILENO, buf, strlen(buf)) < 0) {
Expand Down

0 comments on commit 2ded1c0

Please sign in to comment.