-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathMemory.java
More file actions
49 lines (36 loc) · 1.23 KB
/
Copy pathMemory.java
File metadata and controls
49 lines (36 loc) · 1.23 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
package loop.runtime;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
/**
* Support class for software transactional memory and global immutable
* shared state.
*
* @author [email protected] (Dhanji R. Prasanna)
*/
public class Memory {
public static Map<Object, Object> unsafe = new HashMap<Object, Object>();
private static final ConcurrentMap<String, Object> cells = new ConcurrentHashMap<String, Object>();
public static Object insert(Object key, Object value) {
assert key instanceof String;
return cells.put((String) key, value);
}
public static Object update(Object key, Object old, Object value) {
assert key instanceof String;
return cells.replace((String) key, old, value);
}
public static Object delete(Object key) {
assert key instanceof String;
return cells.remove(key);
}
public static Object lookupOrInsert(Object key, Object value) {
assert key instanceof String;
Object previous = cells.putIfAbsent((String) key, value);
return previous == null ? value : previous;
}
public static Object lookup(Object key) {
assert key instanceof String;
return cells.get(key);
}
}