00001 package gov.nasa.arc.ase.jpf.jvm.runtime;
00002
00003 import gov.nasa.arc.ase.jpf.*;
00004 import gov.nasa.arc.ase.jpf.jvm.*;
00005 import java.util.*;
00006 import gov.nasa.arc.ase.util.Debug;
00007
00008 public class LockSet{
00009
00010 HashSet locks = new HashSet();
00011
00012
00013 public void addLock(Ref ref){
00014 locks.add(ref);
00015 }
00016 public int cardinality(){
00017 return locks.size();
00018 }
00019 private boolean contains(Ref ref){
00020 return locks.contains(ref);
00021 }
00022 public void deleteLock(Ref ref){
00023 locks.remove(ref);
00024 }
00025 public void intersect(LockSet new_locks){
00026 Analyze.debug_info("intersection called");
00027 Iterator locks_it = locks.iterator();
00028 locks = new HashSet();
00029 while(locks_it.hasNext()){
00030 Ref lock = (Ref)locks_it.next();
00031 if (new_locks.contains(lock))
00032 addLock(lock);
00033 }
00034 }
00035 public boolean isEmpty(){
00036 return locks.isEmpty();
00037 }
00038 public Iterator iterator(){
00039 return locks.iterator();
00040 }
00041 public void print(){
00042 Analyze.print("Locks held by thread = ");
00043 printSet();
00044 }
00045 protected void printSet(){
00046 Iterator locks_it = locks.iterator();
00047 Analyze.print("{ ");
00048 while(locks_it.hasNext()){
00049 Analyze.print(((Integer)locks_it.next()).intValue() + " ");
00050 };
00051 Analyze.println("}");
00052 }
00053 public void union(LockSet new_locks){
00054 Analyze.debug_info("union called");
00055 Iterator new_locks_it = new_locks.iterator();
00056 while (new_locks_it.hasNext()){
00057 addLock((Ref)new_locks_it.next());
00058 }
00059 }
00060 }