SpinLockSynchronizedState.close now synchronized too

This commit is contained in:
Andrew Golovashevich 2025-10-03 20:05:40 +03:00
parent 6ea651ce6d
commit 5f6823cfb9
3 changed files with 10 additions and 14 deletions

View File

@ -82,12 +82,16 @@ public /* open */ class SpinLockSynchronizedState
@ManualStateManipulation
@Override
public final void close() {
while (true) {
switch (this._currentState.compareAndExchange(State.OPEN, State.CLOSED)) {
case CLOSED:
this.throwClosed();
case IN_USE:
this.throwInUse();
Thread.onSpinWait();
continue;
case OPEN:
return;
}
}
}

View File

@ -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}>"

View File

@ -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")
}
}