root/trunk/ProjectFortress/src/com/sun/fortress/interpreter/env/ValueNode.java @ 2738

Revision 2738, 3.6 KB (checked in by chf, 15 months ago)

Some cleanups and refactorings. More to come

Line 
1/*******************************************************************************
2    Copyright 2008 Sun Microsystems, Inc.,
3    4150 Network Circle, Santa Clara, California 95054, U.S.A.
4    All rights reserved.
5
6    U.S. Government Rights - Commercial software.
7    Government users are subject to the Sun Microsystems, Inc. standard
8    license agreement and applicable provisions of the FAR and its supplements.
9
10    Use is subject to license terms.
11
12    This distribution may include materials developed by third parties.
13
14    Sun, Sun Microsystems, the Sun logo and Java are trademarks or registered
15    trademarks of Sun Microsystems, Inc. in the U.S. and other countries.
16******************************************************************************/
17
18package com.sun.fortress.interpreter.env;
19
20import com.sun.fortress.interpreter.evaluator.values.FValue;
21import com.sun.fortress.interpreter.evaluator.tasks.FortressTaskRunner;
22import com.sun.fortress.exceptions.transactions.AbortedException;
23import com.sun.fortress.interpreter.evaluator.transactions.ReadSet;
24import com.sun.fortress.interpreter.evaluator.transactions.Transaction;
25
26import java.util.ArrayList;
27import java.util.List;
28
29public class ValueNode {
30    ValueNode old;
31    FValue value;
32    Transaction writer;
33    ReadSet readers;
34
35    public  ValueNode(FValue v, Transaction w, ReadSet r, ValueNode o) {
36        old = o;
37        value = v;
38        writer = w;
39        readers = new ReadSet(r);
40    }
41
42    ValueNode() {
43        old = null;
44        value = null;
45        writer = null;
46        readers = new ReadSet();
47    }
48
49    public static final ValueNode nullValueNode = new ValueNode();
50
51    public String toString() {
52        if (this == nullValueNode)
53            return "nullValueNode";
54        else return "ValueNode[" + value +  ":" + writer +  "::" + readers + "]" ;
55    }
56
57    public FValue getValue() {  return value;}
58    public Transaction getWriter() { return writer;}
59    public ReadSet getReaders() { return readers;}
60    public ValueNode getOld() { return old; }
61
62    public void addReader() {
63        Transaction me  = FortressTaskRunner.getTransaction();
64        if (!readers.add(me)) {
65            me.abort();
66            throw new AbortedException(me, "ReadSet Sealed : " + readers );
67        }
68    }
69           
70    public void AbortAllReaders() {
71        if (this == nullValueNode)
72            throw new RuntimeException(Thread.currentThread().getName() + "Trying to abort all the readers of the null value node");
73
74                readers.seal();
75                for (Transaction r : readers) {
76                        r.abort();
77                }
78    }
79
80    public void AbortWriter() {
81        if (writer != null)  {
82            writer.abort();
83        }
84    }
85
86    public void AbortAllReadersAndWriters() {
87        AbortAllReaders();
88        AbortWriter();
89    }
90   
91    public void resolveReadConflicts() {
92        Transaction me  = FortressTaskRunner.getTransaction(); 
93        List<Transaction> conflicts = new ArrayList<Transaction>();
94        for (Transaction reader : readers)
95            if (reader.isActive() && !reader.isAncestorOf(me)) {
96                conflicts.add(reader);
97            }
98        if (!conflicts.isEmpty())
99            me.getContentionManager().resolveConflict(me, conflicts);       
100    }
101
102    public void resolveWriteConflict() {
103        Transaction me  = FortressTaskRunner.getTransaction(); 
104        if (writer != null && writer.isActive() && !writer.isAncestorOf(me)) {
105            me.getContentionManager().resolveConflict(me, writer);
106        }
107    }
108
109    public void resolveReadWriteConflicts() {
110        resolveReadConflicts();
111        resolveWriteConflict();
112    }
113}
Note: See TracBrowser for help on using the browser.