Skip to content

Commit 7530fce

Browse files
committed
Merge pull request #14408 from JuliaLang/yyc/jl_-thread
Make jl_ thread safe
2 parents 97443cd + abac887 commit 7530fce

File tree

5 files changed

+7
-5
lines changed

5 files changed

+7
-5
lines changed

src/builtins.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,18 +1642,17 @@ JL_DLLEXPORT size_t jl_static_show_func_sig(JL_STREAM *s, jl_value_t *type)
16421642
return n;
16431643
}
16441644

1645-
int in_jl_ = 0;
16461645
JL_DLLEXPORT void jl_(void *jl_value)
16471646
{
1648-
in_jl_++;
1647+
jl_in_jl_++;
16491648
JL_TRY {
16501649
(void)jl_static_show((JL_STREAM*)STDERR_FILENO, (jl_value_t*)jl_value);
16511650
jl_printf((JL_STREAM*)STDERR_FILENO,"\n");
16521651
}
16531652
JL_CATCH {
16541653
jl_printf((JL_STREAM*)STDERR_FILENO, "\n!!! ERROR in jl_ -- ABORTING !!!\n");
16551654
}
1656-
in_jl_--;
1655+
jl_in_jl_--;
16571656
}
16581657

16591658
JL_DLLEXPORT void jl_breakpoint(jl_value_t *v)

src/jl_uv.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,8 @@ JL_DLLEXPORT int jl_fs_chmod(char *path, int mode)
308308
JL_DLLEXPORT int jl_fs_write(int handle, const char *data, size_t len,
309309
int64_t offset)
310310
{
311+
if (jl_in_jl_)
312+
return write(handle, data, len);
311313
uv_fs_t req;
312314
uv_buf_t buf[1];
313315
buf[0].base = (char*)data;

src/julia.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,6 +1420,7 @@ typedef struct _jl_tls_states_t {
14201420
void *stackbase;
14211421
jl_jmp_buf *volatile jmp_target;
14221422
jl_jmp_buf base_ctx; // base context of stack
1423+
int8_t in_jl_;
14231424
int16_t tid;
14241425
size_t bt_size;
14251426
ptrint_t bt_data[JL_MAX_BT_SIZE + 1];

src/julia_internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ extern jl_function_t *jl_typeinf_func;
1717
#if defined(JL_USE_INTEL_JITEVENTS)
1818
extern unsigned sig_stack_size;
1919
#endif
20+
#define jl_in_jl_ jl_get_ptls_states()->in_jl_
2021

2122
JL_DLLEXPORT extern int jl_lineno;
2223
JL_DLLEXPORT extern const char *jl_filename;

src/signals-unix.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,12 @@ void sigdie_handler(int sig, siginfo_t *info, void *context)
7070
#include <signals-mach.c>
7171
#else
7272

73-
extern int in_jl_;
7473
static void segv_handler(int sig, siginfo_t *info, void *context)
7574
{
7675
sigset_t sset;
7776
assert(sig == SIGSEGV);
7877

79-
if (in_jl_ || is_addr_on_stack(info->si_addr)) { // stack overflow, or restarting jl_
78+
if (jl_in_jl_ || is_addr_on_stack(info->si_addr)) { // stack overflow, or restarting jl_
8079
sigemptyset(&sset);
8180
sigaddset(&sset, SIGSEGV);
8281
sigprocmask(SIG_UNBLOCK, &sset, NULL);

0 commit comments

Comments
 (0)