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

No get_mut method on AtomicPtr #154

Open
jrmuizel opened this issue Jul 2, 2020 · 4 comments
Open

No get_mut method on AtomicPtr #154

jrmuizel opened this issue Jul 2, 2020 · 4 comments

Comments

@jrmuizel
Copy link

jrmuizel commented Jul 2, 2020

The AtomicPtr implementation seems to be missing an implementation of get_mut

@Restioson
Copy link
Contributor

Would a PR to implement this be accepted?

@hawkw
Copy link
Member

hawkw commented Sep 11, 2020

@Restioson

Would a PR to implement this be accepted?

Yes, that would be great! It should probably be simulated using Atomic::unsync_load:

loom/src/rt/atomic.rs

Lines 200 to 216 in 73e6c14

/// Loads a value from the atomic cell without performing synchronization
pub(crate) fn unsync_load(&self, location: Location) -> T {
rt::execution(|execution| {
let state = self.state.get_mut(&mut execution.objects);
state
.unsync_loaded_locations
.track(location, &execution.threads);
// An unsync load counts as a "read" access
state.track_unsync_load(&execution.threads);
// Return the value
let index = index(state.cnt - 1);
T::from_u64(state.stores[index].value)
})
}

We might want to add get_mut methods to the other loom atomic types, like AtomicUsize, since they also have get_mut methods.

@carllerche
Copy link
Member

If we do get_mut() it needs to return a guard type and not the ptr itself. loom needs to know when the ptr is no longer accessible in order to ensure correctness. This is why other types have with_mut but that can be changed to a guard type return as well instead of a closure.

@Restioson
Copy link
Contributor

Would the logic be essentially the same as with_mut otherwise? The cleanup moved to the drop impl and the setup to the get_mut function?

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

No branches or pull requests

4 participants