| author | wenzelm |
| Sat, 01 Feb 2014 21:09:53 +0100 | |
| changeset 55239 | 97921d23ebe3 |
| parent 46712 | 8650d9a95736 |
| child 56685 | 535d59d4ed12 |
| permissions | -rw-r--r-- |
| 38840 | 1 |
/* Title: Pure/Concurrent/volatile.scala |
|
45673
cd41e3903fbf
separate compilation of PIDE vs. Pure sources, which enables independent Scala library;
wenzelm
parents:
45667
diff
changeset
|
2 |
Module: PIDE |
| 38840 | 3 |
Author: Makarius |
4 |
||
5 |
Volatile variables. |
|
6 |
*/ |
|
7 |
||
8 |
package isabelle |
|
9 |
||
10 |
||
| 45248 | 11 |
object Volatile |
12 |
{
|
|
13 |
def apply[A](init: A): Volatile[A] = new Volatile(init) |
|
14 |
} |
|
15 |
||
16 |
||
| 46712 | 17 |
final class Volatile[A] private(init: A) |
| 38840 | 18 |
{
|
19 |
@volatile private var state: A = init |
|
| 43719 | 20 |
def apply(): A = state |
| 46687 | 21 |
def >> (f: A => A) { state = f(state) }
|
22 |
def >>>[B] (f: A => (B, A)): B = |
|
| 38840 | 23 |
{
|
24 |
val (result, new_state) = f(state) |
|
25 |
state = new_state |
|
26 |
result |
|
27 |
} |
|
28 |
} |
|
29 |