@@ -4,6 +4,7 @@ use log::Event::*;
44use registry:: { self , WorkerThread } ;
55use std:: any:: Any ;
66use unwind;
7+ use tlv;
78
89use FnContext ;
910
@@ -120,10 +121,12 @@ where
120121 worker: worker_thread. index( )
121122 } ) ;
122123
124+ let tlv = tlv:: get ( ) ;
123125 // Create virtual wrapper for task b; this all has to be
124126 // done here so that the stack frame can keep it all live
125127 // long enough.
126128 let job_b = StackJob :: new (
129+ tlv,
127130 |migrated| oper_b ( FnContext :: new ( migrated) ) ,
128131 SpinLatch :: new ( ) ,
129132 ) ;
@@ -134,7 +137,7 @@ where
134137 let status_a = unwind:: halt_unwinding ( move || oper_a ( FnContext :: new ( injected) ) ) ;
135138 let result_a = match status_a {
136139 Ok ( v) => v,
137- Err ( err) => join_recover_from_panic ( worker_thread, & job_b. latch , err) ,
140+ Err ( err) => join_recover_from_panic ( worker_thread, & job_b. latch , err, tlv ) ,
138141 } ;
139142
140143 // Now that task A has finished, try to pop job B from the
@@ -151,7 +154,11 @@ where
151154 log ! ( PoppedRhs {
152155 worker: worker_thread. index( )
153156 } ) ;
157+ // Restore the TLV since we might have run some jobs overwriting it when waiting for job b.
158+ tlv:: set ( tlv) ;
159+
154160 let result_b = job_b. run_inline ( injected) ;
161+
155162 return ( result_a, result_b) ;
156163 } else {
157164 log ! ( PoppedJob {
@@ -171,6 +178,9 @@ where
171178 }
172179 }
173180
181+ // Restore the TLV since we might have run some jobs overwriting it when waiting for job b.
182+ tlv:: set ( tlv) ;
183+
174184 return ( result_a, job_b. into_result ( ) ) ;
175185 } )
176186}
@@ -183,7 +193,12 @@ unsafe fn join_recover_from_panic(
183193 worker_thread : & WorkerThread ,
184194 job_b_latch : & SpinLatch ,
185195 err : Box < Any + Send > ,
196+ tlv : usize ,
186197) -> ! {
187198 worker_thread. wait_until ( job_b_latch) ;
199+
200+ // Restore the TLV since we might have run some jobs overwriting it when waiting for job b.
201+ tlv:: set ( tlv) ;
202+
188203 unwind:: resume_unwinding ( err)
189204}
0 commit comments