Skip to content

Commit a676386

Browse files
committed
Move logstate into task-local storage
1 parent e1ea3d6 commit a676386

File tree

5 files changed

+20
-16
lines changed

5 files changed

+20
-16
lines changed

base/boot.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@
163163
# result::Any
164164
# exception::Any
165165
# backtrace::Any
166-
# logstate::Any
167166
# code::Any
168167
#end
169168

base/logging.jl

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ end
492492
LogState(logger) = LogState(LogLevel(_invoked_min_enabled_level(logger)), logger)
493493

494494
function current_logstate()
495-
logstate = current_task().logstate
495+
logstate = get(task_local_storage(), :logstate, nothing)
496496
return (logstate !== nothing ? logstate : _global_logstate)::LogState
497497
end
498498

@@ -505,15 +505,28 @@ end
505505
return nothing
506506
end
507507

508+
function logstate_task_hook(code::UInt8, to)
509+
if code == 0
510+
to::Task
511+
@assert to.storage === nothing
512+
to.storage = IdDict{Any,Any}()
513+
to.storage[:logstate] = get(task_local_storage(), :logstate, nothing)
514+
attach_task_hook!(to, logstate_task_hook_ptr)
515+
end
516+
return
517+
end
518+
const logstate_task_hook_ptr = @cfunction(logstate_task_hook, Nothing, (UInt8, Any))
519+
508520
function with_logstate(f::Function, logstate)
509521
@nospecialize
510-
t = current_task()
511-
old = t.logstate
522+
tls = task_local_storage()
523+
old = get(tls, :logstate, nothing)
524+
tls[:logstate] = logstate
525+
attach_task_hook!(to, logstate_task_hook_ptr)
512526
try
513-
t.logstate = logstate
514527
f()
515528
finally
516-
t.logstate = old
529+
tls[:logstate] = old
517530
end
518531
end
519532

src/jltypes.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2769,13 +2769,12 @@ void jl_init_types(void) JL_GC_DISABLED
27692769
NULL,
27702770
jl_any_type,
27712771
jl_emptysvec,
2772-
jl_perm_symsvec(17,
2772+
jl_perm_symsvec(16,
27732773
"next",
27742774
"queue",
27752775
"storage",
27762776
"donenotify",
27772777
"result",
2778-
"logstate",
27792778
"code",
27802779
"rngState0",
27812780
"rngState1",
@@ -2787,8 +2786,7 @@ void jl_init_types(void) JL_GC_DISABLED
27872786
"sticky",
27882787
"_isexception",
27892788
"priority"),
2790-
jl_svec(17,
2791-
jl_any_type,
2789+
jl_svec(16,
27922790
jl_any_type,
27932791
jl_any_type,
27942792
jl_any_type,

src/julia.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1920,10 +1920,7 @@ typedef struct _jl_task_t {
19201920
jl_value_t *tls;
19211921
jl_value_t *donenotify;
19221922
jl_value_t *result;
1923-
jl_value_t *logstate;
19241923
jl_function_t *start;
1925-
// 4 byte padding on 32-bit systems
1926-
// uint32_t padding0;
19271924
uint64_t rngState[JL_RNG_SIZE];
19281925
jl_value_t *hooks;
19291926
_Atomic(uint8_t) _state;

src/task.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,8 +1113,6 @@ JL_DLLEXPORT jl_task_t *jl_new_task(jl_function_t *start, jl_value_t *completion
11131113
t->result = jl_nothing;
11141114
t->donenotify = completion_future;
11151115
jl_atomic_store_relaxed(&t->_isexception, 0);
1116-
// Inherit logger state from parent task
1117-
t->logstate = ct->logstate;
11181116
// Fork task-local random state from parent
11191117
jl_rng_split(t->rngState, ct->rngState);
11201118
// there is no active exception handler available on this stack yet
@@ -1714,7 +1712,6 @@ jl_task_t *jl_init_root_task(jl_ptls_t ptls, void *stack_lo, void *stack_hi)
17141712
ct->result = jl_nothing;
17151713
ct->donenotify = jl_nothing;
17161714
jl_atomic_store_relaxed(&ct->_isexception, 0);
1717-
ct->logstate = jl_nothing;
17181715
ct->eh = NULL;
17191716
ct->gcstack = NULL;
17201717
ct->excstack = NULL;

0 commit comments

Comments
 (0)