Skip to content

Commit

Permalink
Add jl_inside_heartbeat_thread()
Browse files Browse the repository at this point in the history
To allow `jl_safe_printf()` to determine whether it's being called
from the heartbeat thread.
  • Loading branch information
kpamnany authored and Drvi committed Jun 7, 2024
1 parent 2d97d29 commit 07cb65e
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/threading.c
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,7 @@ JL_DLLEXPORT int jl_alignment(size_t sz)
#include <time.h>

volatile int heartbeat_enabled;
uv_thread_t heartbeat_uvtid;
uv_sem_t heartbeat_on_sem, // jl_heartbeat_enable -> thread
heartbeat_off_sem; // thread -> jl_heartbeat_enable
int heartbeat_interval_s,
Expand All @@ -965,12 +966,17 @@ void jl_heartbeat_threadfun(void *arg);
// start the heartbeat thread with heartbeats disabled
void jl_init_heartbeat(void)
{
uv_thread_t uvtid;
heartbeat_enabled = 0;
uv_sem_init(&heartbeat_on_sem, 0);
uv_sem_init(&heartbeat_off_sem, 0);
uv_thread_create(&uvtid, jl_heartbeat_threadfun, NULL);
uv_thread_detach(&uvtid);
uv_thread_create(&heartbeat_uvtid, jl_heartbeat_threadfun, NULL);
uv_thread_detach(&heartbeat_uvtid);
}

int jl_inside_heartbeat_thread(void)
{
uv_thread_t curr_uvtid = uv_thread_self();
return curr_uvtid == heartbeat_uvtid;
}

// enable/disable heartbeats
Expand Down Expand Up @@ -1143,6 +1149,11 @@ void jl_init_heartbeat(void)
{
}

int jl_inside_heartbeat_thread(void)
{
return 0;
}

JL_DLLEXPORT int jl_heartbeat_enable(int heartbeat_s, int show_tasks_after_n,
int reset_after_n)
{
Expand Down

0 comments on commit 07cb65e

Please sign in to comment.