Address PR comments
Motivation: Clean up code to fix PR comments. Modification: Rename a method and add javadocs. Result: Code is cleaner and mode documented.
This commit is contained in:
parent
8b0ea44f02
commit
b5abfdd1f8
@ -74,7 +74,7 @@ public class BBuf extends Rc<BBuf> {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BBuf copy(Thread recipient, Drop<BBuf> drop) {
|
||||
protected BBuf transferOwnership(Thread recipient, Drop<BBuf> drop) {
|
||||
BBuf copy = new BBuf(segment.withOwnerThread(recipient), drop);
|
||||
copy.read = read;
|
||||
copy.write = write;
|
||||
@ -87,7 +87,7 @@ public class BBuf extends Rc<BBuf> {
|
||||
MemorySegment transferSegment = segment.withOwnerThread(TRANSFER_OWNER);
|
||||
return new BBuf(transferSegment, NO_DROP) {
|
||||
@Override
|
||||
protected BBuf copy(Thread recipient, Drop<BBuf> drop) {
|
||||
protected BBuf transferOwnership(Thread recipient, Drop<BBuf> drop) {
|
||||
overwriteMemorySegmentOwner(transferSegment, recipient);
|
||||
BBuf copy = new BBuf(transferSegment, drop);
|
||||
copy.read = outer.read;
|
||||
|
@ -45,7 +45,21 @@ public abstract class Rc<T extends Rc<T>> implements AutoCloseable {
|
||||
return new TransferSend<>(prepareSend(), drop);
|
||||
}
|
||||
|
||||
protected abstract T copy(Thread recipient, Drop<T> drop);
|
||||
/**
|
||||
* Transfer the ownership of this Rc, to the given recipient thread.
|
||||
* This Rc is invalidated but without disposing of its internal state.
|
||||
* Then a new Rc with the given owner is produced in its stead.
|
||||
* <p>
|
||||
* This method is called by {@link Send} implementations.
|
||||
* These implementations will ensure that the transfer of ownership (the calling of this
|
||||
* method) happens-before the new owner begins accessing the new object.
|
||||
* This ensures that the new Rc is safely published to the new owners.
|
||||
*
|
||||
* @param recipient The new owner of the state represented by this Rc.
|
||||
* @param drop The drop object that knows how to dispose of the state represented by this Rc.
|
||||
* @return A new Rc instance that is exactly the same as this Rc, except it has the new owner.
|
||||
*/
|
||||
protected abstract T transferOwnership(Thread recipient, Drop<T> drop);
|
||||
|
||||
protected T prepareSend() {
|
||||
return self();
|
||||
|
@ -1,6 +1,5 @@
|
||||
package io.netty.buffer.b2;
|
||||
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.invoke.VarHandle;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
@ -45,7 +44,7 @@ class RendezvousSend<T extends Rc<T>> implements Send<T> {
|
||||
throw new IllegalStateException("Already sent.");
|
||||
}
|
||||
recipientLatch.await();
|
||||
incoming = outgoing.copy(recipient, drop);
|
||||
incoming = outgoing.transferOwnership(recipient, drop);
|
||||
drop.accept(incoming);
|
||||
sentLatch.countDown();
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ class TransferSend<T extends Rc<T>> implements Send<T> {
|
||||
if (!RECEIVED.compareAndSet(this, false, true)) {
|
||||
throw new IllegalStateException("This object has already been received.");
|
||||
}
|
||||
var copy = outgoing.copy(Thread.currentThread(), drop);
|
||||
var copy = outgoing.transferOwnership(Thread.currentThread(), drop);
|
||||
drop.accept(copy);
|
||||
return copy;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user