@@ -127,9 +127,9 @@ private val LOCKED = Symbol("LOCKED")
127
127
private val UNLOCKED = Symbol (" UNLOCKED" )
128
128
129
129
@SharedImmutable
130
- private val EmptyLocked = Empty (LOCKED )
130
+ private val EMPTY_LOCKED = Empty (LOCKED )
131
131
@SharedImmutable
132
- private val EmptyUnlocked = Empty (UNLOCKED )
132
+ private val EMPTY_UNLOCKED = Empty (UNLOCKED )
133
133
134
134
private class Empty (
135
135
@JvmField val locked : Any
@@ -140,7 +140,7 @@ private class Empty(
140
140
internal class MutexImpl (locked : Boolean ) : Mutex, SelectClause2<Any?, Mutex> {
141
141
// State is: Empty | LockedQueue | OpDescriptor
142
142
// shared objects while we have no waiters
143
- private val _state = atomic<Any ?>(if (locked) EmptyLocked else EmptyUnlocked )
143
+ private val _state = atomic<Any ?>(if (locked) EMPTY_LOCKED else EMPTY_UNLOCKED )
144
144
145
145
public override val isLocked: Boolean get() {
146
146
_state .loop { state ->
@@ -164,7 +164,7 @@ internal class MutexImpl(locked: Boolean) : Mutex, SelectClause2<Any?, Mutex> {
164
164
when (state) {
165
165
is Empty -> {
166
166
if (state.locked != = UNLOCKED ) return false
167
- val update = if (owner == null ) EmptyLocked else Empty (
167
+ val update = if (owner == null ) EMPTY_LOCKED else Empty (
168
168
owner
169
169
)
170
170
if (_state .compareAndSet(state, update)) return true
@@ -195,7 +195,7 @@ internal class MutexImpl(locked: Boolean) : Mutex, SelectClause2<Any?, Mutex> {
195
195
_state .compareAndSet(state, LockedQueue (state.locked))
196
196
} else {
197
197
// try lock
198
- val update = if (owner == null ) EmptyLocked else Empty (owner)
198
+ val update = if (owner == null ) EMPTY_LOCKED else Empty (owner)
199
199
if (_state .compareAndSet(state, update)) { // locked
200
200
cont.resume(Unit )
201
201
return @sc
@@ -272,21 +272,21 @@ internal class MutexImpl(locked: Boolean) : Mutex, SelectClause2<Any?, Mutex> {
272
272
// This is Harris's RDCSS (Restricted Double-Compare Single Swap) operation
273
273
private inner class PrepareOp (private val op : AtomicOp <* >) : OpDescriptor() {
274
274
override fun perform (affected : Any? ): Any? {
275
- val update: Any = if (op.isDecided) EmptyUnlocked else op // restore if was already decided
275
+ val update: Any = if (op.isDecided) EMPTY_UNLOCKED else op // restore if was already decided
276
276
(affected as MutexImpl )._state .compareAndSet(this , update)
277
277
return null // ok
278
278
}
279
279
}
280
280
281
281
override fun prepare (op : AtomicOp <* >): Any? {
282
282
val prepare = PrepareOp (op)
283
- if (! mutex._state .compareAndSet(EmptyUnlocked , prepare)) return LOCK_FAIL
283
+ if (! mutex._state .compareAndSet(EMPTY_UNLOCKED , prepare)) return LOCK_FAIL
284
284
return prepare.perform(mutex)
285
285
}
286
286
287
287
override fun complete (op : AtomicOp <* >, failure : Any? ) {
288
- val update = if (failure != null ) EmptyUnlocked else {
289
- if (owner == null ) EmptyLocked else Empty (owner)
288
+ val update = if (failure != null ) EMPTY_UNLOCKED else {
289
+ if (owner == null ) EMPTY_LOCKED else Empty (owner)
290
290
}
291
291
mutex._state .compareAndSet(op, update)
292
292
}
@@ -322,7 +322,7 @@ internal class MutexImpl(locked: Boolean) : Mutex, SelectClause2<Any?, Mutex> {
322
322
check(state.locked != = UNLOCKED ) { " Mutex is not locked" }
323
323
else
324
324
check(state.locked == = owner) { " Mutex is locked by ${state.locked} but expected $owner " }
325
- if (_state .compareAndSet(state, EmptyUnlocked )) return
325
+ if (_state .compareAndSet(state, EMPTY_UNLOCKED )) return
326
326
}
327
327
is OpDescriptor -> state.perform(this )
328
328
is LockedQueue -> {
@@ -406,7 +406,7 @@ internal class MutexImpl(locked: Boolean) : Mutex, SelectClause2<Any?, Mutex> {
406
406
will fail anyway.
407
407
*/
408
408
val success = queue.isEmpty
409
- val update: Any = if (success) EmptyUnlocked else queue
409
+ val update: Any = if (success) EMPTY_UNLOCKED else queue
410
410
(affected as MutexImpl )._state .compareAndSet(this @UnlockOp, update)
411
411
/*
412
412
`perform` invocation from the original `unlock` invocation may be coming too late, when
0 commit comments