12
12
13
13
Task local data management
14
14
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
16
16
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
18
18
foreign code with bad callback interfaces.
19
19
20
20
To declare a new key for storing local data of a particular type, use the
@@ -70,16 +70,16 @@ pub enum KeyValue<T> { Key }
70
70
trait LocalData { }
71
71
impl < T : ' static > LocalData for T { }
72
72
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.
74
74
// 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
76
76
// 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.
78
78
//
79
79
// 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
81
81
// 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
83
83
// can be reallocated/moved when new values are pushed onto it.
84
84
//
85
85
// This problem currently isn't solved in a very elegant way. Inside the `get`
@@ -88,11 +88,11 @@ impl<T: 'static> LocalData for T {}
88
88
// pointers from being moved under our feet so long as LLVM doesn't go too crazy
89
89
// with the optimizations.
90
90
//
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
92
92
// a proper map.
93
93
#[ 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 > ;
96
96
97
97
// Gets the map from the runtime. Lazily initialises if not done so already.
98
98
unsafe fn get_local_map < ' a > ( ) -> Option < & ' a mut Map > {
@@ -101,11 +101,11 @@ unsafe fn get_local_map<'a>() -> Option<&'a mut Map> {
101
101
let task: * mut Task = Local :: unsafe_borrow ( ) ;
102
102
match & mut ( * task) . storage {
103
103
// 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
105
105
& LocalStorage ( Some ( ref mut map_ptr) ) => {
106
106
return Some ( map_ptr) ;
107
107
}
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
109
109
// actions to the oldsched way of doing things.
110
110
& LocalStorage ( ref mut slot) => {
111
111
* slot = Some ( Vec :: new ( ) ) ;
@@ -135,14 +135,14 @@ pub struct Ref<T> {
135
135
}
136
136
137
137
impl < T : ' static > KeyValue < T > {
138
- /// Replaces a value in task local storage .
138
+ /// Replaces a value in task local data .
139
139
///
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
141
141
/// replaced with the provided data, and then returned.
142
142
///
143
143
/// # Failure
144
144
///
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
146
146
/// loan with the `get` method.
147
147
///
148
148
/// # Example
@@ -171,7 +171,7 @@ impl<T: 'static> KeyValue<T> {
171
171
//
172
172
// Additionally, the type of the local data map must ascribe to Send, so
173
173
// 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
175
175
// out) and we're not actually sending it to other schedulers or
176
176
// anything.
177
177
let newval = data. map ( |d| {
@@ -182,7 +182,7 @@ impl<T: 'static> KeyValue<T> {
182
182
183
183
let pos = match self . find ( map) {
184
184
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 \
186
186
is already borrowed") ,
187
187
None => map. iter ( ) . position ( |entry| entry. is_none ( ) ) ,
188
188
} ;
@@ -207,11 +207,11 @@ impl<T: 'static> KeyValue<T> {
207
207
}
208
208
}
209
209
210
- /// Borrows a value from TLS .
210
+ /// Borrows a value from TLD .
211
211
///
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
213
213
/// 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
215
215
/// `replace` method.
216
216
///
217
217
/// # Example
@@ -246,7 +246,7 @@ impl<T: 'static> KeyValue<T> {
246
246
}
247
247
248
248
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 ) > {
250
250
let key_value = key_to_key_value ( self ) ;
251
251
map. mut_iter ( ) . enumerate ( ) . filter_map ( |( i, entry) | {
252
252
match * entry {
@@ -285,7 +285,7 @@ mod tests {
285
285
static my_key: Key < String > = & Key ;
286
286
my_key. replace ( Some ( "parent data" . to_string ( ) ) ) ;
287
287
task:: spawn ( proc ( ) {
288
- // TLS shouldn't carry over.
288
+ // TLD shouldn't carry over.
289
289
assert ! ( my_key. get( ) . is_none( ) ) ;
290
290
my_key. replace ( Some ( "child data" . to_string ( ) ) ) ;
291
291
assert ! ( my_key. get( ) . get_ref( ) . as_slice( ) == "child data" ) ;
0 commit comments