@@ -1023,33 +1023,35 @@ unsafe fn shallow_clone_vec(
1023
1023
// `Release` is used synchronize with other threads that
1024
1024
// will load the `arc` field.
1025
1025
//
1026
- // If the `compare_and_swap ` fails, then the thread lost the
1026
+ // If the `compare_exchange ` fails, then the thread lost the
1027
1027
// race to promote the buffer to shared. The `Acquire`
1028
- // ordering will synchronize with the `compare_and_swap `
1028
+ // ordering will synchronize with the `compare_exchange `
1029
1029
// that happened in the other thread and the `Shared`
1030
1030
// pointed to by `actual` will be visible.
1031
- let actual = atom. compare_and_swap ( ptr as _ , shared as _ , Ordering :: AcqRel ) ;
1032
-
1033
- if actual as usize == ptr as usize {
1034
- // The upgrade was successful, the new handle can be
1035
- // returned.
1036
- return Bytes {
1037
- ptr : offset,
1038
- len,
1039
- data : AtomicPtr :: new ( shared as _ ) ,
1040
- vtable : & SHARED_VTABLE ,
1041
- } ;
1031
+ match atom. compare_exchange ( ptr as _ , shared as _ , Ordering :: AcqRel , Ordering :: Acquire ) {
1032
+ Ok ( actual) => {
1033
+ debug_assert ! ( actual as usize == ptr as usize ) ;
1034
+ // The upgrade was successful, the new handle can be
1035
+ // returned.
1036
+ Bytes {
1037
+ ptr : offset,
1038
+ len,
1039
+ data : AtomicPtr :: new ( shared as _ ) ,
1040
+ vtable : & SHARED_VTABLE ,
1041
+ }
1042
+ }
1043
+ Err ( actual) => {
1044
+ // The upgrade failed, a concurrent clone happened. Release
1045
+ // the allocation that was made in this thread, it will not
1046
+ // be needed.
1047
+ let shared = Box :: from_raw ( shared) ;
1048
+ mem:: forget ( * shared) ;
1049
+
1050
+ // Buffer already promoted to shared storage, so increment ref
1051
+ // count.
1052
+ shallow_clone_arc ( actual as _ , offset, len)
1053
+ }
1042
1054
}
1043
-
1044
- // The upgrade failed, a concurrent clone happened. Release
1045
- // the allocation that was made in this thread, it will not
1046
- // be needed.
1047
- let shared = Box :: from_raw ( shared) ;
1048
- mem:: forget ( * shared) ;
1049
-
1050
- // Buffer already promoted to shared storage, so increment ref
1051
- // count.
1052
- shallow_clone_arc ( actual as _ , offset, len)
1053
1055
}
1054
1056
1055
1057
unsafe fn release_shared ( ptr : * mut Shared ) {
0 commit comments