Skip to content

Rewrite TLS to require less usage of @ #7677

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 8 commits into from
Jul 12, 2013
4 changes: 2 additions & 2 deletions src/libextra/rl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ fn complete_key(_v: @CompletionCb) {}

/// Bind to the main completion callback
pub unsafe fn complete(cb: CompletionCb) {
local_data::local_data_set(complete_key, @(cb));
local_data::set(complete_key, @(cb));

extern fn callback(line: *c_char, completions: *()) {
unsafe {
let cb = *local_data::local_data_get(complete_key)
let cb = *local_data::get(complete_key, |k| k.map(|&k| *k))
.get();

do cb(str::raw::from_c_str(line)) |suggestion| {
Expand Down
4 changes: 2 additions & 2 deletions src/libextra/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1204,11 +1204,11 @@ mod big_tests {
#[unsafe_destructor]
impl<'self> Drop for LVal<'self> {
fn drop(&self) {
let x = unsafe { local_data::local_data_get(self.key) };
let x = unsafe { local_data::get(self.key, |k| k.map(|&k| *k)) };
match x {
Some(@y) => {
unsafe {
local_data::local_data_set(self.key, @(y+1));
local_data::set(self.key, @(y+1));
}
}
_ => fail!("Expected key to work"),
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ fn task_local_insn_key(_v: @~[&'static str]) {}

pub fn with_insn_ctxt(blk: &fn(&[&'static str])) {
unsafe {
let opt = local_data::local_data_get(task_local_insn_key);
let opt = local_data::get(task_local_insn_key, |k| k.map(|&k| *k));
if opt.is_some() {
blk(*opt.unwrap());
}
Expand All @@ -101,7 +101,7 @@ pub fn with_insn_ctxt(blk: &fn(&[&'static str])) {

pub fn init_insn_ctxt() {
unsafe {
local_data::local_data_set(task_local_insn_key, @~[]);
local_data::set(task_local_insn_key, @~[]);
}
}

Expand All @@ -111,7 +111,7 @@ pub struct _InsnCtxt { _x: () }
impl Drop for _InsnCtxt {
fn drop(&self) {
unsafe {
do local_data::local_data_modify(task_local_insn_key) |c| {
do local_data::modify(task_local_insn_key) |c| {
do c.map_consume |ctx| {
let mut ctx = copy *ctx;
ctx.pop();
Expand All @@ -125,7 +125,7 @@ impl Drop for _InsnCtxt {
pub fn push_ctxt(s: &'static str) -> _InsnCtxt {
debug!("new InsnCtxt: %s", s);
unsafe {
do local_data::local_data_modify(task_local_insn_key) |c| {
do local_data::modify(task_local_insn_key) |c| {
do c.map_consume |ctx| {
let mut ctx = copy *ctx;
ctx.push(s);
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/trans/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,14 +241,14 @@ impl Drop for CrateContext {

fn task_local_llcx_key(_v: @ContextRef) {}
pub fn task_llcx() -> ContextRef {
let opt = unsafe { local_data::local_data_get(task_local_llcx_key) };
let opt = unsafe { local_data::get(task_local_llcx_key, |k| k.map(|&k| *k)) };
*opt.expect("task-local LLVMContextRef wasn't ever set!")
}

unsafe fn set_task_llcx(c: ContextRef) {
local_data::local_data_set(task_local_llcx_key, @c);
local_data::set(task_local_llcx_key, @c);
}

unsafe fn unset_task_llcx() {
local_data::local_data_pop(task_local_llcx_key);
local_data::pop(task_local_llcx_key);
}
10 changes: 5 additions & 5 deletions src/librusti/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ struct LocalVariable {
}

type LocalCache = @mut HashMap<~str, @~[u8]>;
fn tls_key(_k: @LocalCache) {}
fn tls_key(_k: LocalCache) {}

impl Program {
pub fn new() -> Program {
Expand Down Expand Up @@ -132,7 +132,7 @@ impl Program {
");

let key: sys::Closure = unsafe {
let tls_key: &'static fn(@LocalCache) = tls_key;
let tls_key: &'static fn(LocalCache) = tls_key;
cast::transmute(tls_key)
};
// First, get a handle to the tls map which stores all the local
Expand All @@ -144,7 +144,7 @@ impl Program {
let key = ::std::sys::Closure{ code: %? as *(),
env: ::std::ptr::null() };
let key = ::std::cast::transmute(key);
*::std::local_data::local_data_get(key).unwrap()
::std::local_data::get(key, |k| k.map(|&x| *x)).unwrap()
};\n", key.code as uint));

// Using this __tls_map handle, deserialize each variable binding that
Expand Down Expand Up @@ -227,7 +227,7 @@ impl Program {
map.insert(copy *name, @copy value.data);
}
unsafe {
local_data::local_data_set(tls_key, @map);
local_data::set(tls_key, map);
}
}

Expand All @@ -236,7 +236,7 @@ impl Program {
/// it updates this cache with the new values of each local variable.
pub fn consume_cache(&mut self) {
let map = unsafe {
local_data::local_data_pop(tls_key).expect("tls is empty")
local_data::pop(tls_key).expect("tls is empty")
};
do map.consume |name, value| {
match self.local_vars.find_mut(&name) {
Expand Down
17 changes: 8 additions & 9 deletions src/libstd/condition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

#[allow(missing_doc)];

use local_data::{local_data_pop, local_data_set};
use local_data;
use prelude::*;

Expand All @@ -26,14 +25,14 @@ pub struct Handler<T, U> {

pub struct Condition<'self, T, U> {
name: &'static str,
key: local_data::LocalDataKey<'self, Handler<T, U>>
key: local_data::Key<'self, @Handler<T, U>>
}

impl<'self, T, U> Condition<'self, T, U> {
pub fn trap(&'self self, h: &'self fn(T) -> U) -> Trap<'self, T, U> {
unsafe {
let p : *RustClosure = ::cast::transmute(&h);
let prev = local_data::local_data_get(self.key);
let prev = local_data::get(self.key, |k| k.map(|&x| *x));
let h = @Handler { handle: *p, prev: prev };
Trap { cond: self, handler: h }
}
Expand All @@ -46,7 +45,7 @@ impl<'self, T, U> Condition<'self, T, U> {

pub fn raise_default(&self, t: T, default: &fn() -> U) -> U {
unsafe {
match local_data_pop(self.key) {
match local_data::pop(self.key) {
None => {
debug!("Condition.raise: found no handler");
default()
Expand All @@ -55,12 +54,12 @@ impl<'self, T, U> Condition<'self, T, U> {
debug!("Condition.raise: found handler");
match handler.prev {
None => {}
Some(hp) => local_data_set(self.key, hp)
Some(hp) => local_data::set(self.key, hp)
}
let handle : &fn(T) -> U =
::cast::transmute(handler.handle);
let u = handle(t);
local_data_set(self.key, handler);
local_data::set(self.key, handler);
u
}
}
Expand All @@ -78,7 +77,7 @@ impl<'self, T, U> Trap<'self, T, U> {
unsafe {
let _g = Guard { cond: self.cond };
debug!("Trap: pushing handler to TLS");
local_data_set(self.cond.key, self.handler);
local_data::set(self.cond.key, self.handler);
inner()
}
}
Expand All @@ -93,12 +92,12 @@ impl<'self, T, U> Drop for Guard<'self, T, U> {
fn drop(&self) {
unsafe {
debug!("Guard: popping handler from TLS");
let curr = local_data_pop(self.cond.key);
let curr = local_data::pop(self.cond.key);
match curr {
None => {}
Some(h) => match h.prev {
None => {}
Some(hp) => local_data_set(self.cond.key, hp)
Some(hp) => local_data::set(self.cond.key, hp)
}
}
}
Expand Down
Loading