Skip to content

Commit

Permalink
[UNDERTOW-2356] PreChunkedStreamSinkConduit
Browse files Browse the repository at this point in the history
  • Loading branch information
baranowb committed Dec 5, 2024
1 parent f294bd3 commit 6cf2480
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.nio.channels.ClosedChannelException;
import java.nio.channels.FileChannel;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;

import static org.xnio.Bits.allAreClear;
import static org.xnio.Bits.anyAreSet;
Expand All @@ -52,7 +53,9 @@ public class PreChunkedStreamSinkConduit extends AbstractStreamSinkConduit<Strea
private static final int FLAG_WRITES_SHUTDOWN = 1;
private static final int FLAG_FINISHED = 1 << 2;

int state = 0;
private volatile int state = 0;
private static final AtomicIntegerFieldUpdater<PreChunkedStreamSinkConduit> stateUpdater = AtomicIntegerFieldUpdater.newUpdater(
PreChunkedStreamSinkConduit.class, "state");
final ChunkReader<PreChunkedStreamSinkConduit> chunkReader;

/**
Expand Down Expand Up @@ -183,7 +186,7 @@ public boolean flush() throws IOException {
}

private void invokeFinishListener() {
state |= FLAG_FINISHED;
stateUpdater.accumulateAndGet(this, FLAG_FINISHED, (current, flag) -> current | flag);
if (finishListener != null) {
finishListener.handleEvent(this);
}
Expand All @@ -197,7 +200,7 @@ public void terminateWrites() throws IOException {
if (chunkReader.getChunkRemaining() != -1) {
throw UndertowMessages.MESSAGES.chunkedChannelClosedMidChunk();
}
state |= FLAG_WRITES_SHUTDOWN;
stateUpdater.accumulateAndGet(this, FLAG_WRITES_SHUTDOWN, (current, flag) -> current | flag);
}

@Override
Expand Down

0 comments on commit 6cf2480

Please sign in to comment.