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 9da122e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,14 @@ NOINLINE uintptr_t gc_get_stack_ptr(void)

#define should_timeout() 0

uv_thread_t safepoint_waiter;

int jl_inside_waiting_for_the_world(void)
{
uv_thread_t self = uv_thread_self();
return uv_thread_equal(&safepoint_waiter, &self);
}

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 +242,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 Expand Up @@ -263,6 +272,7 @@ void jl_gc_wait_for_the_world(jl_ptls_t* gc_all_tls_states, int gc_n_threads)
}
}
}
memset(&safepoint_waiter, 0, sizeof(safepoint_waiter));
}

// malloc wrappers, aligned allocation
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 int jl_inside_waiting_for_the_world(void);

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() || jl_inside_waiting_for_the_world())) {
write_to_safe_crash_log(buf);
}
if (write(STDERR_FILENO, buf, strlen(buf)) < 0) {
Expand Down

0 comments on commit 9da122e

Please sign in to comment.