-
-
Save ugexe/09d8220ca20426fb8f1fa52fc27a9261 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/6model/reprs/MVMThread.h b/src/6model/reprs/MVMThread.h | |
index 9aa0804ec..e2bf5b0bf 100644 | |
--- a/src/6model/reprs/MVMThread.h | |
+++ b/src/6model/reprs/MVMThread.h | |
@@ -36,6 +36,9 @@ struct MVMThreadBody { | |
/* Non-zero if the thread should not block shutdown of the VM (those with | |
* zero in here will be joined when the main thread ends). */ | |
MVMint32 app_lifetime; | |
+ | |
+ /* Stack size in bytes. */ | |
+ MVMint64 stack_size; | |
}; | |
struct MVMThread { | |
MVMObject common; | |
diff --git a/src/core/interp.c b/src/core/interp.c | |
index d892e0e99..f06ac8c3a 100644 | |
--- a/src/core/interp.c | |
+++ b/src/core/interp.c | |
@@ -3684,8 +3684,8 @@ void MVM_interp_run(MVMThreadContext *tc, void (*initial_invoke)(MVMThreadContex | |
} | |
OP(newthread): | |
GET_REG(cur_op, 0).o = MVM_thread_new(tc, GET_REG(cur_op, 2).o, | |
- GET_REG(cur_op, 4).i64); | |
- cur_op += 6; | |
+ GET_REG(cur_op, 4).i64, GET_REG(cur_op, 6).i64); | |
+ cur_op += 8; | |
goto NEXT; | |
OP(threadjoin): | |
MVM_thread_join(tc, GET_REG(cur_op, 0).o); | |
diff --git a/src/core/threads.c b/src/core/threads.c | |
index 2940762a8..b4d31626e 100644 | |
--- a/src/core/threads.c | |
+++ b/src/core/threads.c | |
@@ -9,7 +9,7 @@ typedef struct { | |
/* Creates a new thread handle with the MVMThread representation. Does not | |
* actually start execution of the thread, but does give it its unique ID. */ | |
-MVMObject * MVM_thread_new(MVMThreadContext *tc, MVMObject *invokee, MVMint64 app_lifetime) { | |
+MVMObject * MVM_thread_new(MVMThreadContext *tc, MVMObject *invokee, MVMint64 app_lifetime, MVMint64 stack_size) { | |
MVMThread *thread; | |
MVMThreadContext *child_tc; | |
unsigned int interval_id; | |
@@ -23,6 +23,7 @@ MVMObject * MVM_thread_new(MVMThreadContext *tc, MVMObject *invokee, MVMint64 ap | |
thread->body.stage = MVM_thread_stage_unstarted; | |
MVM_ASSIGN_REF(tc, &(thread->common.header), thread->body.invokee, invokee); | |
thread->body.app_lifetime = app_lifetime; | |
+ thread->body.stack_size = stack_size; | |
/* Try to create the new threadcontext. Can throw if libuv can't | |
* create a loop for it for some reason (i.e. too many open files) */ | |
@@ -111,6 +112,7 @@ void MVM_thread_run(MVMThreadContext *tc, MVMObject *thread_obj) { | |
MVMThread *child = (MVMThread *)thread_obj; | |
int status, added; | |
ThreadStart *ts; | |
+ uv_thread_options_t options; | |
if (REPR(child)->ID == MVM_REPR_ID_MVMThread && IS_CONCRETE(thread_obj)) { | |
MVMThreadContext *child_tc = child->body.tc; | |
@@ -166,7 +168,9 @@ void MVM_thread_run(MVMThreadContext *tc, MVMObject *thread_obj) { | |
} | |
/* Do the actual thread creation. */ | |
- status = uv_thread_create(&child->body.thread, start_thread, ts); | |
+ options.flags = UV_THREAD_HAS_STACK_SIZE; | |
+ options.stack_size = child->body.stack_size > 0 ? child->body.stack_size : 0; | |
+ status = uv_thread_create_ex(&child->body.thread, &options, start_thread, ts); | |
if (status < 0) | |
MVM_panic(MVM_exitcode_compunit, "Could not spawn thread: errorcode %d", status); | |
} | |
diff --git a/src/core/threads.h b/src/core/threads.h | |
index 1038d6814..086fc9607 100644 | |
--- a/src/core/threads.h | |
+++ b/src/core/threads.h | |
@@ -1,4 +1,4 @@ | |
-MVMObject * MVM_thread_new(MVMThreadContext *tc, MVMObject *invokee, MVMint64 app_lifetime); | |
+MVMObject * MVM_thread_new(MVMThreadContext *tc, MVMObject *invokee, MVMint64 app_lifetime, MVMint64 stack_size); | |
void MVM_thread_run(MVMThreadContext *tc, MVMObject *thread); | |
void MVM_thread_join(MVMThreadContext *tc, MVMObject *thread); | |
MVMint64 MVM_thread_id(MVMThreadContext *tc, MVMObject *thread); | |
diff --git a/src/debug/debugserver.c b/src/debug/debugserver.c | |
index b2b4f49c3..3366b34a5 100644 | |
--- a/src/debug/debugserver.c | |
+++ b/src/debug/debugserver.c | |
@@ -2807,7 +2807,7 @@ MVM_PUBLIC void MVM_debugserver_init(MVMThreadContext *tc, MVMuint32 port) { | |
worker_entry_point = MVM_repr_alloc_init(tc, tc->instance->boot_types.BOOTCCode); | |
((MVMCFunction *)worker_entry_point)->body.func = debugserver_worker; | |
- MVM_thread_run(tc, MVM_thread_new(tc, worker_entry_point, 1)); | |
+ MVM_thread_run(tc, MVM_thread_new(tc, worker_entry_point, 1, 0)); | |
} | |
MVM_PUBLIC void MVM_debugserver_mark_handles(MVMThreadContext *tc, MVMGCWorklist *worklist, MVMHeapSnapshotState *snapshot) { | |
diff --git a/src/io/eventloop.c b/src/io/eventloop.c | |
index 044b33757..00a3293c3 100644 | |
--- a/src/io/eventloop.c | |
+++ b/src/io/eventloop.c | |
@@ -139,7 +139,7 @@ void MVM_io_eventloop_start(MVMThreadContext *tc) { | |
loop_runner = MVM_repr_alloc_init(tc, instance->boot_types.BOOTCCode); | |
((MVMCFunction *)loop_runner)->body.func = enter_loop; | |
- instance->event_loop_thread = MVM_thread_new(tc, loop_runner, 1); | |
+ instance->event_loop_thread = MVM_thread_new(tc, loop_runner, 1, 0); | |
MVM_thread_run(tc, instance->event_loop_thread); | |
} | |
diff --git a/src/spesh/worker.c b/src/spesh/worker.c | |
index acf5bd72b..ca3e334cf 100644 | |
--- a/src/spesh/worker.c | |
+++ b/src/spesh/worker.c | |
@@ -170,7 +170,7 @@ void MVM_spesh_worker_start(MVMThreadContext *tc) { | |
worker_entry_point = MVM_repr_alloc_init(tc, tc->instance->boot_types.BOOTCCode); | |
((MVMCFunction *)worker_entry_point)->body.func = worker; | |
- tc->instance->spesh_thread = MVM_thread_new(tc, worker_entry_point, 1); | |
+ tc->instance->spesh_thread = MVM_thread_new(tc, worker_entry_point, 1, 0); | |
MVM_thread_run(tc, tc->instance->spesh_thread); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment