448156 Fixed INACTIVE race in IteratingCallback
Additional cleanups of ICB code
This commit is contained in:
parent
34782005b2
commit
679b8d30f8
|
@ -18,6 +18,7 @@
|
|||
|
||||
package org.eclipse.jetty.util;
|
||||
|
||||
import java.nio.channels.ClosedChannelException;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
/**
|
||||
|
@ -339,11 +340,11 @@ public abstract class IteratingCallback implements Callback
|
|||
break processing;
|
||||
|
||||
case PROCESSING:
|
||||
if (_state.compareAndSet(State.PROCESSING, State.SUCCEEDED))
|
||||
{
|
||||
onCompleteSuccess();
|
||||
break processing;
|
||||
}
|
||||
if (!_state.compareAndSet(State.PROCESSING, State.SUCCEEDED))
|
||||
continue acting;
|
||||
_iterate=false;
|
||||
onCompleteSuccess();
|
||||
break processing;
|
||||
|
||||
default:
|
||||
throw new IllegalStateException("state="+state);
|
||||
|
@ -367,8 +368,8 @@ public abstract class IteratingCallback implements Callback
|
|||
{
|
||||
loop: while (true)
|
||||
{
|
||||
State current = _state.get();
|
||||
switch (current)
|
||||
State state = _state.get();
|
||||
switch (state)
|
||||
{
|
||||
case PROCESSING:
|
||||
{
|
||||
|
@ -407,7 +408,7 @@ public abstract class IteratingCallback implements Callback
|
|||
@Override
|
||||
public void failed(Throwable x)
|
||||
{
|
||||
while (true)
|
||||
loop: while (true)
|
||||
{
|
||||
State state = _state.get();
|
||||
switch (state)
|
||||
|
@ -418,15 +419,21 @@ public abstract class IteratingCallback implements Callback
|
|||
case CLOSED:
|
||||
{
|
||||
// Already complete!.
|
||||
return;
|
||||
break loop;
|
||||
}
|
||||
case LOCKED:
|
||||
{
|
||||
Thread.yield();
|
||||
continue loop;
|
||||
}
|
||||
default:
|
||||
{
|
||||
if (_state.compareAndSet(state, State.FAILED))
|
||||
{
|
||||
onCompleteFailure(x);
|
||||
return;
|
||||
}
|
||||
if (!_state.compareAndSet(state, State.FAILED))
|
||||
continue loop;
|
||||
|
||||
onCompleteFailure(x);
|
||||
break loop;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -434,7 +441,7 @@ public abstract class IteratingCallback implements Callback
|
|||
|
||||
public void close()
|
||||
{
|
||||
while (true)
|
||||
loop: while (true)
|
||||
{
|
||||
State state = _state.get();
|
||||
switch (state)
|
||||
|
@ -443,17 +450,26 @@ public abstract class IteratingCallback implements Callback
|
|||
case SUCCEEDED:
|
||||
case FAILED:
|
||||
{
|
||||
if (_state.compareAndSet(state, State.CLOSED))
|
||||
return;
|
||||
break;
|
||||
if (!_state.compareAndSet(state, State.CLOSED))
|
||||
continue loop;
|
||||
break loop;
|
||||
}
|
||||
case CLOSED:
|
||||
{
|
||||
break loop;
|
||||
}
|
||||
case LOCKED:
|
||||
{
|
||||
Thread.yield();
|
||||
continue loop;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
if (_state.compareAndSet(state, State.CLOSED))
|
||||
{
|
||||
onCompleteFailure(new IllegalStateException("Closed with pending callback " + this));
|
||||
return;
|
||||
}
|
||||
if (!_state.compareAndSet(state, State.CLOSED))
|
||||
continue loop;
|
||||
onCompleteFailure(new ClosedChannelException());
|
||||
break loop;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -507,14 +523,20 @@ public abstract class IteratingCallback implements Callback
|
|||
return true;
|
||||
|
||||
case SUCCEEDED:
|
||||
if (_state.compareAndSet(State.SUCCEEDED, State.IDLE))
|
||||
return true;
|
||||
break;
|
||||
if (!_state.compareAndSet(State.SUCCEEDED, State.IDLE))
|
||||
continue;
|
||||
_iterate=false;
|
||||
return true;
|
||||
|
||||
case FAILED:
|
||||
if (_state.compareAndSet(State.FAILED, State.IDLE))
|
||||
return true;
|
||||
break;
|
||||
if (!_state.compareAndSet(State.FAILED, State.IDLE))
|
||||
continue;
|
||||
_iterate=false;
|
||||
return true;
|
||||
|
||||
case LOCKED:
|
||||
Thread.yield();
|
||||
continue;
|
||||
|
||||
default:
|
||||
return false;
|
||||
|
|
Loading…
Reference in New Issue