-
Notifications
You must be signed in to change notification settings - Fork 7
Removing *_owned methods #30
Comments
How about removing all First of all, in my experience, Second, if you really need a |
It is true that But I definitely don't want to give up on fn insert(&self, key: K, value: V) {
epoch::pin(|scope| {
let (found, mut left, mut right) = self.search(&key, scope);
if found {
return;
}
let height = self.random_height();
let mut new = Owned::new(Node::new(key, value, height));
let p = loop {
new.tower[0].store(right[0], Relaxed);
match left[0].tower[0].compare_and_set_owned(right[0], new, SeqCst, scope) {
Ok(p) => break p,
Err((_, n)) => new = n,
}
let (found, l, r) = self.search(&new.key, scope);
if found {
// Here, `new` is automatically destroyed.
return;
} else {
left = l;
right = r;
}
};
// Continue building the tower of `p`...
})
} I think the only reason we haven't needed |
In your use case, why not first converting an |
It's possible, but then I have to manually destroy the Another nice thing about let mut new = Owned::new(Node::new(Block::new()));
self.traverse_chain(&mut new.block, node, scope);
loop {
match page.node.compare_and_set_owned(node, new, SeqCst, scope) {
Ok(_) => return,
Err((prev, n)) => {
node = prev;
new = n;
}
}
// The CAS operation failed. Now we have to traverse the delta chain from scratch and refill
// the block.
// Here we have mutable access to `new.block`, which wouldn't be possible with `Ptr`.
new.block.clear();
self.traverse_chain(&mut new.block, node, scope);
} |
I'm convinced with your "delta chain consolidation" example (of which I don't know the details, though). I would suggest:
After reading the current API, I'd like to suggest one more API change to CAS. How about using |
Would
I guess we would implement it for
Does this mean one would have to write |
|
I'm a bit torn on this. On one hand, it is true that But on the other hand, if @Vtec234, what do you think about all this?
I'm afraid that would get a little bit too verbose: let ord = CompareAndSetOrdering {
success: SeqCst,
failure: Relaxed,
};
a.compare_and_set(b, c, ord, scope); C++ solves this problem simply by using overloaded |
Sorry for delay :)
|
Maybe. But I don't think a user will ever have to explicitly type it, just like they don't have to type a
I was actually thinking of the same thing - that would be a very nice naming scheme. :) |
I agree. Let's go for |
I'm okay with the changes as long as the API stays as expressive as it is, i.e. nothing that was previously possible becomes impossible or appreciably more difficult to express. One thing to note is that |
By the way, I think it's better to resolve this issue before reaching 0.1.0, because it will break API too much :) If we're agreed upon the changes, I can prepare a PR. @stjepang do you have a working branch? |
@jeehoonkang I don't have a working branch. If you'd like to implement this - feel free to go ahead! |
Have a look at the following methods on
Atomic<T>
we currently implement:Click to expand
It's interesting that
swap_owned
is missing, although it is not stricly speaking necessary:a.swap_owned(o, ord, scope)
would be equivalent toa.swap(o.into_ptr(scope), ord, scope)
. But, for the sake of consistency and convenience, we should probably haveswap_owned
as well.There's a lot of duplication. We have one set of functions for
Ptr
and another forOwned
. Let's try to unify them. First, we could introduce a trait that is implemented byPtr
andOwned
:Second, let's clarify the return value of
compare_and_set_owned
. Instead of returningwe could return something like
But let's make the error type a little bit more generic:
Finally, now we're ready to eliminate all those
*_owned
functions. The new set of store/swap/compare-and-set functions is much smaller than the one at the beginning of this comment.The obvious downside is that the
OwnedOrPtr<T>
trait makes function signatures slightly more complicated. But maybe it's not too bad...? Maybe it's worth it in the end? What do you think?The text was updated successfully, but these errors were encountered: