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

Revision 2649, 3.6 KB (checked in by mspiegel, 16 months ago)

[warnings] Removed all unused imports in com.sun.fortress.interpreter.* and children packages.

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    ValueNode() {
36        old = null;
37        value = null;
38        writer = FortressTaskRunner.getTransaction();
39        readers = new ReadSet();
40    }
41
42    ValueNode(FValue val) {
43        old = null;
44        value = val;
45        writer = FortressTaskRunner.getTransaction();
46        readers = new ReadSet();
47    }
48
49    ValueNode(FValue val, Transaction w, ValueNode o) {
50        old = o;
51        value = val;
52        writer = w;
53        if (o != null)
54            readers = new ReadSet(o.readers);
55        else readers = new ReadSet();
56    }
57
58    ValueNode(FValue val, ReadSet r) {
59        old = null;
60        value = val;
61        readers = new ReadSet(r);
62    }
63
64    public String toString() {
65        return "ValueNode[" + value +  ":" + writer + "]" ;
66    }
67
68    public FValue getValue() {  return value;}
69    public Transaction getWriter() { return writer;}
70    public ReadSet getReaders() { return readers;}
71    public ValueNode getOld() { return old; }
72
73    public void addReader() {
74        Transaction me  = FortressTaskRunner.getTransaction();
75        if (!readers.add(me)) {
76            me.abort();
77            throw new AbortedException(me, "ReadSet Sealed : " + readers );
78        }
79    }
80           
81    public void AbortAllReaders() {
82                readers.seal();
83                for (Transaction r : readers) {
84                        r.abort();
85                }
86    }
87
88    public void AbortWriter() {
89        if (writer != null)  {
90            writer.abort();
91        }
92    }
93
94    public void AbortAllReadersAndWriters() {
95        AbortAllReaders();
96        AbortWriter();
97    }
98   
99    public void resolveReadConflicts() {
100        Transaction me  = FortressTaskRunner.getTransaction(); 
101        List<Transaction> conflicts = new ArrayList<Transaction>();
102        for (Transaction reader : readers)
103            if (reader.isActive() && !reader.isAncestorOf(me)) {
104                conflicts.add(reader);
105            }
106        if (!conflicts.isEmpty())
107            me.getContentionManager().resolveConflict(me, conflicts);       
108    }
109
110    public void resolveWriteConflict() {
111        Transaction me  = FortressTaskRunner.getTransaction(); 
112        if (writer != null && writer.isActive() && !writer.isAncestorOf(me)) {
113            me.getContentionManager().resolveConflict(me, writer);
114        }
115    }
116
117    public void resolveReadWriteConflicts() {
118        resolveReadConflicts();
119        resolveWriteConflict();
120    }
121}
Note: See TracBrowser for help on using the browser.