15 lines
397 B
Kotlin
15 lines
397 B
Kotlin
package net.sergeych.tools
|
|
|
|
/**
|
|
* Thread-safe multiplatform counter
|
|
*/
|
|
@Suppress("unused")
|
|
class AtomicCounter(initialValue: Long = 0) : AtomicValue<Long>(initialValue) {
|
|
|
|
fun incrementAndGet(): Long = op { ++actualValue }
|
|
fun getAndIncrement(): Long = op { actualValue++ }
|
|
|
|
fun decrementAndGet(): Long = op { --actualValue }
|
|
|
|
fun getAndDecrement(): Long = op { actualValue-- }
|
|
} |