Skip to content

Commit

Permalink
Merge pull request #14408 from JuliaLang/yyc/jl_-thread
Browse files Browse the repository at this point in the history
Make jl_ thread safe
  • Loading branch information
vtjnash committed Dec 16, 2015
2 parents 97443cd + abac887 commit 7530fce
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 5 deletions.
5 changes: 2 additions & 3 deletions src/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -1642,18 +1642,17 @@ JL_DLLEXPORT size_t jl_static_show_func_sig(JL_STREAM *s, jl_value_t *type)
return n;
}

int in_jl_ = 0;
JL_DLLEXPORT void jl_(void *jl_value)
{
in_jl_++;
jl_in_jl_++;
JL_TRY {
(void)jl_static_show((JL_STREAM*)STDERR_FILENO, (jl_value_t*)jl_value);
jl_printf((JL_STREAM*)STDERR_FILENO,"\n");
}
JL_CATCH {
jl_printf((JL_STREAM*)STDERR_FILENO, "\n!!! ERROR in jl_ -- ABORTING !!!\n");
}
in_jl_--;
jl_in_jl_--;
}

JL_DLLEXPORT void jl_breakpoint(jl_value_t *v)
Expand Down
2 changes: 2 additions & 0 deletions src/jl_uv.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,8 @@ JL_DLLEXPORT int jl_fs_chmod(char *path, int mode)
JL_DLLEXPORT int jl_fs_write(int handle, const char *data, size_t len,
int64_t offset)
{
if (jl_in_jl_)
return write(handle, data, len);
uv_fs_t req;
uv_buf_t buf[1];
buf[0].base = (char*)data;
Expand Down
1 change: 1 addition & 0 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -1420,6 +1420,7 @@ typedef struct _jl_tls_states_t {
void *stackbase;
jl_jmp_buf *volatile jmp_target;
jl_jmp_buf base_ctx; // base context of stack
int8_t in_jl_;
int16_t tid;
size_t bt_size;
ptrint_t bt_data[JL_MAX_BT_SIZE + 1];
Expand Down
1 change: 1 addition & 0 deletions src/julia_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ extern jl_function_t *jl_typeinf_func;
#if defined(JL_USE_INTEL_JITEVENTS)
extern unsigned sig_stack_size;
#endif
#define jl_in_jl_ jl_get_ptls_states()->in_jl_

JL_DLLEXPORT extern int jl_lineno;
JL_DLLEXPORT extern const char *jl_filename;
Expand Down
3 changes: 1 addition & 2 deletions src/signals-unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,12 @@ void sigdie_handler(int sig, siginfo_t *info, void *context)
#include <signals-mach.c>
#else

extern int in_jl_;
static void segv_handler(int sig, siginfo_t *info, void *context)
{
sigset_t sset;
assert(sig == SIGSEGV);

if (in_jl_ || is_addr_on_stack(info->si_addr)) { // stack overflow, or restarting jl_
if (jl_in_jl_ || is_addr_on_stack(info->si_addr)) { // stack overflow, or restarting jl_
sigemptyset(&sset);
sigaddset(&sset, SIGSEGV);
sigprocmask(SIG_UNBLOCK, &sset, NULL);
Expand Down

0 comments on commit 7530fce

Please sign in to comment.