SpinLockSynchronizedState.close now synchronized too
This commit is contained in:
parent
6ea651ce6d
commit
5f6823cfb9
@ -82,12 +82,16 @@ public /* open */ class SpinLockSynchronizedState
|
|||||||
@ManualStateManipulation
|
@ManualStateManipulation
|
||||||
@Override
|
@Override
|
||||||
public final void close() {
|
public final void close() {
|
||||||
switch (this._currentState.compareAndExchange(State.OPEN, State.CLOSED)) {
|
while (true) {
|
||||||
case CLOSED:
|
switch (this._currentState.compareAndExchange(State.OPEN, State.CLOSED)) {
|
||||||
this.throwClosed();
|
case CLOSED:
|
||||||
case IN_USE:
|
this.throwClosed();
|
||||||
this.throwInUse();
|
case IN_USE:
|
||||||
case OPEN:
|
Thread.onSpinWait();
|
||||||
|
continue;
|
||||||
|
case OPEN:
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -26,10 +26,6 @@ public class OwnedSpinLockSynchronizedState : SpinLockSynchronizedState {
|
|||||||
throw IllegalStateException("Object is closed: ${this._owner}")
|
throw IllegalStateException("Object is closed: ${this._owner}")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun throwInUse(): Nothing {
|
|
||||||
throw IllegalStateException("Failed close object because it is in use: ${this._owner}")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
val base = super.toString()
|
val base = super.toString()
|
||||||
return base.substring(0, base.length - 1) + " of ${this._owner}>"
|
return base.substring(0, base.length - 1) + " of ${this._owner}>"
|
||||||
|
|||||||
@ -4,8 +4,4 @@ internal abstract class `SpinLockSynchronizedState$Errors` : CloseableState.Exte
|
|||||||
protected open fun throwClosed(): Nothing {
|
protected open fun throwClosed(): Nothing {
|
||||||
throw IllegalStateException("Object is closed")
|
throw IllegalStateException("Object is closed")
|
||||||
}
|
}
|
||||||
|
|
||||||
protected open fun throwInUse(): Nothing {
|
|
||||||
throw IllegalStateException("Failed close object because it is in use")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user