Skip to content

Commit 1a8676b

Browse files
committed
allow tasks to request dedicated stack space when created
1 parent ac31862 commit 1a8676b

File tree

5 files changed

+84
-107
lines changed

5 files changed

+84
-107
lines changed

base/boot.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ eval(:(Core.call(::Type{GlobalRef}, m::Module, s::Symbol) = $(Expr(:new, :Global
298298

299299
Module(name::Symbol=:anonymous, std_imports::Bool=true) = ccall(:jl_f_new_module, Any, (Any, Bool), name, std_imports)::Module
300300

301-
Task(f::ANY) = ccall(:jl_new_task, Any, (Any, Int), f::Function, 0)::Task
301+
Task(f::ANY, reserved_stack::Int=0) = ccall(:jl_new_task, Any, (Any, Int), f::Function, reserved_stack)::Task
302302

303303
# simple convert for use by constructors of types in Core
304304
# note that there is no actual conversion defined here,

src/gc.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,17 +1562,15 @@ static void gc_mark_task_stack(jl_task_t *ta, int d)
15621562
if (ta == jl_current_task) {
15631563
gc_mark_stack((jl_value_t*)ta, jl_pgcstack, 0, d);
15641564
}
1565-
else if (ta == jl_root_task) {
1565+
else if (!ta->copy_stack) {
15661566
gc_mark_stack((jl_value_t*)ta, ta->gcstack, 0, d);
15671567
}
1568-
else if (ta->stkbuf != NULL && ta->stkbuf != (void*)(intptr_t)-1) {
15691568
#ifdef COPY_STACKS
1569+
else if (ta->stkbuf != NULL && ta->stkbuf != (void*)(intptr_t)-1) {
15701570
ptrint_t offset = (char *)ta->stkbuf + ta->ssize - (char *)jl_stackbase;
1571-
#else
1572-
ptrint_t offset = 0;
1573-
#endif
15741571
gc_mark_stack((jl_value_t*)ta, ta->gcstack, offset, d);
15751572
}
1573+
#endif
15761574
}
15771575

15781576
NOINLINE static void gc_mark_task(jl_task_t *ta, int d)
@@ -1808,7 +1806,7 @@ double clock_now(void);
18081806

18091807
extern jl_module_t *jl_old_base_module;
18101808
extern jl_array_t *jl_module_init_order;
1811-
extern jl_value_t *jl_unprotect_stack_func;
1809+
extern jl_value_t *jl_task_cleanup_func;
18121810

18131811
static int inc_count = 0;
18141812
static int quick_count = 0;
@@ -1846,7 +1844,7 @@ static void pre_mark(void)
18461844
}
18471845

18481846
jl_mark_box_caches();
1849-
gc_push_root(jl_unprotect_stack_func, 0);
1847+
gc_push_root(jl_task_cleanup_func, 0);
18501848
gc_push_root(jl_bottom_func, 0);
18511849
gc_push_root(jl_typetype_type, 0);
18521850

src/julia.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1389,7 +1389,8 @@ typedef struct _jl_task_t {
13891389
#endif
13901390
jl_jmp_buf ctx; // saved thread state
13911391
void *stkbuf; // malloc'd memory
1392-
int ssize; // sizeof the portion of stack used in stkbuf
1392+
int ssize:31; // sizeof stkbuf
1393+
int copy_stack:1;
13931394

13941395
// current exception handler
13951396
jl_handler_t *eh;

src/signals-unix.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,12 @@ void fpe_handler(int arg)
1414

1515
static int is_addr_on_stack(void *addr)
1616
{
17-
#ifdef COPY_STACKS
18-
if (jl_current_task == jl_root_task)
19-
return ((char*)addr > (char*)jl_stack_lo-3000000 &&
20-
(char*)addr < (char*)jl_stack_hi);
21-
else
17+
if (jl_current_task->copy_stack)
2218
return ((char*)addr > (char*)jl_stackbase - JL_STACK_SIZE &&
2319
(char*)addr < (char*)jl_stackbase);
24-
#else
25-
return ((char*)addr > (char*)jl_current_task->stkbuf &&
26-
(char*)addr < (char*)jl_current_task->stkbuf + jl_current_task->ssize);
27-
#endif
20+
else
21+
return ((char*)addr > (char*)jl_current_task->stkbuf &&
22+
(char*)addr < (char*)jl_current_task->stkbuf + jl_current_task->ssize);
2823
}
2924

3025
#ifndef SIGINFO

0 commit comments

Comments
 (0)