Skip to content

Commit a53a08e

Browse files
committed
rt: Don't allocate a C stack for tasks that already have one
1 parent 44d4889 commit a53a08e

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

src/rt/rust_task.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ rust_task : public kernel_owned<rust_task>, rust_cond
205205

206206
void call_on_c_stack(void *args, void *fn_ptr);
207207
void call_on_rust_stack(void *args, void *fn_ptr);
208+
bool have_c_stack() { return c_stack != NULL; }
208209
};
209210

210211
// This stuff is on the stack-switching fast path

src/rt/rust_task_thread.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ rust_task_thread::activate(rust_task *task) {
7070
task->ctx.next = &c_context;
7171
DLOG(this, task, "descheduling...");
7272
lock.unlock();
73-
prepare_c_stack();
73+
prepare_c_stack(task);
7474
task->ctx.swap(c_context);
7575
unprepare_c_stack();
7676
lock.lock();
@@ -367,9 +367,9 @@ rust_task_thread::exit() {
367367
// stack), because once we're on the Rust stack we won't have enough
368368
// room to do the allocation
369369
void
370-
rust_task_thread::prepare_c_stack() {
370+
rust_task_thread::prepare_c_stack(rust_task *task) {
371371
I(this, !extra_c_stack);
372-
if (!cached_c_stack) {
372+
if (!cached_c_stack && !task->have_c_stack()) {
373373
cached_c_stack = create_stack(kernel, C_STACK_SIZE);
374374
prepare_valgrind_stack(cached_c_stack);
375375
}

src/rt/rust_task_thread.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ struct rust_task_thread : public kernel_owned<rust_task_thread>,
9898
stk_seg *cached_c_stack;
9999
stk_seg *extra_c_stack;
100100

101-
void prepare_c_stack();
101+
void prepare_c_stack(rust_task *task);
102102
void unprepare_c_stack();
103103

104104
public:

0 commit comments

Comments
 (0)