@@ -2,6 +2,7 @@ use crate::job::StackJob;
22use crate :: latch:: { LatchProbe , SpinLatch } ;
33use crate :: log:: Event :: * ;
44use crate :: registry:: { self , WorkerThread } ;
5+ use crate :: tlv;
56use crate :: unwind;
67use std:: any:: Any ;
78
@@ -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,6 +165,9 @@ 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) ;
167172 return ( result_a, result_b) ;
168173 } else {
@@ -183,6 +188,9 @@ where
183188 }
184189 }
185190
191+ // Restore the TLV since we might have run some jobs overwriting it when waiting for job b.
192+ tlv:: set ( tlv) ;
193+
186194 ( result_a, job_b. into_result ( ) )
187195 } )
188196}
@@ -195,7 +203,12 @@ unsafe fn join_recover_from_panic(
195203 worker_thread : & WorkerThread ,
196204 job_b_latch : & SpinLatch ,
197205 err : Box < dyn Any + Send > ,
206+ tlv : usize ,
198207) -> ! {
199208 worker_thread. wait_until ( job_b_latch) ;
209+
210+ // Restore the TLV since we might have run some jobs overwriting it when waiting for job b.
211+ tlv:: set ( tlv) ;
212+
200213 unwind:: resume_unwinding ( err)
201214}
0 commit comments