Skip to content

reduce the size of arcs from 2 words to 1 #8867

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/libstd/unstable/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use vec;
/// An atomically reference counted pointer.
///
/// Enforces no shared-memory safety.
#[unsafe_no_drop_flag]
pub struct UnsafeArc<T> {
data: *mut ArcData<T>,
}
Expand Down Expand Up @@ -221,8 +222,9 @@ impl<T: Send> Clone for UnsafeArc<T> {
impl<T> Drop for UnsafeArc<T>{
fn drop(&self) {
unsafe {
// Happens when destructing an unwrapper's handle and from `#[unsafe_no_drop_flag]`
if self.data.is_null() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at this, where is self.data set to null? I don't remember if destructors zero out the whole structure or just the drop flag, but it seems like without the drop flag this could be run twice and self.data is non-null both times?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you use #[unsafe_no_drop_flag], it zeroes the whole structure instead of the drop flag. That's how it's defined, or it wouldn't be useful.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah that makes sense.

return; // Happens when destructing an unwrapper's handle.
return
}
let mut data: ~ArcData<T> = cast::transmute(self.data);
// Must be acquire+release, not just release, to make sure this
Expand Down Expand Up @@ -440,6 +442,12 @@ mod tests {
use super::{Exclusive, UnsafeArc, atomically};
use task;
use util;
use sys::size_of;

#[test]
fn test_size() {
assert_eq!(size_of::<UnsafeArc<[int, ..10]>>(), size_of::<*[int, ..10]>());
}

#[test]
fn test_atomically() {
Expand Down