dsgryazin
02/21/2018, 7:06 PMMutex.kt
internal class MutexImpl(locked: Boolean) : Mutex, SelectClause2<Any?, Mutex> {
// State is: Empty | LockedQueue | OpDescriptor
// shared objects while we have no waiters
private val _state = atomic<Any?>(if (locked) EmptyLocked else EmptyUnlocked)
// resumeNext is: RESUME_QUIESCENT | RESUME_ACTIVE | ResumeReq
private val _resumeNext = atomic<Any>(RESUME_QUIESCENT)
public override val isLocked: Boolean get() {
_state.loop { state ->
when (state) {
is Empty -> return state.locked !== UNLOCKED
is LockedQueue -> return true
is OpDescriptor -> state.perform(this) // help
else -> error("Illegal state $state")
}
}
}
1. Please, explain, what is meant by each of Empty | LockedQueue | OpDescriptor
?
2. What is for resumeNext is: RESUME_QUIESCENT | RESUME_ACTIVE | ResumeReq
?
3. What means the `help`comment in is OpDescriptor -> state.perform(this) // help
? 😅elizarov
02/21/2018, 7:09 PMAny?
OpDescriptor
class and AtomicOp
in the same file.dsgryazin
02/21/2018, 7:17 PMOpDescriptor
is for. Is there a popular preparation of Mutex?elizarov
02/21/2018, 7:50 PMOpDescriptor
for that. It is only use when Mutex is a part of select
, which you can ignore at first. Assume that OpDescriptor
never happens there