rt: Add task_local_data and related builtin calls (Closes #2680)

This commit is contained in:
Ben Blum
2012-06-27 13:07:00 -04:00
parent e56ba156e2
commit 1ba3028d8b
5 changed files with 45 additions and 16 deletions

View File

@@ -31,6 +31,8 @@ rust_task::rust_task(rust_sched_loop *sched_loop, rust_task_state state,
propagate_failure(true),
cc_counter(0),
total_stack_sz(0),
task_local_data(NULL),
task_local_data_cleanup(NULL),
state(state),
cond(NULL),
cond_name("none"),
@@ -115,6 +117,16 @@ cleanup_task(cleanup_args *args) {
}
}
// Clean up TLS. This will only be set if TLS was used to begin with.
// Because this is a crust function, it must be called from the C stack.
if (task->task_local_data_cleanup != NULL) {
// This assert should hold but it's not our job to ensure it (and
// the condition might change). Handled in libcore/task.rs.
// assert(task->task_local_data != NULL);
task->task_local_data_cleanup(task->task_local_data);
task->task_local_data = NULL;
}
// FIXME (#2676): For performance we should do the annihilator
// instead of the cycle collector even under normal termination, but
// since that would hide memory management errors (like not derefing