Skip to content

Commit ee5cfb0

Browse files
committed
Don't use unkillable in UnsafeArc dtor when there's no unwrapper. Close #8382.
1 parent ecfc9a8 commit ee5cfb0

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

src/libstd/unstable/sync.rs

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -229,20 +229,22 @@ impl<T> Drop for UnsafeAtomicRcBox<T>{
229229
if self.data.is_null() {
230230
return; // Happens when destructing an unwrapper's handle.
231231
}
232-
do task::unkillable {
233-
let mut data: ~AtomicRcBoxData<T> = cast::transmute(self.data);
234-
// Must be acquire+release, not just release, to make sure this
235-
// doesn't get reordered to after the unwrapper pointer load.
236-
let old_count = data.count.fetch_sub(1, SeqCst);
237-
assert!(old_count >= 1);
238-
if old_count == 1 {
239-
// Were we really last, or should we hand off to an
240-
// unwrapper? It's safe to not xchg because the unwrapper
241-
// will set the unwrap lock *before* dropping his/her
242-
// reference. In effect, being here means we're the only
243-
// *awake* task with the data.
244-
match data.unwrapper.take(Acquire) {
245-
Some(~(message,response)) => {
232+
let mut data: ~AtomicRcBoxData<T> = cast::transmute(self.data);
233+
// Must be acquire+release, not just release, to make sure this
234+
// doesn't get reordered to after the unwrapper pointer load.
235+
let old_count = data.count.fetch_sub(1, SeqCst);
236+
assert!(old_count >= 1);
237+
if old_count == 1 {
238+
// Were we really last, or should we hand off to an
239+
// unwrapper? It's safe to not xchg because the unwrapper
240+
// will set the unwrap lock *before* dropping his/her
241+
// reference. In effect, being here means we're the only
242+
// *awake* task with the data.
243+
match data.unwrapper.take(Acquire) {
244+
Some(~(message,response)) => {
245+
let cell = Cell::new((message, response, data));
246+
do task::unkillable {
247+
let (message, response, data) = cell.take();
246248
// Send 'ready' and wait for a response.
247249
message.send(());
248250
// Unkillable wait. Message guaranteed to come.
@@ -253,13 +255,13 @@ impl<T> Drop for UnsafeAtomicRcBox<T>{
253255
// Other task was killed. drop glue takes over.
254256
}
255257
}
256-
None => {
257-
// drop glue takes over.
258-
}
259258
}
260-
} else {
261-
cast::forget(data);
259+
None => {
260+
// drop glue takes over.
261+
}
262262
}
263+
} else {
264+
cast::forget(data);
263265
}
264266
}
265267
}

0 commit comments

Comments
 (0)