File tree 1 file changed +6
-5
lines changed
compiler/rustc_data_structures/src/sync
1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -106,6 +106,12 @@ pub struct WorkerLocal<T> {
106
106
registry : Registry ,
107
107
}
108
108
109
+ // This is safe because the `deref` call will return a reference to a `T` unique to each thread
110
+ // or it will panic for threads without an associated local. So there isn't a need for `T` to do
111
+ // it's own synchronization. The `verify` method on `RegistryId` has an issue where the id
112
+ // can be reused, but `WorkerLocal` has a reference to `Registry` which will prevent any reuse.
113
+ unsafe impl < T : Send > Sync for WorkerLocal < T > { }
114
+
109
115
impl < T > WorkerLocal < T > {
110
116
/// Creates a new worker local where the `initial` closure computes the
111
117
/// value this worker local should take for each thread in the registry.
@@ -132,11 +138,6 @@ impl<T> Deref for WorkerLocal<T> {
132
138
fn deref ( & self ) -> & T {
133
139
// This is safe because `verify` will only return values less than
134
140
// `self.registry.thread_limit` which is the size of the `self.locals` array.
135
-
136
- // The `deref` call will return a reference to a `T` unique to each thread
137
- // or it will panic for threads without an associated local. So there isn't a need for `T` to do
138
- // it's own synchronization. The `verify` method on `RegistryId` has an issue where the id
139
- // can be reused, but `WorkerLocal` has a reference to `Registry` which will prevent any reuse.
140
141
unsafe { & self . locals . get_unchecked ( self . registry . id ( ) . verify ( ) ) . 0 }
141
142
}
142
143
}
You can’t perform that action at this time.
0 commit comments