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

Fix concurrency modification exception [AStream] #73

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
14 changes: 9 additions & 5 deletions src/com/stuypulse/stuylib/streams/angles/PollingAStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
public class PollingAStream implements AStream, AutoCloseable {

private Notifier mPoller;
private final Notifier mPoller;
private volatile Angle mResult;

/**
Expand All @@ -31,19 +31,23 @@ public PollingAStream(AStream stream, double dt) {
}

mResult = Angle.kNull;
mPoller = new Notifier(() -> mResult = stream.get());
mPoller = new Notifier(() -> this.set(stream.get()));
mPoller.startPeriodic(dt);
}

public Angle get() {
private final synchronized set(Angle result) {
mResult = result;
}

public final synchronized Angle get() {
return mResult;
}

protected void finalize() {
protected final synchronized void finalize() {
close();
}

public void close() {
public final synchronized void close() {
mPoller.close();
mResult = Angle.kNull;
}
Expand Down