8000 Scheduling and Task Safety Improvements by eholk · Pull Request #753 · rust-lang/rust · GitHub
[go: up one dir, main page]

Skip to content

Scheduling and Task Safety Improvements #753

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

Closed
wants to merge 11 commits into from
Prev Previous commit
Next Next commit
Adding upcalls to to ref() and deref() tasks. This is the first step …
…towards atomic reference counting of tasks.
  • Loading branch information
Eric Holk committed Jul 27, 2011
commit 0f014710de81db36d87706d9f6d438621f049732
4 changes: 4 additions & 0 deletions src/comp/back/upcall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ type upcalls =
vec_append: ValueRef,
get_type_desc: ValueRef,
new_task: ValueRef,
take_task: ValueRef,
drop_task: ValueRef,
start_task: ValueRef,
ivec_resize: ValueRef,
ivec_spill: ValueRef,
Expand Down Expand Up @@ -129,6 +131,8 @@ fn declare_upcalls(tn: type_names, tydesc_type: TypeRef,
~[T_ptr(T_nil()), T_size_t(), T_size_t(), T_size_t(),
T_ptr(T_ptr(tydesc_type))], T_ptr(tydesc_type)),
new_task: d("new_task", ~[T_ptr(T_str())], taskptr_type),
take_task: dv("take_task", ~[taskptr_type]),
drop_task: dv("drop_task", ~[taskptr_type]),
start_task:
d("start_task", ~[taskptr_type, T_int(), T_int(), T_size_t()],
taskptr_type),
Expand Down
15 changes: 13 additions & 2 deletions src/comp/middle/trans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1221,7 +1221,13 @@ fn make_copy_glue(cx: &@block_ctxt, v: ValueRef, t: &ty::t) {
// NB: v is an *alias* of type t here, not a direct value.

let bcx;
if ty::type_is_boxed(bcx_tcx(cx), t) {

if ty::type_is_task(bcx_tcx(cx), t) {
let task_ptr = cx.build.Load(v);
cx.build.Call(bcx_ccx(cx).upcalls.take_task,
~[cx.fcx.lltaskptr, task_ptr]);
bcx = cx;
} else if ty::type_is_boxed(bcx_tcx(cx), t) {
bcx = incr_refcnt_of_boxed(cx, cx.build.Load(v)).bcx;
} else if (ty::type_is_structural(bcx_tcx(cx), t)) {
bcx = duplicate_heap_parts_if_necessary(cx, v, t).bcx;
Expand Down Expand Up @@ -1381,7 +1387,12 @@ fn make_drop_glue(cx: &@block_ctxt, v0: ValueRef, t: &ty::t) {
ty::ty_box(_) { decr_refcnt_maybe_free(cx, v0, v0, t) }
ty::ty_port(_) { decr_refcnt_maybe_free(cx, v0, v0, t) }
ty::ty_chan(_) { decr_refcnt_maybe_free(cx, v0, v0, t) }
ty::ty_task. { decr_refcnt_maybe_free(cx, v0, v0, t) }
ty::ty_task. {
let task_ptr = cx.build.Load(v0);
{bcx: cx,
val: cx.build.Call(bcx_ccx(cx).upcalls.drop_task,
~[cx.fcx.lltaskptr, task_ptr])}
}
ty::ty_obj(_) {
let box_cell =
cx.build.GEP(v0, ~[C_int(0), C_int(abi::obj_field_box)]);
Expand Down
5 changes: 5 additions & 0 deletions src/comp/middle/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ export type_is_bot;
export type_is_box;
export type_is_boxed;
export type_is_chan;
export type_is_task;
export type_is_fp;
export type_is_integral;
export type_is_native;
Expand Down Expand Up @@ -839,6 +840,10 @@ fn type_is_chan(cx: &ctxt, ty: &t) -> bool {
alt struct(cx, ty) { ty_chan(_) { ret true; } _ { ret false; } }
}

fn type_is_task(cx: &ctxt, ty: &t) -> bool {
alt struct(cx, ty) { ty_task. { ret true; } _ { ret false; } }
}

fn type_is_structural(cx: &ctxt, ty: &t) -> bool {
alt struct(cx, ty) {
ty_rec(_) { ret true; }
Expand Down
17 changes: 17 additions & 0 deletions src/rt/rust_upcall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,23 @@ upcall_new_task(rust_task *spawner, rust_vec *name) {
return task;
}

extern "C" CDECL void
upcall_take_task(rust_task *task, rust_task *target) {
LOG_UPCALL_ENTRY(task);
if(target) {
target->ref();
}
}

extern "C" CDECL void
upcall_drop_task(rust_task *task, rust_task *target) {
LOG_UPCALL_ENTRY(task);
if(target) {
//target->deref();
--target->ref_count;
}
}

extern "C" CDECL rust_task *
upcall_start_task(rust_task *spawner,
rust_task *task,
Expand Down
2 changes: 2 additions & 0 deletions src/rt/rustrt.def.in
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ upcall_chan_target_task
upcall_clone_chan
upcall_del_chan
upcall_del_port
upcall_drop_task
upcall_dup_str
upcall_exit
upcall_fail
Expand Down Expand Up @@ -87,6 +88,7 @@ upcall_shared_malloc
upcall_shared_free
upcall_sleep
upcall_start_task
upcall_take_task
upcall_trace_str
upcall_trace_word
upcall_vec_append
Expand Down
2 changes: 1 addition & 1 deletion src/rt/sync/lock_and_signal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "lock_and_signal.h"

#if defined(__WIN32__)
lock_and_signal::lock_and_signal()
lock_and_signal::lock_and_signal()
: alive(true)
{
// FIXME: In order to match the behavior of pthread_cond_broadcast on
Expand Down
0