Skip to content

Commit 0c52fe8

Browse files
committed
Remove some unnecessary synchronized blocks
`rootCause` is atomic anyway.
1 parent 970da72 commit 0c52fe8

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

kotlinx-coroutines-core/common/src/JobSupport.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ public open class JobSupport constructor(active: Boolean) : Job, ChildJob, Paren
476476
* to check for an exception, but that logic would need to manually handle the final state, which is
477477
* less straightforward.
478478
*/
479-
val rootCause = (state as? Finishing)?.let { synchronized(it) { it.rootCause } }
479+
val rootCause = (state as? Finishing)?.rootCause
480480
if (rootCause == null) {
481481
/**
482482
* There is no known root cause yet, so we can add the node to the list of state handlers.
@@ -906,7 +906,7 @@ public open class JobSupport constructor(active: Boolean) : Job, ChildJob, Paren
906906
// atomically transition to finishing & completing state
907907
val finishing = state as? Finishing ?: Finishing(list, false, null)
908908
// must synchronize updates to finishing state
909-
var notifyRootCause: Throwable? = null
909+
val notifyRootCause: Throwable?
910910
synchronized(finishing) {
911911
// check if this state is already completing
912912
if (finishing.isCompleting) return COMPLETING_ALREADY
@@ -1035,7 +1035,7 @@ public open class JobSupport constructor(active: Boolean) : Job, ChildJob, Paren
10351035
val rootCause = when (val latestState = this.state) {
10361036
is Finishing -> {
10371037
// The state is still incomplete, so we need to notify the child about the completion cause.
1038-
synchronized(latestState) { latestState.rootCause }
1038+
latestState.rootCause
10391039
}
10401040
else -> {
10411041
/** Since the list is already closed for [onCancelling], the job is either Finishing or

0 commit comments

Comments
 (0)