blob: 5bfecf2eec2f2b1713d3de463fdc7f5f0973c387 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
package java.util.concurrent.atomic
class AtomicLong(private[this] var value: Long) extends Number with Serializable {
def this() = this(0L)
final def get(): Long = value
final def set(newValue: Long): Unit =
value = newValue
final def lazySet(newValue: Long): Unit =
set(newValue)
final def getAndSet(newValue: Long): Long = {
val old = value
value = newValue
old
}
final def compareAndSet(expect: Long, update: Long): Boolean = {
if (expect != value) false else {
value = update
true
}
}
final def weakCompareAndSet(expect: Long, update: Long): Boolean =
compareAndSet(expect, update)
final def getAndIncrement(): Long =
getAndAdd(1L)
final def getAndDecrement(): Long =
getAndAdd(-1L)
@inline final def getAndAdd(delta: Long): Long = {
val old = value
value = old + delta
old
}
final def incrementAndGet(): Long =
addAndGet(1L)
final def decrementAndGet(): Long =
addAndGet(-1L)
@inline final def addAndGet(delta: Long): Long = {
val newValue = value + delta
value = newValue
newValue
}
override def toString(): String =
value.toString()
def intValue(): Int = value.toInt
def longValue(): Long = value
def floatValue(): Float = value.toFloat
def doubleValue(): Double = value.toDouble
}
|