package edu.lsu.cct.MCSMPGC; public class Reference { int to; int which; boolean phantom; Object lock = new Object(); boolean phantom_self; public Reference(int to, int which){ this.to = to; this.which = which; this.phantom = false; this.phantom_self=false; } public void phantomize(){ synchronized(lock){ phantom = true; } Node n = Main.memory.allocated.get(to); if(which==n.which){ n.decSRC(); n.incPhantom(); } else{ n.decWRC(); n.incPhantom(); } } public void unphantomize(){ synchronized(lock){ phantom = false; phantom_self = false; } } public void phantomizeSelf(){ synchronized(lock){ phantom_self = true; } Node n = Main.memory.allocated.get(to); if(which==n.which){ n.decSRC(); n.incPhantom_self(); } else{ n.decWRC(); n.incPhantom_self(); } } public void delete(){ synchronized(lock){ Node n = Main.memory.allocated.get(to); if(phantom==true){ n.decPhantom(); } } } public void deletePS(){ Node n = Main.memory.allocated.get(to); n.decPhantom_self(); } public boolean isPhantomized(){ synchronized(lock){ return phantom; } } public boolean isSelfPhantomized(){ synchronized(lock){ return phantom_self; } } public String type(){ Node n = Main.memory.allocated.get(to); if(which==n.which){ return "SG"; } else{ return "WK"; } } }