Skip to content

Commit 3db5cf6

Browse files
committed
Update docs for TLS -> TLD
The correct terminology is Task-Local Data, or TLD. Task-Local Storage, or TLS, is the old terminology that was abandoned because of the confusion with Thread-Local Storage (TLS).
1 parent 5ebf481 commit 3db5cf6

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

src/librustrt/local_data.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
1313
Task local data management
1414
15-
Allows storing arbitrary types inside task-local-storage (TLS), to be accessed
15+
Allows storing arbitrary types inside task-local-data (TLD), to be accessed
1616
anywhere within a task, keyed by a global pointer parameterized over the type of
17-
the TLS slot. Useful for dynamic variables, singletons, and interfacing with
17+
the TLD slot. Useful for dynamic variables, singletons, and interfacing with
1818
foreign code with bad callback interfaces.
1919
2020
To declare a new key for storing local data of a particular type, use the
@@ -70,16 +70,16 @@ pub enum KeyValue<T> { Key }
7070
trait LocalData {}
7171
impl<T: 'static> LocalData for T {}
7272

73-
// The task-local-map stores all TLS information for the currently running task.
73+
// The task-local-map stores all TLD information for the currently running task.
7474
// It is stored as an owned pointer into the runtime, and it's only allocated
75-
// when TLS is used for the first time. This map must be very carefully
75+
// when TLD is used for the first time. This map must be very carefully
7676
// constructed because it has many mutable loans unsoundly handed out on it to
77-
// the various invocations of TLS requests.
77+
// the various invocations of TLD requests.
7878
//
7979
// One of the most important operations is loaning a value via `get` to a
80-
// caller. In doing so, the slot that the TLS entry is occupying cannot be
80+
// caller. In doing so, the slot that the TLD entry is occupying cannot be
8181
// invalidated because upon returning its loan state must be updated. Currently
82-
// the TLS map is a vector, but this is possibly dangerous because the vector
82+
// the TLD map is a vector, but this is possibly dangerous because the vector
8383
// can be reallocated/moved when new values are pushed onto it.
8484
//
8585
// This problem currently isn't solved in a very elegant way. Inside the `get`
@@ -88,11 +88,11 @@ impl<T: 'static> LocalData for T {}
8888
// pointers from being moved under our feet so long as LLVM doesn't go too crazy
8989
// with the optimizations.
9090
//
91-
// n.b. If TLS is used heavily in future, this could be made more efficient with
91+
// n.b. If TLD is used heavily in future, this could be made more efficient with
9292
// a proper map.
9393
#[doc(hidden)]
94-
pub type Map = Vec<Option<(*const u8, TLSValue, uint)>>;
95-
type TLSValue = Box<LocalData + Send>;
94+
pub type Map = Vec<Option<(*const u8, TLDValue, uint)>>;
95+
type TLDValue = Box<LocalData + Send>;
9696

9797
// Gets the map from the runtime. Lazily initialises if not done so already.
9898
unsafe fn get_local_map<'a>() -> Option<&'a mut Map> {
@@ -101,11 +101,11 @@ unsafe fn get_local_map<'a>() -> Option<&'a mut Map> {
101101
let task: *mut Task = Local::unsafe_borrow();
102102
match &mut (*task).storage {
103103
// If the at_exit function is already set, then we just need to take
104-
// a loan out on the TLS map stored inside
104+
// a loan out on the TLD map stored inside
105105
&LocalStorage(Some(ref mut map_ptr)) => {
106106
return Some(map_ptr);
107107
}
108-
// If this is the first time we've accessed TLS, perform similar
108+
// If this is the first time we've accessed TLD, perform similar
109109
// actions to the oldsched way of doing things.
110110
&LocalStorage(ref mut slot) => {
111111
*slot = Some(Vec::new());
@@ -135,14 +135,14 @@ pub struct Ref<T> {
135135
}
136136

137137
impl<T: 'static> KeyValue<T> {
138-
/// Replaces a value in task local storage.
138+
/// Replaces a value in task local data.
139139
///
140-
/// If this key is already present in TLS, then the previous value is
140+
/// If this key is already present in TLD, then the previous value is
141141
/// replaced with the provided data, and then returned.
142142
///
143143
/// # Failure
144144
///
145-
/// This function will fail if this key is present in TLS and currently on
145+
/// This function will fail if this key is present in TLD and currently on
146146
/// loan with the `get` method.
147147
///
148148
/// # Example
@@ -171,7 +171,7 @@ impl<T: 'static> KeyValue<T> {
171171
//
172172
// Additionally, the type of the local data map must ascribe to Send, so
173173
// we do the transmute here to add the Send bound back on. This doesn't
174-
// actually matter because TLS will always own the data (until its moved
174+
// actually matter because TLD will always own the data (until its moved
175175
// out) and we're not actually sending it to other schedulers or
176176
// anything.
177177
let newval = data.map(|d| {
@@ -182,7 +182,7 @@ impl<T: 'static> KeyValue<T> {
182182

183183
let pos = match self.find(map) {
184184
Some((i, _, &0)) => Some(i),
185-
Some((_, _, _)) => fail!("TLS value cannot be replaced because it \
185+
Some((_, _, _)) => fail!("TLD value cannot be replaced because it \
186186
is already borrowed"),
187187
None => map.iter().position(|entry| entry.is_none()),
188188
};
@@ -207,11 +207,11 @@ impl<T: 'static> KeyValue<T> {
207207
}
208208
}
209209

210-
/// Borrows a value from TLS.
210+
/// Borrows a value from TLD.
211211
///
212-
/// If `None` is returned, then this key is not present in TLS. If `Some` is
212+
/// If `None` is returned, then this key is not present in TLD. If `Some` is
213213
/// returned, then the returned data is a smart pointer representing a new
214-
/// loan on this TLS key. While on loan, this key cannot be altered via the
214+
/// loan on this TLD key. While on loan, this key cannot be altered via the
215215
/// `replace` method.
216216
///
217217
/// # Example
@@ -246,7 +246,7 @@ impl<T: 'static> KeyValue<T> {
246246
}
247247

248248
fn find<'a>(&'static self,
249-
map: &'a mut Map) -> Option<(uint, &'a TLSValue, &'a mut uint)>{
249+
map: &'a mut Map) -> Option<(uint, &'a TLDValue, &'a mut uint)>{
250250
let key_value = key_to_key_value(self);
251251
map.mut_iter().enumerate().filter_map(|(i, entry)| {
252252
match *entry {
@@ -285,7 +285,7 @@ mod tests {
285285
static my_key: Key<String> = &Key;
286286
my_key.replace(Some("parent data".to_string()));
287287
task::spawn(proc() {
288-
// TLS shouldn't carry over.
288+
// TLD shouldn't carry over.
289289
assert!(my_key.get().is_none());
290290
my_key.replace(Some("child data".to_string()));
291291
assert!(my_key.get().get_ref().as_slice() == "child data");

0 commit comments

Comments
 (0)