From 1ba3028d8b7acb0c97859ea438f2beb4ccd364f9 Mon Sep 17 00:00:00 2001 From: Ben Blum Date: Wed, 27 Jun 2012 13:07:00 -0400 Subject: rt: Add task_local_data and related builtin calls (Closes #2680) --- src/rt/rust_task.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/rt/rust_task.cpp') diff --git a/src/rt/rust_task.cpp b/src/rt/rust_task.cpp index e5d61fda93d..c899d997197 100644 --- a/src/rt/rust_task.cpp +++ b/src/rt/rust_task.cpp @@ -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 -- cgit 1.4.1-3-g733a5