Skip to content

Commit

Permalink
Add accessors for current_task and safe_restore in TLS (#36064)
Browse files Browse the repository at this point in the history
In code which may be compiled against one Julia version but then gets
loaded in another (e.g. due to an update), it is problematic to directly
access members of jl_ptls_t, as this structure frequently changes
between Julia versions

The existing accessor function `jl_get_current_task` helps to avoid this,
so make it public.

Note that the public macro `jl_current_task` exist, but since macros are
compiled into the code which includes `julia.h`, they do not deal with the
situation described above.

No alternatives currently exist for `jl_get_safe_restore` and
`jl_set_safe_restore`.
  • Loading branch information
fingolfin authored Jul 27, 2020
1 parent 90cc95e commit 7adb9ce
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -2077,6 +2077,11 @@ typedef struct {
#define jl_current_task (jl_get_ptls_states()->current_task)
#define jl_root_task (jl_get_ptls_states()->root_task)

JL_DLLEXPORT jl_value_t *jl_get_current_task(void);

JL_DLLEXPORT jl_jmp_buf *jl_get_safe_restore(void);
JL_DLLEXPORT void jl_set_safe_restore(jl_jmp_buf *);

// codegen interface ----------------------------------------------------------
// The root propagation here doesn't have to be literal, but callers should
// ensure that the return value outlives the MethodInstance
Expand Down
1 change: 0 additions & 1 deletion src/julia_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,6 @@ JL_DLLEXPORT jl_value_t *(jl_array_data_owner)(jl_array_t *a);
JL_DLLEXPORT int jl_array_isassigned(jl_array_t *a, size_t i);

JL_DLLEXPORT uintptr_t jl_object_id_(jl_value_t *tv, jl_value_t *v) JL_NOTSAFEPOINT;
JL_DLLEXPORT jl_value_t *jl_get_current_task(void);
JL_DLLEXPORT void jl_set_next_task(jl_task_t *task);

// -- synchronization utilities -- //
Expand Down
12 changes: 12 additions & 0 deletions src/task.c
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,18 @@ JL_DLLEXPORT jl_value_t *jl_get_current_task(void)
return (jl_value_t*)ptls->current_task;
}

JL_DLLEXPORT jl_jmp_buf *jl_get_safe_restore(void)
{
jl_ptls_t ptls = jl_get_ptls_states();
return (jl_value_t*)ptls->safe_restore;
}

JL_DLLEXPORT void jl_set_safe_restore(jl_jmp_buf *sr)
{
jl_ptls_t ptls = jl_get_ptls_states();
ptls->safe_restore = sr;
}

#ifdef JL_HAVE_ASYNCIFY
JL_DLLEXPORT jl_ucontext_t *task_ctx_ptr(jl_task_t *t)
{
Expand Down

4 comments on commit 7adb9ce

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executing the daily benchmark build, I will reply here when finished:

@nanosoldier runbenchmarks(ALL, isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @ararslan

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executing the daily package evaluation, I will reply here when finished:

@nanosoldier runtests(ALL, isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your package evaluation job has completed - possible issues were detected. A full report can be found here. cc @maleadt

Please sign in to comment.