@@ -8,11 +8,12 @@ The idiomatic way to use atomic operations in Kotlin.
8
8
9
9
* Code it like ` AtomicReference/Int/Long ` , but run it in production like ` AtomicReference/Int/LongFieldUpdater ` .
10
10
* Use Kotlin-specific extensions (e.g. inline ` updateAndGet ` and ` getAndUpdate ` functions).
11
- * Compile-time dependency only (no runtime dependencies).
12
- * Post-compilation bytecode transformer that declares all the relevant field updaters for you.
13
- * Cross-platform
14
- * Kotlin/JS and Kotlin/Native (single-thread only) are supported, too.
15
- * However, they work as a library dependency at the moment (unlike Kotlin/JVM).
11
+ * Compile-time dependency only (no runtime dependencies) on Kotlin/JVM.
12
+ * Post-compilation bytecode transformer that declares all the relevant field updaters for you.
13
+ * See [ JVM build setup] ( #jvm-build-setup ) for details.
14
+ * [ Multiplatform] ( #multiplatform )
15
+ * [ Kotlin/JS] ( #javascript ) and [ Kotlin/Native] ( #native ) are supported.
16
+ * However, they work as a library dependencies at the moment (unlike Kotlin/JVM).
16
17
* This enables writing common Kotlin code with atomics.
17
18
18
19
## Example
@@ -84,7 +85,11 @@ public var foo: T // public val/var
84
85
set(value) { _foo .value = value }
85
86
```
86
87
87
- ## Maven build setup
88
+ ## JVM build setup
89
+
90
+ Building with [ Maven] ( #maven ) and [ Gradle] ( #gradle ) is supported for Kotlin/JVM.
91
+
92
+ ## Maven
88
93
89
94
Declare AtomicFU version:
90
95
@@ -154,7 +159,7 @@ which is then transformed to a regular `classes` directory to be used later by t
154
159
</build >
155
160
```
156
161
157
- ## Gradle build setup
162
+ ## Gradle
158
163
159
164
You will need Gradle 4.0 or later for the following snippets to work.
160
165
Add and apply AtomicFU plugin:
@@ -183,11 +188,9 @@ Install bytecode transformation pipeline so that compiled classes from `classes`
183
188
transformed to a different ` classes-post-atomicfu ` directory to be used later by tests and delivery.
184
189
185
190
``` groovy
186
- def CLASSES_POST_ATOMICFU = file("$buildDir/classes-post-atomicfu/main")
187
-
188
191
atomicFU {
189
192
inputFiles = sourceSets.main.output.classesDirs
190
- outputDir = CLASSES_POST_ATOMICFU
193
+ outputDir = file("$buildDir/classes-post-atomicfu/main")
191
194
classPath = sourceSets.main.runtimeClasspath
192
195
variant = "FU" // "VH" to use Java 9 VarHandle, "BOTH" to produce multi-version code
193
196
}
@@ -198,11 +201,91 @@ jar.dependsOn atomicFU
198
201
199
202
jar {
200
203
mainSpec.sourcePaths.clear() // hack to clear existing paths
201
- from files(CLASSES_POST_ATOMICFU , sourceSets.main.output.resourcesDir)
204
+ from files(atomicFU.outputDir , sourceSets.main.output.resourcesDir)
202
205
}
203
206
```
204
207
205
- ## VarHandles with Java 9 (optional)
208
+ ## Multiplatform
209
+
210
+ AtomicFU is also available for [ Kotlin/JS] ( #javascript ) and [ Kotlin/Native] ( #native ) . If you write
211
+ a common code that should get compiled or different platforms, add ` org.jetbrains.kotlinx:atomicfu-common `
212
+ to your common code dependencies.
213
+
214
+ ### JavaScript
215
+
216
+ This library is available for Kotlin/JS via Bintray JCenter and Maven Central as
217
+ [ ` org.jetbrains.kotlinx:atomicfu-js ` ] ( https://bintray.com/kotlin/kotlinx/kotlinx.atomicfu ) and via NPM
218
+ as [ ` kotlinx.atomicfu ` ] ( https://www.npmjs.com/package/kotlinx-atomicfu ) .
219
+ It is a regular library and you should declare a normal dependency, no plugin is needed nor available.
220
+ Both Maven and Gradle can be used.
221
+
222
+ Since Kotlin/JS does not generally provide binary compatibility between versions,
223
+ you should use the same version of Kotlin compiler.
224
+ See [ gradle.properties] ( gradle.properties ) .
225
+
226
+ ### Native
227
+
228
+ This library is available for Kotlin/Native via Bintray JCenter and Maven Central as
229
+ [ ` org.jetbrains.kotlinx:atomicfu-native ` ] ( https://bintray.com/kotlin/kotlinx/kotlinx.atomicfu ) .
230
+ It is a regular library and you should declare a normal dependency, no plugin is needed nor available.
231
+ Only single-threaded code (JS-style) is currently supported.
232
+
233
+ Kotlin/Native supports only Gradle version 4.7 or later
234
+ and you should use ` kotlin-platform-native ` plugin like this.
235
+ First of all, you'll need to enable Gradle metadata in your
236
+ ` settings.gradle ` file:
237
+
238
+ ``` groovy
239
+ enableFeaturePreview('GRADLE_METADATA')
240
+ ```
241
+
242
+ Then, you'll need to apply the corresponding plug and add apropriate dependencies in your
243
+ ` build.gradle ` file:
244
+
245
+ ``` groovy
246
+ buildscript {
247
+ repositories {
248
+ jcenter()
249
+ maven { url 'https://plugins.gradle.org/m2/' }
250
+ maven { url 'https://dl.bintray.com/jetbrains/kotlin-native-dependencies' }
251
+ }
252
+
253
+ dependencies {
254
+ classpath "org.jetbrains.kotlin:kotlin-native-gradle-plugin:$kotlin_native_version"
255
+ }
256
+
257
+ }
258
+
259
+ apply plugin: 'kotlin-platform-native'
260
+
261
+ repositories {
262
+ jcenter()
263
+ }
264
+
265
+ dependencies {
266
+ implementation 'org.jetbrains.kotlinx:atomicfu-native:0.11.0'
267
+ }
268
+
269
+ sourceSets {
270
+ main {
271
+ component {
272
+ target "ios_arm64", "ios_arm32", "ios_x64", "macos_x64", "linux_x64", "mingw_x64"
273
+ outputKinds = [EXECUTABLE]
274
+ }
275
+ }
276
+ }
277
+ ```
278
+
279
+ Since Kotlin/Native does not generally provide binary compatibility between versions,
280
+ you should use the same version of Kotlin/Native compiler as was used to build AtomicFU.
281
+ Add an appropriate ` kotlin_native_version ` to your ` gradle.properties ` file.
282
+ See [ gradle.properties] ( gradle.properties ) in AtomicFu project.
283
+
284
+ ## Additional features
285
+
286
+ AtomicFU provides some additional features that you can optionally use.
287
+
288
+ ### VarHandles with Java 9 (optional)
206
289
207
290
AtomicFU can produce code that is using Java 9
208
291
[ VarHandle] ( http://download.java.net/java/jdk9/docs/api/java/lang/invoke/VarHandle.html )
@@ -213,7 +296,7 @@ You can also create [JEP 238](http://openjdk.java.net/jeps/238) multi-release ja
213
296
Set ` variant ` configuration option to ` BOTH ` and configure ` Multi-Release: true ` attribute
214
297
in the resulting jar manifest.
215
298
216
- ## Testing lock-free data structures (optional)
299
+ ### Testing lock-free data structures on JVM (optional)
217
300
218
301
You can optionally test lock-freedomness of lock-free data structures using ` LockFreedomTestEnvironment ` class.
219
302
See example in [ ` LockFreeQueueLFTest ` ] ( atomicfu-test/src/test/kotlin/kotlinx/atomicfu/test/LockFreeQueueLFTest.kt ) .
0 commit comments