Skip to content

Commit

Permalink
Replace AtomicBoolean with volatile boolean field. (#796)
Browse files Browse the repository at this point in the history
Atomic's are good when you need CAS. If you need only read/write from different threads, volatile is enough.
  • Loading branch information
turbanoff committed Jan 16, 2023
1 parent 6e94df5 commit 4f57697
Showing 1 changed file with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import java.io.PrintWriter;
import java.nio.charset.Charset;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicBoolean;

import org.jline.terminal.spi.Pty;
import org.jline.utils.ClosedException;
Expand Down Expand Up @@ -146,23 +145,23 @@ public boolean paused() {
private static class InputStreamWrapper extends NonBlockingInputStream {

private final NonBlockingInputStream in;
private final AtomicBoolean closed = new AtomicBoolean();
private volatile boolean closed;

protected InputStreamWrapper(NonBlockingInputStream in) {
this.in = in;
}

@Override
public int read(long timeout, boolean isPeek) throws IOException {
if (closed.get()) {
if (closed) {
throw new ClosedException();
}
return in.read(timeout, isPeek);
}

@Override
public void close() throws IOException {
closed.set(true);
closed = true;
}
}

Expand Down

0 comments on commit 4f57697

Please sign in to comment.