@@ -10,6 +10,7 @@ use std::{
1010} ;
1111
1212use compio_buf:: { BufResult , IntoInner } ;
13+ use compio_send_wrapper:: SendWrapper ;
1314use thin_cell:: unsync:: { Inner , Ref , ThinCell } ;
1415
1516use crate :: { Carry , DriverType , Extra , OpCode , PushEntry , control:: Carrier } ;
@@ -348,6 +349,7 @@ impl ErasedKey {
348349 pub ( crate ) unsafe fn freeze ( self ) -> FrozenKey {
349350 FrozenKey {
350351 inner : ManuallyDrop :: new ( self ) ,
352+ thread_id : SendWrapper :: new ( ( ) ) ,
351353 }
352354 }
353355}
@@ -360,10 +362,11 @@ impl Debug for ErasedKey {
360362
361363/// A frozen view into a [`Key`].
362364///
363- /// It's guaranteed to have the same layout as [`ErasedKey`].
364- #[ repr( transparent ) ]
365+ /// It's guaranteed to have [`ErasedKey`] as the first field .
366+ #[ repr( C ) ]
365367pub ( crate ) struct FrozenKey {
366368 inner : ManuallyDrop < ErasedKey > ,
369+ thread_id : SendWrapper < ( ) > ,
367370}
368371
369372impl FrozenKey {
@@ -372,7 +375,16 @@ impl FrozenKey {
372375 }
373376
374377 pub fn into_inner ( self ) -> ErasedKey {
375- ManuallyDrop :: into_inner ( self . inner )
378+ let mut this = ManuallyDrop :: new ( self ) ;
379+ unsafe { ManuallyDrop :: take ( & mut this. inner ) }
380+ }
381+ }
382+
383+ impl Drop for FrozenKey {
384+ fn drop ( & mut self ) {
385+ if self . thread_id . valid ( ) {
386+ unsafe { ManuallyDrop :: drop ( & mut self . inner ) }
387+ }
376388 }
377389}
378390
0 commit comments