@@ -119,8 +119,6 @@ private val UNLOCK_FAIL = Symbol("UNLOCK_FAIL")
119
119
private val SELECT_SUCCESS = Symbol (" SELECT_SUCCESS" )
120
120
private val LOCKED = Symbol (" LOCKED" )
121
121
private val UNLOCKED = Symbol (" UNLOCKED" )
122
- private val RESUME_QUIESCENT = Symbol (" RESUME_QUIESCENT" )
123
- private val RESUME_ACTIVE = Symbol (" RESUME_ACTIVE" )
124
122
125
123
private val EmptyLocked = Empty (LOCKED )
126
124
private val EmptyUnlocked = Empty (UNLOCKED )
@@ -136,9 +134,6 @@ internal class MutexImpl(locked: Boolean) : Mutex, SelectClause2<Any?, Mutex> {
136
134
// shared objects while we have no waiters
137
135
private val _state = atomic<Any ?>(if (locked) EmptyLocked else EmptyUnlocked )
138
136
139
- // resumeNext is: RESUME_QUIESCENT | RESUME_ACTIVE | ResumeReq
140
- private val _resumeNext = atomic<Any >(RESUME_QUIESCENT )
141
-
142
137
public override val isLocked: Boolean get() {
143
138
_state .loop { state ->
144
139
when (state) {
@@ -332,16 +327,8 @@ internal class MutexImpl(locked: Boolean) : Mutex, SelectClause2<Any?, Mutex> {
332
327
} else {
333
328
val token = (waiter as LockWaiter ).tryResumeLockWaiter()
334
329
if (token != null ) {
335
- // successfully resumed waiter that now is holding the lock
336
- // we must immediately transfer ownership to the next waiter, because this coroutine
337
- // might try to lock it again after unlock returns do to StackOverflow avoidance code
338
- // and its attempts to take a lock must be queued.
339
330
state.owner = waiter.owner ? : LOCKED
340
- // StackOverflow avoidance code
341
- if (startResumeNext(waiter, token)) {
342
- waiter.completeResumeLockWaiter(token)
343
- finishResumeNext()
344
- }
331
+ waiter.completeResumeLockWaiter(token)
345
332
return
346
333
}
347
334
}
@@ -351,43 +338,6 @@ internal class MutexImpl(locked: Boolean) : Mutex, SelectClause2<Any?, Mutex> {
351
338
}
352
339
}
353
340
354
- private class ResumeReq (
355
- @JvmField val waiter : LockWaiter ,
356
- @JvmField val token : Any
357
- )
358
-
359
- private fun startResumeNext (waiter : LockWaiter , token : Any ): Boolean {
360
- _resumeNext .loop { resumeNext ->
361
- when {
362
- resumeNext == = RESUME_QUIESCENT -> {
363
- // this is never concurrent, because only one thread is holding mutex and trying to resume
364
- // next waiter, so no need to CAS here
365
- _resumeNext .value = RESUME_ACTIVE
366
- return true
367
- }
368
- resumeNext == = RESUME_ACTIVE ->
369
- if (_resumeNext .compareAndSet(resumeNext, ResumeReq (waiter, token))) return false
370
- else -> error(" Cannot happen" )
371
- }
372
- }
373
- }
374
-
375
- private fun finishResumeNext () {
376
- // also a resumption loop to fulfill requests of inner resume invokes
377
- _resumeNext .loop { resumeNext ->
378
- when {
379
- resumeNext == = RESUME_ACTIVE ->
380
- if (_resumeNext .compareAndSet(resumeNext, RESUME_QUIESCENT )) return
381
- resumeNext is ResumeReq -> {
382
- // this is never concurrently, only one thread is finishing, so no need to CAS here
383
- _resumeNext .value = RESUME_ACTIVE
384
- resumeNext.waiter.completeResumeLockWaiter(resumeNext.token)
385
- }
386
- else -> error(" Cannot happen" )
387
- }
388
- }
389
- }
390
-
391
341
override fun toString (): String {
392
342
_state .loop { state ->
393
343
when (state) {
0 commit comments