Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions bytestring/common/src/-Platform.kt
Original file line number Diff line number Diff line change
@@ -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()
1 change: 1 addition & 0 deletions bytestring/common/src/ByteString.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions bytestring/native/src/-PlatformNative.kt
Original file line number Diff line number Diff line change
@@ -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