@@ -127,9 +127,10 @@ public open class JobSupport constructor(active: Boolean) : Job, ChildJob, Paren
127
127
// Note: use shared objects while we have no listeners
128
128
private val _state = atomic<Any ?>(if (active) EMPTY_ACTIVE else EMPTY_NEW )
129
129
130
- @Volatile
131
- @JvmField
132
- internal var parentHandle: ChildHandle ? = null
130
+ private val _parentHandle = atomic<ChildHandle ?>(null )
131
+ internal var parentHandle: ChildHandle ?
132
+ get() = _parentHandle .value
133
+ set(value) { _parentHandle .value = value }
133
134
134
135
// ------------ initialization ------------
135
136
@@ -1019,23 +1020,33 @@ public open class JobSupport constructor(active: Boolean) : Job, ChildJob, Paren
1019
1020
@Suppress(" UNCHECKED_CAST" )
1020
1021
private class Finishing (
1021
1022
override val list : NodeList ,
1022
- @Volatile
1023
- @JvmField var isCompleting : Boolean ,
1024
- @Volatile
1025
- @JvmField var rootCause : Throwable ? // NOTE: rootCause is kept even when SEALED
1023
+ isCompleting : Boolean ,
1024
+ rootCause : Throwable ?
1026
1025
) : SynchronizedObject(), Incomplete {
1027
- @Volatile
1028
- private var _exceptionsHolder : Any? = null // Contains null | Throwable | ArrayList | SEALED
1026
+ private val _isCompleting = atomic(isCompleting)
1027
+ var isCompleting: Boolean
1028
+ get() = _isCompleting .value
1029
+ set(value) { _isCompleting .value = value }
1030
+
1031
+ private val _rootCause = atomic(rootCause)
1032
+ var rootCause: Throwable ? // NOTE: rootCause is kept even when SEALED
1033
+ get() = _rootCause .value
1034
+ set(value) { _rootCause .value = value }
1035
+
1036
+ private val _exceptionsHolder = atomic<Any ?>(null )
1037
+ private var exceptionsHolder: Any? // Contains null | Throwable | ArrayList | SEALED
1038
+ get() = _exceptionsHolder .value
1039
+ set(value) { _exceptionsHolder .value = value }
1029
1040
1030
1041
// NotE: cannot be modified when sealed
1031
- val isSealed: Boolean get() = _exceptionsHolder == = SEALED
1042
+ val isSealed: Boolean get() = exceptionsHolder == = SEALED
1032
1043
val isCancelling: Boolean get() = rootCause != null
1033
1044
override val isActive: Boolean get() = rootCause == null // !isCancelling
1034
1045
1035
1046
// Seals current state and returns list of exceptions
1036
1047
// guarded by `synchronized(this)`
1037
1048
fun sealLocked (proposedException : Throwable ? ): List <Throwable > {
1038
- val list = when (val eh = _exceptionsHolder ) { // volatile read
1049
+ val list = when (val eh = exceptionsHolder ) { // volatile read
1039
1050
null -> allocateList()
1040
1051
is Throwable -> allocateList().also { it.add(eh) }
1041
1052
is ArrayList <* > -> eh as ArrayList <Throwable >
@@ -1044,7 +1055,7 @@ public open class JobSupport constructor(active: Boolean) : Job, ChildJob, Paren
1044
1055
val rootCause = this .rootCause // volatile read
1045
1056
rootCause?.let { list.add(0 , it) } // note -- rootCause goes to the beginning
1046
1057
if (proposedException != null && proposedException != rootCause) list.add(proposedException)
1047
- _exceptionsHolder = SEALED
1058
+ exceptionsHolder = SEALED
1048
1059
return list
1049
1060
}
1050
1061
@@ -1056,11 +1067,11 @@ public open class JobSupport constructor(active: Boolean) : Job, ChildJob, Paren
1056
1067
return
1057
1068
}
1058
1069
if (exception == = rootCause) return // nothing to do
1059
- when (val eh = _exceptionsHolder ) { // volatile read
1060
- null -> _exceptionsHolder = exception
1070
+ when (val eh = exceptionsHolder ) { // volatile read
1071
+ null -> exceptionsHolder = exception
1061
1072
is Throwable -> {
1062
1073
if (exception == = eh) return // nothing to do
1063
- _exceptionsHolder = allocateList().apply {
1074
+ exceptionsHolder = allocateList().apply {
1064
1075
add(eh)
1065
1076
add(exception)
1066
1077
@@ -1074,7 +1085,7 @@ public open class JobSupport constructor(active: Boolean) : Job, ChildJob, Paren
1074
1085
private fun allocateList () = ArrayList <Throwable >(4 )
1075
1086
1076
1087
override fun toString (): String =
1077
- " Finishing[cancelling=$isCancelling , completing=$isCompleting , rootCause=$rootCause , exceptions=$_exceptionsHolder , list=$list ]"
1088
+ " Finishing[cancelling=$isCancelling , completing=$isCompleting , rootCause=$rootCause , exceptions=$exceptionsHolder , list=$list ]"
1078
1089
}
1079
1090
1080
1091
private val Incomplete .isCancelling: Boolean
0 commit comments