@@ -20,7 +20,6 @@ use std::error::Error as StdError;
2020use std:: fmt:: { self , Debug , Formatter } ;
2121use std:: io;
2222use std:: marker:: PhantomData ;
23- use std:: mem;
2423use std:: ops:: Deref ;
2524use std:: time:: Duration ;
2625
@@ -369,24 +368,10 @@ where
369368 OS_IPC_CHANNELS_FOR_SERIALIZATION . with ( |os_ipc_channels_for_serialization| {
370369 OS_IPC_SHARED_MEMORY_REGIONS_FOR_SERIALIZATION . with (
371370 |os_ipc_shared_memory_regions_for_serialization| {
372- let old_os_ipc_channels =
373- mem:: take ( & mut * os_ipc_channels_for_serialization. borrow_mut ( ) ) ;
374- let old_os_ipc_shared_memory_regions = mem:: take (
375- & mut * os_ipc_shared_memory_regions_for_serialization. borrow_mut ( ) ,
376- ) ;
377- let os_ipc_shared_memory_regions;
378- let os_ipc_channels;
379- {
380- bincode:: serialize_into ( & mut bytes, & data) ?;
381- os_ipc_channels = mem:: replace (
382- & mut * os_ipc_channels_for_serialization. borrow_mut ( ) ,
383- old_os_ipc_channels,
384- ) ;
385- os_ipc_shared_memory_regions = mem:: replace (
386- & mut * os_ipc_shared_memory_regions_for_serialization. borrow_mut ( ) ,
387- old_os_ipc_shared_memory_regions,
388- ) ;
389- } ;
371+ bincode:: serialize_into ( & mut bytes, & data) ?;
372+ let os_ipc_channels = os_ipc_channels_for_serialization. take ( ) ;
373+ let os_ipc_shared_memory_regions =
374+ os_ipc_shared_memory_regions_for_serialization. take ( ) ;
390375 Ok ( self . os_sender . send (
391376 & bytes[ ..] ,
392377 os_ipc_channels,
@@ -726,31 +711,27 @@ impl IpcMessage {
726711 }
727712
728713 /// Deserialize the raw data in the contained message into the inferred type.
729- pub fn to < T > ( mut self ) -> Result < T , bincode:: Error >
714+ pub fn to < T > ( self ) -> Result < T , bincode:: Error >
730715 where
731716 T : for < ' de > Deserialize < ' de > + Serialize ,
732717 {
733718 OS_IPC_CHANNELS_FOR_DESERIALIZATION . with ( |os_ipc_channels_for_deserialization| {
734719 OS_IPC_SHARED_MEMORY_REGIONS_FOR_DESERIALIZATION . with (
735720 |os_ipc_shared_memory_regions_for_deserialization| {
736- mem:: swap (
737- & mut * os_ipc_channels_for_deserialization. borrow_mut ( ) ,
738- & mut self . os_ipc_channels ,
739- ) ;
740- let old_ipc_shared_memory_regions_for_deserialization = mem:: replace (
741- & mut * os_ipc_shared_memory_regions_for_deserialization. borrow_mut ( ) ,
742- self . os_ipc_shared_memory_regions
743- . into_iter ( )
744- . map ( Some )
745- . collect ( ) ,
746- ) ;
721+ // Setup the thread local memory for deserialization to take it.
722+ * os_ipc_channels_for_deserialization. borrow_mut ( ) = self . os_ipc_channels ;
723+ * os_ipc_shared_memory_regions_for_deserialization. borrow_mut ( ) = self
724+ . os_ipc_shared_memory_regions
725+ . into_iter ( )
726+ . map ( Some )
727+ . collect ( ) ;
728+
747729 let result = bincode:: deserialize ( & self . data [ ..] ) ;
748- * os_ipc_shared_memory_regions_for_deserialization. borrow_mut ( ) =
749- old_ipc_shared_memory_regions_for_deserialization;
750- mem:: swap (
751- & mut * os_ipc_channels_for_deserialization. borrow_mut ( ) ,
752- & mut self . os_ipc_channels ,
753- ) ;
730+
731+ // Clear the shared memory
732+ let _ = os_ipc_shared_memory_regions_for_deserialization. take ( ) ;
733+ let _ = os_ipc_channels_for_deserialization. take ( ) ;
734+
754735 /* Error check comes after doing cleanup,
755736 * since we need the cleanup both in the success and the error cases. */
756737 result
0 commit comments