Skip to content

Added Volatile Types #12063

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 3 commits into from
Closed

Added Volatile Types #12063

wants to merge 3 commits into from

Conversation

thehydroimpulse
Copy link
Contributor

This PR adds a nicer wrapper around the volatile intrinsics. It also places the new volatile module under unstable.

I added the following types:

  • VolatilePtr
  • VolatileInt
  • VolatileBool

There is also static types that deal with the specialized types (such as VolatileBool and VolatileInt)

  • INIT_VOLATILE_BOOL
  • INIT_VOLATILE_INT

These can be used basically the same way Atomics are used (I think).

Somethings to consider:

  • I'm not sure if the static API/method is correct
  • Only two specialized types exist (int and bool). Other types are super easy to add.
  • The VolatilePtr doesn't work with pure values, because there needs to be a destination pointer for the intrinsics. One way I can think of allowing this directly (without using another variable) is to reserve a new memory region, with the size based on the passed type, and copying the data over to that region.

I added tests for all the current functionality and they all pass on my machine.

Let me know if there's anything else I need to change, add, remove, etc...


pub struct VolatileUint {
v: uint
}
Copy link
Member

Choose a reason for hiding this comment

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

These fields should all be private.

Copy link
Member

Choose a reason for hiding this comment

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

There seems to be no implementation of a VolatileUint

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahh yes. I'll remove the other struct definitions for now, since they don't have implementations.

@thehydroimpulse
Copy link
Contributor Author

Thanks for the pointers @alexcrichton. I have included those changes in the latest commit (or I think I have addressed them correctly). Let me know if there's anything else that needs to be addressed.

}

#[inline]
pub fn take(&self) -> bool {
Copy link
Member

Choose a reason for hiding this comment

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

bools and ints don't need take, they can be called load because these types don't obey the same ownership semantics as ~T

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, that's right.

@thehydroimpulse
Copy link
Contributor Author

Just messed up my fork. Gonna close this and submit a new PR.

bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 25, 2022
fix: Fall back to parameter definitions on error types in signature help

Fixes  rust-lang#10432
flip1995 pushed a commit to flip1995/rust that referenced this pull request Jan 11, 2024
Add `.front()` to `get_first` lint description

Fix rust-lang#12063

changelog: none
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.

3 participants