-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathLazyListIterableBase.scala
More file actions
54 lines (43 loc) · 1.91 KB
/
LazyListIterableBase.scala
File metadata and controls
54 lines (43 loc) · 1.91 KB
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
/*
* Scala (https://www.scala-lang.org)
*
* Copyright EPFL and Lightbend, Inc. dba Akka
*
* Licensed under Apache License 2.0
* (http://www.apache.org/licenses/LICENSE-2.0).
*
* See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
*/
package scala.collection.immutable
import scala.language.`2.13`
import language.experimental.captureChecking
/**
* Base class for [[LazyList]] to split out code that uses concurrency utilities that are not available on Scala.js.
*/
abstract class LazyListIterableBase[+A] private[immutable] (initialTail: (AnyRef | Null)^) extends Iterable[A] with Serializable {
/** See [[LazyList._head]] for the possible states of this field. */
@volatile private var _tail: AnyRef^{this} | Null /* () => LazyList[A] | Thread | InRace | LazyList[A] | Null */ =
caps.unsafe.unsafeAssumePure(initialTail)
private[immutable] def rawTail: AnyRef^{this} | Null = _tail
private[immutable] def setRawTail(value: AnyRef^): Unit = _tail = caps.unsafe.unsafeAssumePure(value)
private[immutable] def makeTailUpdater: LazyListIterableBase.TailUpdater = LazyListIterableBase.TailUpdater()
}
private[immutable] object LazyListIterableBase {
import caps.unsafe.unsafeAssumePure
final class TailUpdater {
@inline def compareAndSet(ll: LazyListIterableBase[?]^, expected: AnyRef^, value: AnyRef^): Boolean =
if (ll._tail eq expected) { ll._tail = unsafeAssumePure(value); true } else false
@inline def getAndSet(ll: LazyListIterableBase[?]^, value: (AnyRef | Null)^): (AnyRef | Null)^ = {
val old = ll._tail
ll._tail = value.asInstanceOf[AnyRef | Null]
old
}
}
def isCurrentThread(t: Thread^): Boolean = true
def InRace(t: Thread^): InRace = throw new Exception("unreachable")
final class InRace private[LazyListIterableBase] (val owner: Thread) {
def await(): Unit = ()
def countDown(): Unit = ()
}
}