[K/N] Stabilization of Atomics API
`AtomicInt`, `AtomicLong`, `AtomicReference` and `AtomicNativePtr` classes were moved to `kotlin.concurrent` package. The corresponding classes from `kotlin.native.concurrent` were deprecated with warning since Kotlin 1.9.
In order to prepare for further commonization of Atomics API the following changes were made:
* `kotlin.concurrent.AtomicInt`:
* `increment(): Unit` and `decrement(): Unit` methods were deprecated with error
* New methods were added: `incrementAndGet(): Int` , `decrementAndGet(): Int`, `getAndIncrement(): Int`, `getAndDecrement(): Int`, `getAndSet(newValue: Int): Int`
* `kotlin.concurrent.AtomicLong`:
* `increment(): Unit` and `decrement(): Unit` methods were deprecated with error
* New methods were added: `incrementAndGet(): Long`, `decrementAndGet(): Long`, `getAndIncrement(): Long`, `getAndDecrement(): Long`, `getAndSet(newValue: Long): Long`
* Deprecated `AtomicLong()` constructor with default parameter value
* For all atomic classes `compareAndSwap` method was renamed to `compareAndExchange`
See KT-58074 for more details.
Merge-request: KT-MR-9272
Merged-by: Maria Sokolova <maria.sokolova@jetbrains.com>
This commit is contained in:
@@ -25,7 +25,7 @@ package kotlin.text.regex
|
||||
|
||||
import kotlin.experimental.ExperimentalNativeApi
|
||||
import kotlin.collections.associate
|
||||
import kotlin.native.concurrent.AtomicReference
|
||||
import kotlin.concurrent.AtomicReference
|
||||
import kotlin.native.concurrent.freeze
|
||||
import kotlin.native.BitSet
|
||||
import kotlin.native.FreezingIsDeprecated
|
||||
@@ -653,7 +653,7 @@ internal abstract class AbstractCharClass : SpecialToken() {
|
||||
fun getPredefinedClass(name: String, negative: Boolean): AbstractCharClass {
|
||||
val charClass = classCacheMap[name] ?: throw PatternSyntaxException("No such character class")
|
||||
val cachedClass = classCache[charClass.ordinal].value ?: run {
|
||||
classCache[charClass.ordinal].compareAndSwap(null, charClass.factory().freeze())
|
||||
classCache[charClass.ordinal].compareAndExchange(null, charClass.factory().freeze())
|
||||
classCache[charClass.ordinal].value!!
|
||||
}
|
||||
return cachedClass.getValue(negative)
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package kotlin.concurrent
|
||||
|
||||
// Only for compatibility with shared K/N stdlib code
|
||||
|
||||
internal class AtomicReference<T>(public var value: T) {
|
||||
public fun compareAndExchange(expected: T, new: T): T {
|
||||
if (value == expected) {
|
||||
val old = value
|
||||
value = new
|
||||
return old
|
||||
}
|
||||
return value
|
||||
}
|
||||
public fun compareAndSet(expected: T, new: T): Boolean {
|
||||
if (value == expected) {
|
||||
value = new
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -12,21 +12,3 @@ internal val Any?.isFrozen
|
||||
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
internal inline fun <T> T.freeze(): T = this
|
||||
|
||||
internal class AtomicReference<T>(public var value: T) {
|
||||
public fun compareAndSwap(expected: T, new: T): T {
|
||||
if (value == expected) {
|
||||
val old = value
|
||||
value = new
|
||||
return old
|
||||
}
|
||||
return value
|
||||
}
|
||||
public fun compareAndSet(expected: T, new: T): Boolean {
|
||||
if (value == expected) {
|
||||
value = new
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user