Skip to content

Commit eb6c14f

Browse files
committed
LazyListIterableBase for Scala.js
1 parent efbbecc commit eb6c14f

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Scala (https://www.scala-lang.org)
3+
*
4+
* Copyright EPFL and Lightbend, Inc. dba Akka
5+
*
6+
* Licensed under Apache License 2.0
7+
* (http://www.apache.org/licenses/LICENSE-2.0).
8+
*
9+
* See the NOTICE file distributed with this work for
10+
* additional information regarding copyright ownership.
11+
*/
12+
13+
package scala.collection.immutable
14+
15+
import scala.language.`2.13`
16+
import language.experimental.captureChecking
17+
18+
/**
19+
* Base class for [[LazyList]] to split out code that uses concurrency utilities that are not available on Scala.js.
20+
*/
21+
abstract class LazyListIterableBase[+A] private[immutable] (initialTail: (AnyRef | Null)^) extends Iterable[A] with Serializable {
22+
/** See [[LazyList._head]] for the possible states of this field. */
23+
@volatile private var _tail: AnyRef^{this} | Null /* () => LazyList[A] | Thread | InRace | LazyList[A] | Null */ =
24+
caps.unsafe.unsafeAssumePure(initialTail)
25+
26+
private[immutable] def rawTail: AnyRef^{this} | Null = _tail
27+
28+
private[immutable] def setRawTail(value: AnyRef^): Unit = _tail = caps.unsafe.unsafeAssumePure(value)
29+
30+
private[immutable] def makeTailUpdater: LazyListIterableBase.TailUpdater = LazyListIterableBase.TailUpdater()
31+
}
32+
33+
private[immutable] object LazyListIterableBase {
34+
import caps.unsafe.unsafeAssumePure
35+
36+
final class TailUpdater {
37+
@inline def compareAndSet(ll: LazyListIterableBase[?]^, expected: AnyRef^, value: AnyRef^): Boolean =
38+
if (ll._tail eq expected) { ll._tail = unsafeAssumePure(value); true } else false
39+
@inline def getAndSet(ll: LazyListIterableBase[?]^, value: (AnyRef | Null)^): (AnyRef | Null)^ = {
40+
val old = ll._tail
41+
ll._tail = value.asInstanceOf[AnyRef | Null]
42+
old
43+
}
44+
}
45+
46+
def isCurrentThread(t: Thread^): Boolean = true
47+
48+
def InRace(t: Thread^): InRace = throw new Exception("unreachable")
49+
50+
final class InRace private[LazyListIterableBase] (val owner: Thread) {
51+
def await(): Unit = ()
52+
def countDown(): Unit = ()
53+
}
54+
}

0 commit comments

Comments
 (0)