diff --git a/bytestring/common/src/-Platform.kt b/bytestring/common/src/-Platform.kt new file mode 100644 index 000000000..dfaae6840 --- /dev/null +++ b/bytestring/common/src/-Platform.kt @@ -0,0 +1,14 @@ +/* +* 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.txt file. +*/ +package kotlinx.io.bytestring + +/** + * Annotation indicating that the marked property is the subject of benign data race. + * LLVM does not support this notion, so on K/N platforms we alias it into `@Volatile` to prevent potential OoTA. + */ +@OptionalExpectation +@Target(AnnotationTarget.FIELD) +@OptIn(ExperimentalMultiplatform::class) +internal expect annotation class BenignDataRace() diff --git a/bytestring/common/src/ByteString.kt b/bytestring/common/src/ByteString.kt index 6066c9313..19ecef0d8 100644 --- a/bytestring/common/src/ByteString.kt +++ b/bytestring/common/src/ByteString.kt @@ -69,6 +69,7 @@ public class ByteString private constructor( public constructor(data: ByteArray, startIndex: Int = 0, endIndex: Int = data.size) : this(data.copyOfRange(startIndex, endIndex), null) + @BenignDataRace private var hashCode: Int = 0 public companion object { diff --git a/bytestring/native/src/-PlatformNative.kt b/bytestring/native/src/-PlatformNative.kt new file mode 100644 index 000000000..515c94010 --- /dev/null +++ b/bytestring/native/src/-PlatformNative.kt @@ -0,0 +1,10 @@ +/* +* 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.txt file. +*/ +package kotlinx.io.bytestring + +import kotlin.concurrent.* + +@Suppress("ACTUAL_WITHOUT_EXPECT") // This suppress can be removed in 2.0: KT-59355 +internal actual typealias BenignDataRace = Volatile