SpinLockSynchronizedState.close now synchronized too
This commit is contained in:
parent
6ea651ce6d
commit
5f6823cfb9
@ -82,12 +82,16 @@ public /* open */ class SpinLockSynchronizedState
|
||||
@ManualStateManipulation
|
||||
@Override
|
||||
public final void close() {
|
||||
switch (this._currentState.compareAndExchange(State.OPEN, State.CLOSED)) {
|
||||
case CLOSED:
|
||||
this.throwClosed();
|
||||
case IN_USE:
|
||||
this.throwInUse();
|
||||
case OPEN:
|
||||
while (true) {
|
||||
switch (this._currentState.compareAndExchange(State.OPEN, State.CLOSED)) {
|
||||
case CLOSED:
|
||||
this.throwClosed();
|
||||
case IN_USE:
|
||||
Thread.onSpinWait();
|
||||
continue;
|
||||
case OPEN:
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -26,10 +26,6 @@ public class OwnedSpinLockSynchronizedState : SpinLockSynchronizedState {
|
||||
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 {
|
||||
val base = super.toString()
|
||||
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 {
|
||||
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