Skip to content
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

Add a reference counted container #41

Merged
merged 10 commits into from
Sep 24, 2022
Merged

Add a reference counted container #41

merged 10 commits into from
Sep 24, 2022

Conversation

notgull
Copy link
Contributor

@notgull notgull commented Sep 18, 2022

This pull requests resolves #37 by adding Arc and Weak types to the portable-atomic-util crate that use portable_atomic::AtomicUsize in their operation. The goal is to allow for portable using of Arc on platforms that may have allocation but not atomics. Arduino AVR comes to mind for this.

These new types are based off of the ones in libstd, but I explicitly avoid using unstable features. I do not implement unstable functions, like new_uninit. I also avoided certain functions like new_cyclic and take_mut because I didn't get around to it.

@notgull
Copy link
Contributor Author

notgull commented Sep 19, 2022

It looks like, since embedded targets don't come with an allocator, building portable-atomic-util fails on those targets. I've just removed --workspace from build.sh for now

Copy link
Owner

@taiki-e taiki-e left a comment

Choose a reason for hiding this comment

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

Thanks! This looks great to me.

portable-atomic-util/src/lib.rs Outdated Show resolved Hide resolved
tools/build.sh Outdated Show resolved Hide resolved
@notgull
Copy link
Contributor Author

notgull commented Sep 23, 2022

Hmm, it's failing on nightly when building with bpfeb-unknown-none with errors like these:

 error[E0599]: no method named `fetch_add` found for reference `&portable_atomic::AtomicUsize` in the current scope
   --> portable-atomic-util/src/arc.rs:152:46
    |
152 |         let old_size = self.inner().strong().fetch_add(1, Relaxed);
    |            

Looks like, on BPF targets, the compare_exchange-type functions are unavailable.

@taiki-e
Copy link
Owner

taiki-e commented Sep 24, 2022

Ah, it's #29.

Could you add args+=(--exclude portable-atomic-util) to the following line for now?

bpf*) ;; # TODO

@notgull
Copy link
Contributor Author

notgull commented Sep 24, 2022

Thanks!

Copy link
Owner

@taiki-e taiki-e left a comment

Choose a reason for hiding this comment

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

Thanks again!

@taiki-e
Copy link
Owner

taiki-e commented Sep 24, 2022

bors r+

@bors
Copy link
Contributor

bors bot commented Sep 24, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a replacement for std::sync::Arc that uses portable-atomic::AtomicUsize
2 participants