Skip to content

rt: Make some runtime calls work outside of task context #5149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 28, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/rt/rust_builtin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ vec_reserve_shared_actual(type_desc* ty, rust_vec_box** vp,
extern "C" CDECL void
vec_reserve_shared(type_desc* ty, rust_vec_box** vp,
size_t n_elts) {
rust_task *task = rust_get_current_task();
reserve_vec_exact(task, vp, n_elts * ty->size);
reserve_vec_exact(vp, n_elts * ty->size);
}

extern "C" CDECL size_t
Expand Down Expand Up @@ -445,9 +444,8 @@ void tm_to_rust_tm(tm* in_tm, rust_tm* out_tm, int32_t gmtoff,
out_tm->tm_nsec = nsec;

if (zone != NULL) {
rust_task *task = rust_get_current_task();
size_t size = strlen(zone);
reserve_vec_exact(task, &out_tm->tm_zone, size + 1);
reserve_vec_exact(&out_tm->tm_zone, size + 1);
memcpy(out_tm->tm_zone->body.data, zone, size);
out_tm->tm_zone->body.fill = size + 1;
out_tm->tm_zone->body.data[size] = '\0';
Expand Down
7 changes: 6 additions & 1 deletion src/rt/rust_upcall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,12 @@ extern "C" CDECL void
upcall_fail(char const *expr,
char const *file,
size_t line) {
rust_task *task = rust_get_current_task();
rust_task *task = rust_try_get_current_task();
if (task == NULL) {
// NOTE: Need to think about what to do here
printf("failure outside of a task");
abort();
}
s_fail_args args = {task,expr,file,line};
UPCALL_SWITCH_STACK(task, &args, upcall_s_fail);
}
Expand Down
7 changes: 4 additions & 3 deletions src/rt/rust_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,12 @@ inline void reserve_vec_exact_shared(rust_task* task, rust_vec_box** vpp,
}
}

inline void reserve_vec_exact(rust_task* task, rust_vec_box** vpp,
inline void reserve_vec_exact(rust_vec_box** vpp,
size_t size) {
if (size > (*vpp)->body.alloc) {
*vpp = (rust_vec_box*)task->kernel
->realloc(*vpp, size + sizeof(rust_vec_box));
rust_exchange_alloc exchange_alloc;
*vpp = (rust_vec_box*)exchange_alloc
.realloc(*vpp, size + sizeof(rust_vec_box));
(*vpp)->body.alloc = size;
}
}
Expand Down