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

Downlink fix #47

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package swim.runtime.downlink;

import java.util.Map;
import java.util.concurrent.atomic.AtomicLongFieldUpdater;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
import swim.concurrent.Cont;
import swim.concurrent.Conts;
Expand All @@ -34,8 +35,17 @@ public class ValueDownlinkModel extends DemandDownlinkModem<ValueDownlinkView<?>
protected static final int STATEFUL = 1 << 0;
static final AtomicReferenceFieldUpdater<ValueDownlinkModel, Value> STATE =
AtomicReferenceFieldUpdater.newUpdater(ValueDownlinkModel.class, Value.class, "state");
static final AtomicLongFieldUpdater<ValueDownlinkModel> EPOCH =
AtomicLongFieldUpdater.newUpdater(ValueDownlinkModel.class, "epoch");
static final AtomicLongFieldUpdater<ValueDownlinkModel> SENT_EPOCH =
AtomicLongFieldUpdater.newUpdater(ValueDownlinkModel.class, "sentEpoch");

protected int flags;
protected volatile Value state;
@SuppressWarnings("FieldMayBeFinal")
private volatile long epoch = 0;
@SuppressWarnings("FieldMayBeFinal")
private volatile long sentEpoch = Long.MIN_VALUE;

public ValueDownlinkModel(Uri meshUri, Uri hostUri, Uri nodeUri, Uri laneUri,
float prio, float rate, Value body) {
Expand Down Expand Up @@ -147,13 +157,15 @@ final class ValueDownlinkRelaySet extends DownlinkRelay<ValueDownlinkModel, Valu
Value newValue;
Object oldObject;
Object newObject;
private final long epoch;

ValueDownlinkRelaySet(ValueDownlinkModel model, EventMessage message, Cont<EventMessage> cont, Value newValue) {
super(model, 4);
this.message = message;
this.cont = cont;
this.oldValue = newValue;
this.newValue = newValue;
this.epoch = -1;
}

ValueDownlinkRelaySet(ValueDownlinkModel model, Stage stage, Value newValue) {
Expand All @@ -162,6 +174,7 @@ final class ValueDownlinkRelaySet extends DownlinkRelay<ValueDownlinkModel, Valu
this.cont = null;
this.oldValue = newValue;
this.newValue = newValue;
this.epoch = ValueDownlinkModel.EPOCH.getAndIncrement(model);
}

ValueDownlinkRelaySet(ValueDownlinkModel model, Value newValue) {
Expand All @@ -170,6 +183,7 @@ final class ValueDownlinkRelaySet extends DownlinkRelay<ValueDownlinkModel, Valu
this.cont = null;
this.oldValue = newValue;
this.newValue = newValue;
this.epoch = ValueDownlinkModel.EPOCH.getAndIncrement(model);
}

@Override
Expand Down Expand Up @@ -249,7 +263,13 @@ protected void done() {
if (this.message != null) {
this.model.cueDown();
} else {
this.model.cueUp();
final long current = epoch;
final long newLastSent = ValueDownlinkModel.SENT_EPOCH.updateAndGet(
model, e -> Math.max(current, e));

if (current == newLastSent) {
this.model.cueUp();
}
}
if (this.cont != null) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package swim.runtime.lane;

import java.util.Map;
import java.util.concurrent.atomic.AtomicLongFieldUpdater;
import swim.api.Link;
import swim.api.data.ValueData;
import swim.concurrent.Cont;
Expand All @@ -31,11 +32,20 @@

public class ValueLaneModel extends WarpLaneModel<ValueLaneView<?>, ValueLaneUplink> {

static final AtomicLongFieldUpdater<ValueLaneModel> EPOCH =
AtomicLongFieldUpdater.newUpdater(ValueLaneModel.class, "epoch");
static final AtomicLongFieldUpdater<ValueLaneModel> SENT_EPOCH =
AtomicLongFieldUpdater.newUpdater(ValueLaneModel.class, "sentEpoch");

static final int RESIDENT = 1 << 0;
static final int TRANSIENT = 1 << 1;
static final int SIGNED = 1 << 2;
protected int flags;
protected ValueData<Value> data;
@SuppressWarnings("FieldMayBeFinal")
private volatile long epoch = 0;
@SuppressWarnings("FieldMayBeFinal")
private volatile long sentEpoch = Long.MIN_VALUE;

ValueLaneModel(int flags) {
this.flags = flags;
Expand Down Expand Up @@ -169,13 +179,15 @@ final class ValueLaneRelaySet extends LaneRelay<ValueLaneModel, ValueLaneView<?>
Object oldObject;
Value newValue;
Object newObject;
private final long epoch;

ValueLaneRelaySet(ValueLaneModel model, CommandMessage message, Cont<CommandMessage> cont, Value newValue) {
super(model, 4);
this.link = null;
this.message = message;
this.cont = cont;
this.newValue = newValue;
this.epoch = ValueLaneModel.EPOCH.getAndIncrement(model);
}

ValueLaneRelaySet(ValueLaneModel model, Link link, Value newValue) {
Expand All @@ -184,6 +196,7 @@ final class ValueLaneRelaySet extends LaneRelay<ValueLaneModel, ValueLaneView<?>
this.message = null;
this.cont = null;
this.newValue = newValue;
this.epoch = ValueLaneModel.EPOCH.getAndIncrement(model);
}

ValueLaneRelaySet(ValueLaneModel model, Stage stage, Value newValue) {
Expand All @@ -192,6 +205,7 @@ final class ValueLaneRelaySet extends LaneRelay<ValueLaneModel, ValueLaneView<?>
this.message = null;
this.cont = null;
this.newValue = newValue;
this.epoch = ValueLaneModel.EPOCH.getAndIncrement(model);
}

@Override
Expand Down Expand Up @@ -262,7 +276,12 @@ protected boolean runPhase(ValueLaneView<?> view, int phase, boolean preemptive)

@Override
protected void done() {
this.model.cueDown();
final long current = epoch;
final long newLastSent = ValueLaneModel.SENT_EPOCH.updateAndGet(
model, e -> Math.max(current, e));
if (current == newLastSent) {
this.model.cueDown();
}
if (this.cont != null) {
try {
this.cont.bind(this.message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public void queueUp(ListLinkDelta delta) {
public void pushUp(ListLinkDelta delta) {
queueUp(delta);
do {
final int oldStatus = this.status;
final int newStatus = oldStatus | FEEDING_UP;
final long oldStatus = this.status;
final long newStatus = oldStatus | FEEDING_UP;
if (oldStatus != newStatus) {
if (STATUS.compareAndSet(this, oldStatus, newStatus)) {
this.linkContext.feedUp();
Expand Down
Loading