@@ -3,6 +3,7 @@ use latch::{LatchProbe, SpinLatch};
33use log:: Event :: * ;
44use registry:: { self , WorkerThread } ;
55use std:: any:: Any ;
6+ use tlv;
67use unwind;
78
89use FnContext ;
@@ -135,18 +136,19 @@ where
135136 worker: worker_thread. index( )
136137 } ) ;
137138
139+ let tlv = tlv:: get ( ) ;
138140 // Create virtual wrapper for task b; this all has to be
139141 // done here so that the stack frame can keep it all live
140142 // long enough.
141- let job_b = StackJob :: new ( call_b ( oper_b) , SpinLatch :: new ( ) ) ;
143+ let job_b = StackJob :: new ( tlv , call_b ( oper_b) , SpinLatch :: new ( ) ) ;
142144 let job_b_ref = job_b. as_job_ref ( ) ;
143145 worker_thread. push ( job_b_ref) ;
144146
145147 // Execute task a; hopefully b gets stolen in the meantime.
146148 let status_a = unwind:: halt_unwinding ( call_a ( oper_a, injected) ) ;
147149 let result_a = match status_a {
148150 Ok ( v) => v,
149- Err ( err) => join_recover_from_panic ( worker_thread, & job_b. latch , err) ,
151+ Err ( err) => join_recover_from_panic ( worker_thread, & job_b. latch , err, tlv ) ,
150152 } ;
151153
152154 // Now that task A has finished, try to pop job B from the
@@ -163,7 +165,11 @@ where
163165 log ! ( PoppedRhs {
164166 worker: worker_thread. index( )
165167 } ) ;
168+ // Restore the TLV since we might have run some jobs overwriting it when waiting for job b.
169+ tlv:: set ( tlv) ;
170+
166171 let result_b = job_b. run_inline ( injected) ;
172+
167173 return ( result_a, result_b) ;
168174 } else {
169175 log ! ( PoppedJob {
@@ -183,6 +189,9 @@ where
183189 }
184190 }
185191
192+ // Restore the TLV since we might have run some jobs overwriting it when waiting for job b.
193+ tlv:: set ( tlv) ;
194+
186195 ( result_a, job_b. into_result ( ) )
187196 } )
188197}
@@ -195,7 +204,12 @@ unsafe fn join_recover_from_panic(
195204 worker_thread : & WorkerThread ,
196205 job_b_latch : & SpinLatch ,
197206 err : Box < dyn Any + Send > ,
207+ tlv : usize ,
198208) -> ! {
199209 worker_thread. wait_until ( job_b_latch) ;
210+
211+ // Restore the TLV since we might have run some jobs overwriting it when waiting for job b.
212+ tlv:: set ( tlv) ;
213+
200214 unwind:: resume_unwinding ( err)
201215}
0 commit comments