Skip to content

Commit ed71a7b

Browse files
authored
Fix deprecation warning (#457)
1 parent 064ad9a commit ed71a7b

File tree

1 file changed

+25
-23
lines changed

1 file changed

+25
-23
lines changed

src/bytes.rs

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,33 +1023,35 @@ unsafe fn shallow_clone_vec(
10231023
// `Release` is used synchronize with other threads that
10241024
// will load the `arc` field.
10251025
//
1026-
// If the `compare_and_swap` fails, then the thread lost the
1026+
// If the `compare_exchange` fails, then the thread lost the
10271027
// 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`
10291029
// that happened in the other thread and the `Shared`
10301030
// 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+
}
10421054
}
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)
10531055
}
10541056

10551057
unsafe fn release_shared(ptr: *mut Shared) {

0 commit comments

Comments
 (0)