for (Enumeration ecld = child_prefetch_set_copy.keys(); ecld.hasMoreElements();) {
PrefetchPair childpp = (PrefetchPair) ecld.nextElement();
- if (childpp.base == currfsen.getDst()){
+ if (childpp.base == currfsen.getDst()) {
int sizedesc = childpp.desc.size();
if((childpp.getDescAt(0) instanceof IndexDescriptor)) {
int sizetempdesc = ((IndexDescriptor)(childpp.getDescAt(0))).tddesc.size();
newvisited.addLast(fn);
for(int i=0; i<fn.numNext(); i++) {
FlatNode nn = fn.getNext(i);
- if(!newtovisit.contains(nn) && !newvisited.contains(nn)){
+ if(!newtovisit.contains(nn) && !newvisited.contains(nn)) {
newtovisit.addLast(nn);
}
}
for (int j = 0; j < shrt.desc.size(); j++) {
if(shrt.getDescAt(j) instanceof IndexDescriptor) {
IndexDescriptor shrtid = (IndexDescriptor) shrt.getDescAt(j);
- if(lng.getDescAt(j) instanceof IndexDescriptor){
+ if(lng.getDescAt(j) instanceof IndexDescriptor) {
IndexDescriptor lngid = (IndexDescriptor) lng.getDescAt(j);
if(shrtid.equals(lngid)) {
continue;
return false;
}
} else {
- if ((Descriptor)shrt.getDescAt(j) != (Descriptor)lng.getDescAt(j)){
+ if ((Descriptor)shrt.getDescAt(j) != (Descriptor)lng.getDescAt(j)) {
return false;
}
}
ClassNode o = null;
try {
o = (ClassNode) super.clone();
- } catch(CloneNotSupportedException e){
+ } catch(CloneNotSupportedException e) {
e.printStackTrace();
}
o.uid = ClassNode.nodeID++;
this.lastchoices[next]++;
if((this.lastchoices[next] == this.rootNodes.size() ||
(this.rootNodes.elementAt(this.lastchoices[next]).elementAt(0).getCid() >
- this.node2Combine.elementAt(next).elementAt(0).getCid()))){
+ this.node2Combine.elementAt(next).elementAt(0).getCid()))) {
// break the rule that a node can only be combined to nodes with smaller colorid.
// or no more buckets
// backtrack
ClassDescriptor cd = cNode.getClassDescriptor();
Vector rootnodes = taskanalysis.getRootNodes(cd);
if(rootnodes != null) {
- for(int h = 0; h < rootnodes.size(); h++){
+ for(int h = 0; h < rootnodes.size(); h++) {
FlagState root=(FlagState)rootnodes.elementAt(h);
Vector allocatingTasks = root.getAllocatingTasks();
if(allocatingTasks != null) {
try {
int repeat = (int)Math.ceil(se.getNewRate() * se.getProbability() / 100);
int rate = 0;
- if(repeat > 1){
+ if(repeat > 1) {
for(int j = 1; j< repeat; j++ ) {
cloneSNodeList(se, true);
}
se.setProbability(100);
} else {
repeat -= rate;
- if(repeat > 0){
+ if(repeat > 0) {
// clone the whole ScheduleNode lists starting with se's target
for(int j = 0; j < repeat; j++ ) {
cloneSNodeList(se, true);
Queue<FlagState> toiterate = new LinkedList<FlagState>();
toiterate.add(nfs);
fStates.add(nfs);
- while(!toiterate.isEmpty()){
+ while(!toiterate.isEmpty()) {
FlagState tfs = toiterate.poll();
Iterator it_edges = tfs.edges();
while(it_edges.hasNext()) {
Vector<ScheduleEdge> toremove = new Vector<ScheduleEdge>();
Vector<ClassNode> rCNodes = new Vector<ClassNode>();
rCNodes.addElement(sCNode);
- if(it_isEdges != null){
+ if(it_isEdges != null) {
while(it_isEdges.hasNext()) {
ScheduleEdge tse = (ScheduleEdge)it_isEdges.next();
if(rCNodes.contains(tse.getSourceCNode())) {
return false;
}
}
- if ((fs.executionTime != this.executionTime)){
+ if ((fs.executionTime != this.executionTime)) {
return false;
}
if(fs.classNodes != null) {
ScheduleNode o = null;
try {
o = (ScheduleNode) super.clone();
- } catch(CloneNotSupportedException e){
+ } catch(CloneNotSupportedException e) {
e.printStackTrace();
}
o.uid = ScheduleNode.nodeID++;
isfirst = true;
}
tmpLabel = tmpTaskNodes.get(tmpTaskNode);
- switch(taction.getType()){
+ switch(taction.getType()) {
case Action.ADDOBJ: {
if(!isfirst) {
tmpLabel.append("\\n");
} else {
if((this.paraQueues != null) &&
(this.paraQueues.elementAt(i) != null) &&
- (this.paraQueues.elementAt(i).contains(obj))){
+ (this.paraQueues.elementAt(i).contains(obj))) {
this.paraQueues.elementAt(i).remove(obj);
this.objVersionTbl.remove(obj);
}
EGTaskNode srcnode=new EGTaskNode(alloctask.getSymbol(),alloctask, fs);
nodes.add(srcnode);
srcnode.setSource();
- for (Iterator edges = fs.edges(); edges.hasNext();){
+ for (Iterator edges = fs.edges(); edges.hasNext();) {
FEdge edge = (FEdge)edges.next();
EGTaskNode targetnode=getNode(edge, map, nodes);
EGEdge newedge=new EGEdge(fs, targetnode);
private void test(Hashtable graph) {
System.out.println("\nGraph contains :");
Collection c = graph.values();
- for ( Iterator it = c.iterator(); it.hasNext();){
+ for ( Iterator it = c.iterator(); it.hasNext();) {
EGTaskNode tn = (EGTaskNode)it.next();
System.out.println(tn.getTextLabel()+" ID "+tn.getLabel()+" FS "+tn.getFSName());
}
//create dot files execution_classname_.dot
private void printDOTFile() throws java.io.IOException {
Enumeration e = executiongraph.keys();
- while (e.hasMoreElements()){
+ while (e.hasMoreElements()) {
createDOTFile((ClassDescriptor)e.nextElement());
}
}
private void traverse(java.io.PrintWriter output, Set v) {
EGTaskNode tn;
- for(Iterator it1 = v.iterator(); it1.hasNext();){
+ for(Iterator it1 = v.iterator(); it1.hasNext();) {
tn = (EGTaskNode)it1.next();
output.println("\t"+tn.getLabel()+" [label=\""+tn.getTextLabel()+"\"");
if (tn.isMultipleParams()) output.println(", color=blue");
output.println("];");
- for(Iterator it2 = tn.edges(); it2.hasNext();){
+ for(Iterator it2 = tn.edges(); it2.hasNext();) {
output.println("\t"+tn.getLabel()+" -> "+((EGTaskNode)((EGEdge)it2.next()).getTarget()).getLabel()+";");
}
}
public int getFlagInt(FlagState fs) {
int flagid=0;
- for(Iterator flags = fs.getFlags(); flags.hasNext();){
+ for(Iterator flags = fs.getFlags(); flags.hasNext();) {
FlagDescriptor flagd = (FlagDescriptor)flags.next();
int id=1<<((Integer)flaginfo.get(flagd)).intValue();
flagid|=id;
/** Sets the flagstate as a source node.
*/
public void setAsSourceNode() {
- if(!issourcenode){
+ if(!issourcenode) {
issourcenode=true;
this.tasks=new Vector();
}
HashSet newset1=(HashSet)flagstate.clone();
Hashtable<TagDescriptor,Integer> newtags1=(Hashtable<TagDescriptor,Integer>)tags.clone();
- if (tags.containsKey(tag)){
+ if (tags.containsKey(tag)) {
//Code could try to remove flag that doesn't exist
- switch (tags.get(tag).intValue()){
+ switch (tags.get(tag).intValue()) {
case ONETAG:
newtags1.put(tag,new Integer(MULTITAGS));
return new FlagState[] {this, new FlagState(newset1, cd, newtags1)};
}
public FlagState[] clearTag(TagDescriptor tag) {
- if (tags.containsKey(tag)){
- switch(tags.get(tag).intValue()){
+ if (tags.containsKey(tag)) {
+ switch(tags.get(tag).intValue()) {
case ONETAG:
HashSet newset=(HashSet)flagstate.clone();
Hashtable<TagDescriptor,Integer> newtags=(Hashtable<TagDescriptor,Integer>)tags.clone();
*/
public String toString(FlagDescriptor[] flags) {
StringBuffer sb = new StringBuffer(flagstate.size());
- for(int i=0; i < flags.length; i++){
+ for(int i=0; i < flags.length; i++) {
if (get(flags[i]))
sb.append(1);
else
Hashtable<TagDescriptor,Integer> newtags=(Hashtable<TagDescriptor,Integer>)tags.clone();
if (status)
newset.add(fd);
- else if (newset.contains(fd)){
+ else if (newset.contains(fd)) {
newset.remove(fd);
}
else
label+=", "+fd.toString();
}
- for (Enumeration en_tags=getTags(); en_tags.hasMoreElements();){
+ for (Enumeration en_tags=getTags(); en_tags.hasMoreElements();) {
TagDescriptor td=(TagDescriptor)en_tags.nextElement();
- switch (tags.get(td).intValue()){
+ switch (tags.get(td).intValue()) {
case ONETAG:
if (label==null)
label=td.toString()+"(1)";
FlagState o = null;
try {
o = (FlagState) super.clone();
- } catch(CloneNotSupportedException e){
+ } catch(CloneNotSupportedException e) {
e.printStackTrace();
}
o.uid = FlagState.nodeid++;
int gap = 0;
for(int i = 0; i < this.edges.size(); i++) {
int temp = ((FEdge) this.edges.elementAt(index)).getInvokeNumGap();
- if((temp > gap) && (next.getTask().equals(td))){
+ if((temp > gap) && (next.getTask().equals(td))) {
index = i;
gap = temp;
}
//Conservatively handle tag changes
setotd=new HashSet<OptionalTaskDescriptor>();
} else if(egnode.isMultipleParams()) {
- if( goodMultiple(egnode)){
+ if( goodMultiple(egnode)) {
Predicate p=returnPredicate(egnode);
Set<OptionalTaskDescriptor> oldsetotd;
if (fstootd.containsKey(egnode.getPostFS()))
private HashSet createIntersection(Set A, Set B, ClassDescriptor cd) {
HashSet result = new HashSet();
- for(Iterator b_it = B.iterator(); b_it.hasNext();){
+ for(Iterator b_it = B.iterator(); b_it.hasNext();) {
OptionalTaskDescriptor otd_b = (OptionalTaskDescriptor)b_it.next();
- for(Iterator a_it = A.iterator(); a_it.hasNext();){
+ for(Iterator a_it = A.iterator(); a_it.hasNext();) {
OptionalTaskDescriptor otd_a = (OptionalTaskDescriptor)a_it.next();
if(otd_a.td==otd_b.td&&
otd_a.getIndex()==otd_b.getIndex()) {
newfs.addAll(otd_a.enterflagstates);
newfs.addAll(otd_b.enterflagstates);
OptionalTaskDescriptor newotd = new OptionalTaskDescriptor(otd_b.td, otd_b.getIndex(), newfs, combinePredicates(otd_a.predicate, otd_b.predicate));
- if(optionaltaskdescriptors.get(cd).get(newotd)!=null){
+ if(optionaltaskdescriptors.get(cd).get(newotd)!=null) {
newotd = optionaltaskdescriptors.get(cd).get(newotd);
} else {
newotd.setuid();
result.flags.putAll(A.flags);
result.tags.putAll(A.tags);
Collection c = B.vardescriptors;
- for(Iterator varit = c.iterator(); varit.hasNext();){ //maybe change that
+ for(Iterator varit = c.iterator(); varit.hasNext();) { //maybe change that
VarDescriptor vd = (VarDescriptor)varit.next();
if(result.vardescriptors.contains(vd))
System.out.println("Already in ");
}
}
Collection vardesc = result.vardescriptors;
- for(Iterator varit = vardesc.iterator(); varit.hasNext();){
+ for(Iterator varit = vardesc.iterator(); varit.hasNext();) {
VarDescriptor vd = (VarDescriptor)varit.next();
HashSet bflags = B.flags.get(vd);
- if( bflags == null ){
+ if( bflags == null ) {
continue;
} else {
if (result.flags.containsKey(vd))
result.flags.put(vd, bflags);
}
TagExpressionList btags = B.tags.get(vd);
- if( btags != null ){
+ if( btags != null ) {
if (result.tags.containsKey(vd))
System.out.println("Tag found but there should be nothing to do because same tag");
else
FlatFlagActionNode ffan=(FlatFlagActionNode)fn1;
if (ffan.getTaskType() == FlatFlagActionNode.TASKEXIT) {
HashSet tempset = new HashSet();
- for(Iterator it_fs = otd.enterflagstates.iterator(); it_fs.hasNext();){
+ for(Iterator it_fs = otd.enterflagstates.iterator(); it_fs.hasNext();) {
FlagState fstemp = (FlagState)it_fs.next();
Vector<FlagState> processed=new Vector<FlagState>();
Vector<FlagState> oldprocess=processed;
processed=new Vector<FlagState>();
- for (Enumeration en=oldprocess.elements(); en.hasMoreElements();){
+ for (Enumeration en=oldprocess.elements(); en.hasMoreElements();) {
FlagState fsworking=(FlagState)en.nextElement();
- if (!ffan.getTagChange(ttp)){
+ if (!ffan.getTagChange(ttp)) {
processed.addAll(Arrays.asList(fsworking.clearTag(ttp.getTag())));
} else processed.add(fsworking);
}
Vector<FlagState> oldprocess=processed;
processed=new Vector<FlagState>();
- for (Enumeration en=oldprocess.elements(); en.hasMoreElements();){
+ for (Enumeration en=oldprocess.elements(); en.hasMoreElements();) {
FlagState fsworking=(FlagState)en.nextElement();
- if (ffan.getTagChange(ttp)){
+ if (ffan.getTagChange(ttp)) {
processed.addAll(Arrays.asList(fsworking.setTag(ttp.getTag())));
} else processed.add(fsworking);
}
System.out.println("\nTesting class : "+cdtemp.getSymbol()+"\n");
Hashtable hashtbtemp = safeexecution.get(cdtemp);
Enumeration fses = hashtbtemp.keys();
- while(fses.hasMoreElements()){
+ while(fses.hasMoreElements()) {
FlagState fs = (FlagState)fses.nextElement();
System.out.println("\t"+fs.getTextLabel()+"\n\tSafe tasks to execute :\n");
HashSet availabletasks = (HashSet)hashtbtemp.get(fs);
- for(Iterator otd_it = availabletasks.iterator(); otd_it.hasNext();){
+ for(Iterator otd_it = availabletasks.iterator(); otd_it.hasNext();) {
OptionalTaskDescriptor otd = (OptionalTaskDescriptor)otd_it.next();
System.out.println("\t\tTASK "+otd.td.getSymbol()+" UID : "+otd.getuid()+"\n");
System.out.println("\t\twith flags :");
- for(Iterator myfses = otd.enterflagstates.iterator(); myfses.hasNext();){
+ for(Iterator myfses = otd.enterflagstates.iterator(); myfses.hasNext();) {
System.out.println("\t\t\t"+((FlagState)myfses.next()).getTextLabel());
}
System.out.println("\t\tand exitflags :");
- for(Iterator fseshash = otd.exitfses.iterator(); fseshash.hasNext();){
+ for(Iterator fseshash = otd.exitfses.iterator(); fseshash.hasNext();) {
HashSet temphs = (HashSet)fseshash.next();
System.out.println("");
- for(Iterator exfses = temphs.iterator(); exfses.hasNext();){
+ for(Iterator exfses = temphs.iterator(); exfses.hasNext();) {
System.out.println("\t\t\t"+((FlagState)exfses.next()).getTextLabel());
}
}
Predicate predicate = otd.predicate;
System.out.println("\t\tPredicate constraints :");
Collection c = predicate.vardescriptors;
- for(Iterator varit = c.iterator(); varit.hasNext();){
+ for(Iterator varit = c.iterator(); varit.hasNext();) {
VarDescriptor vard = (VarDescriptor)varit.next();
System.out.println("\t\t\tClass "+vard.getType().getClassDesc().getSymbol());
}
System.out.println("\n\n\n\tOptionaltaskdescriptors contains : ");
Collection c_otd = optionaltaskdescriptors.get(cdtemp).values();
- for(Iterator otd_it = c_otd.iterator(); otd_it.hasNext();){
+ for(Iterator otd_it = c_otd.iterator(); otd_it.hasNext();) {
OptionalTaskDescriptor otd = (OptionalTaskDescriptor)otd_it.next();
System.out.println("\t\tTASK "+otd.td.getSymbol()+" UID : "+otd.getuid()+"\n");
System.out.println("\t\twith flags :");
- for(Iterator myfses = otd.enterflagstates.iterator(); myfses.hasNext();){
+ for(Iterator myfses = otd.enterflagstates.iterator(); myfses.hasNext();) {
System.out.println("\t\t\t"+((FlagState)myfses.next()).getTextLabel());
}
System.out.println("\t\tand exitflags :");
- for(Iterator fseshash = otd.exitfses.iterator(); fseshash.hasNext();){
+ for(Iterator fseshash = otd.exitfses.iterator(); fseshash.hasNext();) {
HashSet temphs = (HashSet)fseshash.next();
System.out.println("");
- for(Iterator exfses = temphs.iterator(); exfses.hasNext();){
+ for(Iterator exfses = temphs.iterator(); exfses.hasNext();) {
System.out.println("\t\t\t"+((FlagState)exfses.next()).getTextLabel());
}
}
Predicate predicate = otd.predicate;
System.out.println("\t\tPredicate contains :");
Collection c = predicate.vardescriptors;
- for(Iterator varit = c.iterator(); varit.hasNext();){
+ for(Iterator varit = c.iterator(); varit.hasNext();) {
VarDescriptor vard = (VarDescriptor)varit.next();
System.out.println("\t\t\tClass "+vard.getType().getClassDesc().getSymbol());
HashSet temphash = predicate.flags.get(vard.getName());
FlatFlagActionNode ffan=(FlatFlagActionNode)fn1;
if (ffan.getTaskType() == FlatFlagActionNode.TASKEXIT) {
Iterator it_ttp=ffan.getTempTagPairs();
- if(it_ttp.hasNext()){
+ if(it_ttp.hasNext()) {
System.out.println("Tag change detected in Task "+tn.getName());
return true;
} else continue; // avoid queueing the return node if reachable
private void traverse(java.io.PrintWriter output, Collection v) {
EGTaskNode tn;
- for(Iterator it1 = v.iterator(); it1.hasNext();){
+ for(Iterator it1 = v.iterator(); it1.hasNext();) {
tn = (EGTaskNode)it1.next();
output.println("\t"+tn.getLabel()+" [label=\""+tn.getTextLabel()+"\"");
- if (tn.isOptional()){
+ if (tn.isOptional()) {
if (tn.isMultipleParams())
output.println(", shape = tripleoctagon");
else
output.println(", shape=octagon");
output.println("];");
- for(Iterator it2 = tn.edges(); it2.hasNext();){
+ for(Iterator it2 = tn.edges(); it2.hasNext();) {
EGTaskNode tn2 = (EGTaskNode)((Edge)it2.next()).getTarget();
output.println("\t"+tn.getLabel()+" -> "+tn2.getLabel()+";");
}
initFStates.addElement(fs);
}
Vector<FlagState> targetFStates = ffan.getTargetFStates(fs);
- for(Enumeration en=fsv_taskexit.elements(); en.hasMoreElements();){
+ for(Enumeration en=fsv_taskexit.elements(); en.hasMoreElements();) {
FlagState fs_taskexit=(FlagState)en.nextElement();
if (!sourcenodes.containsKey(fs_taskexit)) {
toprocess.add(fs_taskexit);
private boolean isTaskTrigger_tag(TagExpressionList tel, FlagState fs) {
- if (tel!=null){
- for (int i=0; i<tel.numTags() ; i++){
- switch (fs.getTagCount(tel.getType(i))){
+ if (tel!=null) {
+ for (int i=0; i<tel.numTags() ; i++) {
+ switch (fs.getTagCount(tel.getType(i))) {
case FlagState.ONETAG:
case FlagState.MULTITAGS:
break;
Vector<FlagState> oldprocess=processed;
processed=new Vector<FlagState>();
- for (Enumeration en=oldprocess.elements(); en.hasMoreElements();){
+ for (Enumeration en=oldprocess.elements(); en.hasMoreElements();) {
FlagState fsworking=(FlagState)en.nextElement();
- if (!ffan.getTagChange(ttp)){
+ if (!ffan.getTagChange(ttp)) {
processed.addAll(Arrays.asList(fsworking.clearTag(ttp.getTag())));
} else processed.add(fsworking);
}
Vector<FlagState> oldprocess=processed;
processed=new Vector<FlagState>();
- for (Enumeration en=oldprocess.elements(); en.hasMoreElements();){
+ for (Enumeration en=oldprocess.elements(); en.hasMoreElements();) {
FlagState fsworking=(FlagState)en.nextElement();
- if (ffan.getTagChange(ttp)){
+ if (ffan.getTagChange(ttp)) {
processed.addAll(Arrays.asList(fsworking.setTag(ttp.getTag())));
} else processed.add(fsworking);
}
for(Iterator it2=src.iterator(); it2.hasNext();) {
TaskDescriptor td=(TaskDescriptor)it2.next();
sn=new TaskNode(td.getSymbol());
- if(fs.edges().hasNext()){
+ if(fs.edges().hasNext()) {
addEdges(fs,sn,tasknodes);
}
}
}
- while(it_inedges.hasNext()){
+ while(it_inedges.hasNext()) {
FEdge inedge=(FEdge)it_inedges.next();
tn=new TaskNode(inedge.getLabel());
- if(fs.edges().hasNext()){
+ if(fs.edges().hasNext()) {
addEdges(fs,tn,tasknodes);
}
}
private void produceAllTaskNodes() {
alltasknodes=new Hashtable<TaskNode,TaskNode>();
- for(Iterator it_tasks=state.getTaskSymbolTable().getDescriptorsIterator(); it_tasks.hasNext();){
+ for(Iterator it_tasks=state.getTaskSymbolTable().getDescriptorsIterator(); it_tasks.hasNext();) {
TaskDescriptor td=(TaskDescriptor)it_tasks.next();
TaskNode tn=new TaskNode(td.getSymbol());
alltasknodes.put(tn,tn);
ClassDescriptor cd=(ClassDescriptor) classit.next();
Set fsnodes;
- if (cd.hasFlags()&&((fsnodes=taskanalysis.getFlagStates(cd))!=null)){
+ if (cd.hasFlags()&&((fsnodes=taskanalysis.getFlagStates(cd))!=null)) {
//
System.out.println("\nWorking on fses of Class: "+cd.getSymbol());
//
TaskNode tn,sn;
- if (fs.isSourceNode()){
+ if (fs.isSourceNode()) {
//
System.out.println("A sourcenode");
//
- if(fs.edges().hasNext()){
+ if(fs.edges().hasNext()) {
Vector allocatingtasks=fs.getAllocatingTasks();
//
if (allocatingtasks.iterator().hasNext())
System.out.println("has been allocated by "+allocatingtasks.size()+" tasks");
//
- for(Iterator it_at=allocatingtasks.iterator(); it_at.hasNext();){
+ for(Iterator it_at=allocatingtasks.iterator(); it_at.hasNext();) {
TaskDescriptor allocatingtd=(TaskDescriptor)it_at.next();
//
System.out.println(allocatingtd.getSymbol());
}
}
- while(it_inedges.hasNext()){
+ while(it_inedges.hasNext()) {
FEdge inedge=(FEdge)it_inedges.next();
tn=new TaskNode(inedge.getLabel());
- if(fs.edges().hasNext()){
+ if(fs.edges().hasNext()) {
addEdges(fs,tn,alltasknodes,ColorID);
}
}
// Hashtable<TaskNode,TaskNode> tasknodes=(Hashtable<TaskNode,TaskNode>)cdtonodes.get(fs.getClassDescriptor());
tn=(TaskNode)canonicalizeTaskNode(tasknodes, tn);
- for (Iterator it_edges=fs.edges(); it_edges.hasNext();){
+ for (Iterator it_edges=fs.edges(); it_edges.hasNext();) {
TaskNode target=new TaskNode(((FEdge)it_edges.next()).getLabel());
target=(TaskNode)canonicalizeTaskNode(tasknodes,target);
private void addEdges(FlagState fs, TaskNode tn,Hashtable<TaskNode,TaskNode> tasknodes,int ColorID) {
tn=(TaskNode)canonicalizeTaskNode(tasknodes, tn);
- for (Iterator it_edges=fs.edges(); it_edges.hasNext();){
+ for (Iterator it_edges=fs.edges(); it_edges.hasNext();) {
TaskNode target=new TaskNode(((FEdge)it_edges.next()).getLabel());
target=(TaskNode)canonicalizeTaskNode(tasknodes,target);
private static boolean isTaskTrigger_tag(TagExpressionList tel, FlagState fs) {
- if (tel!=null){
- for (int i=0; i<tel.numTags() ; i++){
- switch (fs.getTagCount(tel.getType(i))){
+ if (tel!=null) {
+ for (int i=0; i<tel.numTags() ; i++) {
+ switch (fs.getTagCount(tel.getType(i))) {
case FlagState.ONETAG:
case FlagState.MULTITAGS:
break;
int random;
// Do a little bit unrolling of the above algorithm.
int max = bytes.length & ~0x3;
- for (int i = 0; i < max; i += 4){
+ for (int i = 0; i < max; i += 4) {
random = next(32);
bytes[i] = (byte) random;
bytes[i + 1] = (byte) (random >> 8);
bytes[i + 2] = (byte) (random >> 16);
bytes[i + 3] = (byte) (random >> 24);
}
- if (max < bytes.length){
+ if (max < bytes.length) {
random = next(32);
- for (int j = max; j < bytes.length; j++){
+ for (int j = max; j < bytes.length; j++) {
bytes[j] = (byte) random;
random >>= 8;
}
* @return the next pseudorandom Gaussian distributed double
*/
public synchronized double nextGaussian() {
- if (haveNextNextGaussian){
+ if (haveNextNextGaussian) {
haveNextNextGaussian = false;
return nextNextGaussian;
}
if (state.TASK) {
outtask=new PrintWriter(new FileOutputStream(PREFIX+"task.h"), true);
outtaskdefs=new PrintWriter(new FileOutputStream(PREFIX+"taskdefs.c"), true);
- if (state.OPTIONAL){
+ if (state.OPTIONAL) {
outoptionalarrays=new PrintWriter(new FileOutputStream(PREFIX+"optionalarrays.c"), true);
optionalheaders=new PrintWriter(new FileOutputStream(PREFIX+"optionalstruct.h"), true);
}
}
/* Generate information for task with optional parameters */
- if (state.TASK&&state.OPTIONAL){
+ if (state.TASK&&state.OPTIONAL) {
generateOptionalArrays(outoptionalarrays, optionalheaders, state.getAnalysisResult(), state.getOptionalTaskDescriptors());
outoptionalarrays.close();
}
outclassdefs.println(" int version;");
outclassdefs.println(" struct ___Object___ * original;");
}
- if(state.OPTIONAL){
+ if(state.OPTIONAL) {
outclassdefs.println(" int numfses;");
outclassdefs.println(" int * fses;");
}
classdefout.println(" int flag;");
if((!state.MULTICORE) || (cn.getSymbol().equals("TagDescriptor"))) {
classdefout.println(" void * flagptr;");
- } else if (state.MULTICORE){
+ } else if (state.MULTICORE) {
classdefout.println(" int isolate;"); // indicate if this object is shared or not
classdefout.println(" int version;");
classdefout.println(" struct ___Object___ * original;");
}
- if (state.OPTIONAL){
+ if (state.OPTIONAL) {
classdefout.println(" int numfses;");
classdefout.println(" int * fses;");
}
Hashtable<TempDescriptor, Integer> slotnumber=new Hashtable<TempDescriptor, Integer>();
int current_slot=0;
- for(Iterator vard_it = c_vard.iterator(); vard_it.hasNext();){
+ for(Iterator vard_it = c_vard.iterator(); vard_it.hasNext();) {
VarDescriptor vard = (VarDescriptor)vard_it.next();
TypeDescriptor typed = vard.getType();
HashSet fen_hashset = predicate.flags.get(vard.getSymbol());
output.println("int predicateflags_"+predicateindex+"_OTD"+otd.getuid()+"_"+cdtemp.getSafeSymbol()+"[]={");
int numberterms=0;
- if (fen_hashset!=null){
- for (Iterator fen_it = fen_hashset.iterator(); fen_it.hasNext();){
+ if (fen_hashset!=null) {
+ for (Iterator fen_it = fen_hashset.iterator(); fen_it.hasNext();) {
FlagExpressionNode fen = (FlagExpressionNode)fen_it.next();
if (fen!=null) {
DNFFlag dflag=fen.getDNF();
TagExpressionList tagel = predicate.tags.get(vard.getSymbol());
output.println("int predicatetags_"+predicateindex+"_OTD"+otd.getuid()+"_"+cdtemp.getSafeSymbol()+"[]={");
int numtags = 0;
- if (tagel!=null){
+ if (tagel!=null) {
for(int j=0; j<tagel.numTags(); j++) {
if (j!=0)
output.println(",");
//generate an array that stores the entire predicate
output.println("struct predicatemember * predicatememberarray_OTD"+otd.getuid()+"_"+cdtemp.getSafeSymbol()+"[]={");
- for( int j = 0; j<predicateindex; j++){
+ for( int j = 0; j<predicateindex; j++) {
if( j != predicateindex-1) output.println("&predicatemember_"+j+"_OTD"+otd.getuid()+"_"+cdtemp.getSafeSymbol()+",");
else output.println("&predicatemember_"+j+"_OTD"+otd.getuid()+"_"+cdtemp.getSafeSymbol());
}
Collection c_otd = ((Hashtable)optionaltaskdescriptors.get(cdtemp)).values();
numotd = c_otd.size();
if(maxotd<numotd) maxotd = numotd;
- if( !c_otd.isEmpty() ){
- for(Iterator otd_it = c_otd.iterator(); otd_it.hasNext();){
+ if( !c_otd.isEmpty() ) {
+ for(Iterator otd_it = c_otd.iterator(); otd_it.hasNext();) {
OptionalTaskDescriptor otd = (OptionalTaskDescriptor)otd_it.next();
//generate the int arrays for the predicate
//iterate through possible FSes corresponding to
//the state when entering
- for(Iterator fses = otd.enterflagstates.iterator(); fses.hasNext();){
+ for(Iterator fses = otd.enterflagstates.iterator(); fses.hasNext();) {
FlagState fs = (FlagState)fses.next();
int flagid=0;
- for(Iterator flags = fs.getFlags(); flags.hasNext();){
+ for(Iterator flags = fs.getFlags(); flags.hasNext();) {
FlagDescriptor flagd = (FlagDescriptor)flags.next();
int id=1<<((Integer)flaginfo.get(flagd)).intValue();
flagid|=id;
output.println("struct optionaltaskdescriptor * otdarray"+cdtemp.getSafeSymbol()+"[]={");
c_otd = ((Hashtable)optionaltaskdescriptors.get(cdtemp)).values();
- if( !c_otd.isEmpty() ){
+ if( !c_otd.isEmpty() ) {
boolean needcomma=false;
- for(Iterator otd_it = c_otd.iterator(); otd_it.hasNext();){
+ for(Iterator otd_it = c_otd.iterator(); otd_it.hasNext();) {
OptionalTaskDescriptor otd = (OptionalTaskDescriptor)otd_it.next();
if(needcomma)
output.println(",");
//top) into an array
output.println("struct optionaltaskdescriptor * optionaltaskdescriptorarray_FS"+fscounter+"_"+cdtemp.getSafeSymbol()+"[] = {");
- for(Iterator<OptionalTaskDescriptor> mos = ordertd(availabletasks).iterator(); mos.hasNext();){
+ for(Iterator<OptionalTaskDescriptor> mos = ordertd(availabletasks).iterator(); mos.hasNext();) {
OptionalTaskDescriptor mm = mos.next();
if(!mos.hasNext())
output.println("&optionaltaskdescriptor_"+mm.getuid()+"_"+cdtemp.getSafeSymbol());
//process flag information (what the flag after failure is) so we know what optionaltaskdescriptors to choose.
int flagid=0;
- for(Iterator flags = fs.getFlags(); flags.hasNext();){
+ for(Iterator flags = fs.getFlags(); flags.hasNext();) {
FlagDescriptor flagd = (FlagDescriptor)flags.next();
int id=1<<((Integer)flaginfo.get(flagd)).intValue();
flagid|=id;
boolean first = true;
Enumeration tag_enum = fs.getTags();
output.println("int tags_FS"+fscounter+"_"+cdtemp.getSafeSymbol()+"[]={");
- while(tag_enum.hasMoreElements()){
+ while(tag_enum.hasMoreElements()) {
tagcounter++;
TagDescriptor tagd = (TagDescriptor)tag_enum.nextElement();
if(first==true)
//Build the array of fsanalysiswrappers
output.println("struct fsanalysiswrapper * fsanalysiswrapperarray_"+cdtemp.getSafeSymbol()+"[] = {");
boolean needcomma=false;
- for(int i = 0; i<fscounter; i++){
+ for(int i = 0; i<fscounter; i++) {
if (needcomma) output.print(",");
output.println("&fsanalysiswrapper_FS"+(i+1)+"_"+cdtemp.getSafeSymbol());
needcomma=true;
} else {
tmpinfo.fs = tmpFState;
}
- if(!contains(sendto, tmpinfo)){
+ if(!contains(sendto, tmpinfo)) {
qinfo = outputtransqueues(tmpinfo.fs, targetcore, output);
output.println("tmpObjInfo = RUNMALLOC(sizeof(struct transObjInfo));");
output.println("tmpObjInfo->objptr = (void *)" + tmpinfo.name + ";");
} else {
tmpinfo.fs = tmpFState;
}
- if(!contains(sendto, tmpinfo)){
+ if(!contains(sendto, tmpinfo)) {
qinfo = outputtransqueues(tmpinfo.fs, targetcore, output);
output.println("tmpObjInfo = RUNMALLOC(sizeof(struct transObjInfo));");
output.println("tmpObjInfo->objptr = (void *)" + tmpinfo.name + ";");
} else {
tmpinfo.fs = tmpFState;
}
- if(!contains(sendto, tmpinfo)){
+ if(!contains(sendto, tmpinfo)) {
qinfo = outputtransqueues(tmpinfo.fs, targetcores.elementAt(i), output);
output.println("tmpObjInfo = RUNMALLOC(sizeof(struct transObjInfo));");
output.println("tmpObjInfo->objptr = (void *)" + tmpinfo.name + ";");
ParseNodeVector pnv=paramlist.getChildren();
for(int i=0; i<pnv.size(); i++) {
ParseNode paramn=pnv.elementAt(i);
- if(paramn.getChild("optional")!=null){
+ if(paramn.getChild("optional")!=null) {
optional = true;
paramn = paramn.getChild("optional").getFirstChild();
System.out.println("OPTIONAL FOUND!!!!!!!");
"Content-Length: "+ fileLength + "\n\n"; // length
try {
out.write(header.getBytes());
- } catch(IOException e) {
+ } catch(IOException e) {
e.printStackTrace(); // do nothing!
}
}
while((size = reader.read(buffer,0,buffer.length)) != -1)
out.write(buffer,0,size);
reader.close();
- } catch(IOException e) {
+ } catch(IOException e) {
e.printStackTrace();
resp.returnCode = 501; // error during transmision
}
try {
reader = get_reader(fileName, resp);
resp.returnCode = 200;
- } catch(IOException e) {
+ } catch(IOException e) {
resp.returnCode = 404; // file not found
}
try {
System.out.println("creating the port");
server = new ServerSocket(port);
- } catch (IOException e) {
+ } catch (IOException e) {
System.err.println(e);
System.exit(1);
}
public void run() {
// infinite loop
- while (true){
+ while (true) {
try {
startWorker(server.accept());
- } catch (Exception e) {
+ } catch (Exception e) {
System.err.println(e);
}
}
client.getInputStream()));
out = client.getOutputStream();
- } catch(IOException e) {
+ } catch(IOException e) {
// I'm not too good at HTTP. Normally, we should put some
// error code here. Anyway, I have assumed that an error
// is equivalent to an unhandled request / method (501)
resp.returnCode = 501;
}
- if(resp.returnCode == 200){
+ if(resp.returnCode == 200) {
// call the appropriate hanndler
- switch(method(in)){
+ switch(method(in)) {
case 0:
if (webinterface.specialRequest(fileName)) {
out.close();
in.close();
client.close();
- } catch(IOException e) {
+ } catch(IOException e) {
; // do nothing
}
}
line = in.readLine();
// only spaces used
StringTokenizer tok = new StringTokenizer(line, " ");
- if (tok.hasMoreTokens()){ // make sure there is a request
+ if (tok.hasMoreTokens()) { // make sure there is a request
String str = tok.nextToken();
- if ( str.equals("GET") ){
+ if ( str.equals("GET") ) {
ret = 0;
methodType = "GET";
} else if ( str.equals("HEAD") ) {
}
// get the filename
- if (tok.hasMoreTokens()){
+ if (tok.hasMoreTokens()) {
fileName = tok.nextToken();
- if(fileName.equals("/")){
+ if(fileName.equals("/")) {
fileName = "/index.html";
}
} else
// read the http version number
// - right now nothing is done with this information
- if (tok.hasMoreTokens()){
+ if (tok.hasMoreTokens()) {
httpVersion = tok.nextToken();
} else
{
// read remainder of the browser's header
// - nothing done right now with this info... placeholder
- while((line = in.readLine()) != null){
+ while((line = in.readLine()) != null) {
StringTokenizer token = new StringTokenizer(line," ");
// do processing here
- if(!token.hasMoreTokens()){
+ if(!token.hasMoreTokens()) {
break;
}
}
- } catch(Exception e) {
+ } catch(Exception e) {
System.err.println(e);
return -1;
}
out.write(Entry,0,Entry.length());
out.flush();
out.close();
- } catch (IOException e) {
+ } catch (IOException e) {
System.err.println("Gicu " + e);
}
taskmap = new Hashtable();
sourcenodemap=new Hashtable();
- for(Iterator it_tasks=state.getTaskSymbolTable().getDescriptorsIterator(); it_tasks.hasNext();){
+ for(Iterator it_tasks=state.getTaskSymbolTable().getDescriptorsIterator(); it_tasks.hasNext();) {
TaskDescriptor td=(TaskDescriptor)it_tasks.next();
taskmap.put("/"+td.getSymbol()+".html",td);
}
for(Iterator it_classes=state.getClassSymbolTable().getDescriptorsIterator(); it_classes.hasNext();) {
ClassDescriptor cd=(ClassDescriptor) it_classes.next();
- if(cd.hasFlags()){
+ if(cd.hasFlags()) {
Vector rootnodes=taskanalysis.getRootNodes(cd);
if(rootnodes!=null)
- for(Iterator it_rootnodes=rootnodes.iterator(); it_rootnodes.hasNext();){
+ for(Iterator it_rootnodes=rootnodes.iterator(); it_rootnodes.hasNext();) {
FlagState root=(FlagState)it_rootnodes.next();
Vector cd_nodeid=new Vector(); //Vector is designed to contain only 2 elements: ClassDescriptor,Node label
// Both the values are required to correctly resolve the rootnode.
private String printTask(TaskDescriptor td, PrintWriter pw) {
try {
- for(int i=0; i < td.numParameters(); i++){
+ for(int i=0; i < td.numParameters(); i++) {
pw.println("FlagState Graph: <a href=\"/"+td.getParamType(i)+".html\">"+td.getParamType(i)+"</a><br>");
pw.println("Task Graph: <a href=\"/"+td.getParamType(i)+"-t.html\">"
+td.getParamType(i)+"</a><br>");
private String sourcenode(Vector cd_nodeid,OutputStream out, HTTPResponse resp) {
Vector rootnodes=taskanalysis.getRootNodes((ClassDescriptor)cd_nodeid.elementAt(0));
- for(Iterator it_rootnodes=rootnodes.iterator(); it_rootnodes.hasNext();){
+ for(Iterator it_rootnodes=rootnodes.iterator(); it_rootnodes.hasNext();) {
FlagState root=(FlagState)it_rootnodes.next();
- if (root.getLabel().equals((String)cd_nodeid.elementAt(1))){
+ if (root.getLabel().equals((String)cd_nodeid.elementAt(1))) {
try {
PrintWriter pw=new PrintWriter(out);
pw.println("<br><br><h3>Allocating tasks for "+root.getTextLabel()+":</h3><br>");
Vector tasks=root.getAllocatingTasks();
- for(Iterator it_tasks=tasks.iterator(); it_tasks.hasNext();){
+ for(Iterator it_tasks=tasks.iterator(); it_tasks.hasNext();) {
TaskDescriptor td=(TaskDescriptor)it_tasks.next();
pw.println("<br><strong>Task: "+td.toString()+"</strong><br>");
printTask(td,pw);
pw.println("<a href=\"/"+ cd.getSymbol()+".ps\">ps</a><br>");
//pw.println("<a href=\"/"+ cd.getSymbol()+".map\"><img src=\"/"+ cd.getSymbol()+".gif\" ismap=\"ismap\"></A>");
pw.println("<img src=\""+cd.getSymbol()+".jpg\" usemap=\"#dotvisitor\" />");
- while((str=mapbr.readLine())!=null){
+ while((str=mapbr.readLine())!=null) {
pw.println(str);
}
// pw.println("<a href=\"/"+ cd.getSymbol()+"-t.map\"><img src=\"/"+ cd.getSymbol()+"-t.gif\" ismap=\"ismap\"></A>");
pw.println("<img src=\""+cd.getSymbol()+"-t.jpg\" usemap=\"#dotvisitor\" />");
- while((str=mapbr.readLine())!=null){
+ while((str=mapbr.readLine())!=null) {
pw.println(str);
}
pw.flush();
PrintWriter pw=new PrintWriter(out);
for(Iterator it_classes=state.getClassSymbolTable().getDescriptorsIterator(); it_classes.hasNext();) {
ClassDescriptor cd=(ClassDescriptor) it_classes.next();
- if (cd.hasFlags()){
+ if (cd.hasFlags()) {
if (taskanalysis.getFlagStates(cd)!=null) {
pw.println("<a href=\""+cd.getSymbol()+".html\">"+ cd.getSymbol() +"</a>");
pw.println("<br>");
int tint = 0;
for(Iterator it_classes=state.getClassSymbolTable().getDescriptorsIterator(); it_classes.hasNext();) {
ClassDescriptor cd=(ClassDescriptor) it_classes.next();
- if(cd.hasFlags()){
+ if(cd.hasFlags()) {
Vector rootnodes=ta.getRootNodes(cd);
if(rootnodes!=null)
- for(Iterator it_rootnodes=rootnodes.iterator(); it_rootnodes.hasNext();){
+ for(Iterator it_rootnodes=rootnodes.iterator(); it_rootnodes.hasNext();) {
FlagState root=(FlagState)it_rootnodes.next();
Vector allocatingTasks = root.getAllocatingTasks();
if(allocatingTasks != null) {
if(numEdges - j == 1) {
pfe.setProbability(total);
} else {
- if((total != 0) && (total != 1)){
+ if((total != 0) && (total != 1)) {
do {
tint = r.nextInt()%total;
} while(tint <= 0);
if (bind(udpPollSock.fd, (struct sockaddr *)&myAddr, socklen) < 0)
perror("dhtInit():bind()");
- if (seed == 0){
+ if (seed == 0) {
dhtLog("I am the leader\n");
leader = myHostData.ipAddr;
setState(LEAD_NORMAL1_STATE);
toAddr.sin_family = AF_INET;
toAddr.sin_port = htons(UDP_PORT);
- while (status != OPERATION_OK){
+ while (status != OPERATION_OK) {
pthread_mutex_lock(&stateMutex);
while (!(state == NORMAL_STATE || state == LEAD_NORMAL1_STATE
|| state == LEAD_NORMAL2_STATE || state == REBUILD4_STATE
toAddr.sin_addr.s_addr = htonl(getKeyOwner(key));
pthread_mutex_unlock(&stateMutex);
- if ((pollsock.fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0){
+ if ((pollsock.fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
perror("dhtInsert():socket()");
return -1;
}
write4(&outBuffer[1], key);
write4(&outBuffer[5], val);
- for (i = 0; i < INSERT_RETRIES; i++){
+ for (i = 0; i < INSERT_RETRIES; i++) {
if (sendto(pollsock.fd, outBuffer, 9, 0, (struct sockaddr *)&toAddr,
- socklen) < 0){
+ socklen) < 0) {
perror("dhtInsert():sendto()");
break;
}
retval = poll(&pollsock, 1, INSERT_TIMEOUT_MS);
- if (retval < 0){
+ if (retval < 0) {
perror("dhtInsert():poll()");
break;
}
- if (retval > 0){
+ if (retval > 0) {
bytesRcvd = recvfrom(pollsock.fd, inBuffer, 2, 0,
(struct sockaddr *)&fromAddr, &socklen);
if (fromAddr.sin_addr.s_addr == toAddr.sin_addr.s_addr
&& fromAddr.sin_port == toAddr.sin_port
- && bytesRcvd == 2 && inBuffer[0] == INSERT_RES){
+ && bytesRcvd == 2 && inBuffer[0] == INSERT_RES) {
status = inBuffer[1]; //status from remote host
break;
}
}
}
- if (status != OPERATION_OK){
+ if (status != OPERATION_OK) {
pthread_mutex_lock(&stateMutex);
setState(REBUILD0_STATE);
outBuffer[0] = REBUILD_REQ;
int i;
status = 0;
- for (i = 0; i < numKeys; i++){
+ for (i = 0; i < numKeys; i++) {
if (dhtInsert(keys[i], vals[i]) != 0)
status = -1;
}
toAddr.sin_family = AF_INET;
toAddr.sin_port = htons(UDP_PORT);
- while (!(status == OPERATION_OK || status == KEY_NOT_FOUND)){
+ while (!(status == OPERATION_OK || status == KEY_NOT_FOUND)) {
pthread_mutex_lock(&stateMutex);
while (!(state == NORMAL_STATE || state == LEAD_NORMAL1_STATE
|| state == LEAD_NORMAL2_STATE))
toAddr.sin_addr.s_addr = htonl(getKeyOwner(key));
pthread_mutex_unlock(&stateMutex);
- if ((pollsock.fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0){
+ if ((pollsock.fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
perror("dhtRemove():socket()");
return -1;
}
outBuffer[0] = REMOVE_CMD;
write4(&outBuffer[1], key);
- for (i = 0; i < REMOVE_RETRIES; i++){
+ for (i = 0; i < REMOVE_RETRIES; i++) {
if (sendto(pollsock.fd, outBuffer, 5, 0, (struct sockaddr *)&toAddr,
- socklen) < 0){
+ socklen) < 0) {
perror("dhtRemove():sendto()");
break;
}
retval = poll(&pollsock, 1, REMOVE_TIMEOUT_MS);
- if (retval < 0){
+ if (retval < 0) {
perror("dhtRemove():poll()");
break;
}
- if (retval > 0){
+ if (retval > 0) {
bytesRcvd = recvfrom(pollsock.fd, inBuffer, 2, 0,
(struct sockaddr *)&fromAddr, &socklen);
if (fromAddr.sin_addr.s_addr == toAddr.sin_addr.s_addr
&& fromAddr.sin_port == toAddr.sin_port
- && bytesRcvd == 2 && inBuffer[0] == REMOVE_RES){
+ && bytesRcvd == 2 && inBuffer[0] == REMOVE_RES) {
status = inBuffer[1]; //status from remote host
break;
}
}
}
- if (!(status == OPERATION_OK || status == KEY_NOT_FOUND)){
+ if (!(status == OPERATION_OK || status == KEY_NOT_FOUND)) {
pthread_mutex_lock(&stateMutex);
setState(REBUILD0_STATE);
outBuffer[0] = REBUILD_REQ;
int i;
status = 0;
- for (i = 0; i < numKeys; i++){
+ for (i = 0; i < numKeys; i++) {
if (dhtRemove(keys[i]) != 0)
status = -1;
}
toAddr.sin_family = AF_INET;
toAddr.sin_port = htons(UDP_PORT);
- while (!(status == OPERATION_OK || status == KEY_NOT_FOUND)){
+ while (!(status == OPERATION_OK || status == KEY_NOT_FOUND)) {
pthread_mutex_lock(&stateMutex);
while (numBlocks == 0)
pthread_cond_wait(&stateCond, &stateMutex);
toAddr.sin_addr.s_addr = htonl(getKeyOwner(key));
pthread_mutex_unlock(&stateMutex);
- if ((pollsock.fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0){
+ if ((pollsock.fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
perror("dhtSearch():socket()");
return -1;
}
outBuffer[0] = SEARCH_CMD;
write4(&outBuffer[1], key);
- for (i = 0; i < SEARCH_RETRIES; i++){
+ for (i = 0; i < SEARCH_RETRIES; i++) {
if (sendto(pollsock.fd, outBuffer, 5, 0, (struct sockaddr *)&toAddr,
- socklen) < 0){
+ socklen) < 0) {
perror("dhtSearch():sendto()");
break;
}
retval = poll(&pollsock, 1, SEARCH_TIMEOUT_MS);
- if (retval < 0){
+ if (retval < 0) {
perror("dhtSearch():poll()");
break;
}
- if (retval > 0){
+ if (retval > 0) {
bytesRcvd = recvfrom(pollsock.fd, inBuffer, 6, 0,
(struct sockaddr *)&fromAddr, &socklen);
if (fromAddr.sin_addr.s_addr == toAddr.sin_addr.s_addr
&& fromAddr.sin_port == toAddr.sin_port
- && bytesRcvd == 6 && inBuffer[0] == SEARCH_RES){
+ && bytesRcvd == 6 && inBuffer[0] == SEARCH_RES) {
status = inBuffer[1]; //status from remote host
*val = read4(&inBuffer[2]);
break;
}
}
}
- if (!(status == OPERATION_OK || status == KEY_NOT_FOUND)){
+ if (!(status == OPERATION_OK || status == KEY_NOT_FOUND)) {
pthread_mutex_lock(&stateMutex);
setState(REBUILD0_STATE);
outBuffer[0] = REBUILD_REQ;
int dhtSearchMult(unsigned int numKeys, unsigned int *keys, unsigned int *vals) {
int i;
int status = 0;
- for (i = 0; i < numKeys; i++){
+ for (i = 0; i < numKeys; i++) {
if (dhtSearch(keys[i], &vals[i]) != 0)
status = -1;
}
if (size < 1)
return 1;
- switch (msg[0]){
+ switch (msg[0]) {
case WHO_IS_LEADER_CMD:
case LEAVE_REQ:
case LEAVE_RES:
memset(&interfaceInfo, 0, sizeof(struct ifreq));
- if((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0){
+ if((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
perror("getMyIpAddr():socket()");
return 1;
}
strcpy(interfaceInfo.ifr_name, interfaceStr);
myAddr->sin_family = AF_INET;
- if(ioctl(sock, SIOCGIFADDR, &interfaceInfo) != 0){
+ if(ioctl(sock, SIOCGIFADDR, &interfaceInfo) != 0) {
perror("getMyIpAddr():ioctl()");
return 1;
}
peerAddr.sin_addr.s_addr = htonl(destIp);
peerAddr.sin_port = htons(UDP_PORT);
- if (size >= 1){
+ if (size >= 1) {
if (msg[0] < NUM_MSG_TYPES)
dhtLog("udpSend(): sending %s to %s, %d bytes\n", msg_types[msg[0]],
inet_ntoa(peerAddr.sin_addr), size);
}
if (sendto(udpPollSock.fd, (void *)msg, size, 0, (struct sockaddr *)&peerAddr,
- socklen) < 0){
+ socklen) < 0) {
perror("udpSend():sendto()");
return -1;
}
int udpSendAll(unsigned char *msg, unsigned int size) {
int i;
int status = 0;
- for (i = 0; i < numHosts; i++){
- if ((hostReplied[i] == 0) && (hostArray[i].ipAddr != myHostData.ipAddr)){
+ for (i = 0; i < numHosts; i++) {
+ if ((hostReplied[i] == 0) && (hostArray[i].ipAddr != myHostData.ipAddr)) {
if (udpSend(msg, size, hostArray[i].ipAddr) != 0)
status = -1;
}
gettimeofday(&now, NULL);
- if (newState >= NUM_STATES){
+ if (newState >= NUM_STATES) {
dhtLog("setState(): ERROR: invalid state %d\n", newState);
} else
{
if (timeout_vals[newState].tv_sec == 0
- && timeout_vals[newState].tv_usec == 0){ //no timer
+ && timeout_vals[newState].tv_usec == 0) { //no timer
timerSet = 0;
} else
{
if (i == -1)
return -1;
- for (j = 0; j < numBlocks; j++){
+ for (j = 0; j < numBlocks; j++) {
if (blockOwnerArray[j] == i)
blockOwnerArray[j] = 0; //TODO: is this what I want to have happen?
else if (blockOwnerArray[j] > i)
blockOwnerArray[j]--;
}
- for (; i < numHosts - 1; i++){
+ for (; i < numHosts - 1; i++) {
hostArray[i] = hostArray[i+1];
hostReplied[i] = hostReplied[i+1];
}
void removeUnresponsiveHosts() {
int i;
- for (i = 0; i < numHosts; i++){
+ for (i = 0; i < numHosts; i++) {
if (!hostReplied[i] && hostArray[i].ipAddr != myHostData.ipAddr)
removeHost(hostArray[i].ipAddr);
}
int i;
int j;
- for (i = 0; i < numHosts; i++){
- if (hostArray[i].ipAddr == newHost.ipAddr){
+ for (i = 0; i < numHosts; i++) {
+ if (hostArray[i].ipAddr == newHost.ipAddr) {
hostArray[i] = newHost;
hostReplied[i] = 0;
return 0;
} else if (hostArray[i].ipAddr > newHost.ipAddr) {
- if (numHosts == hostArraySize){
+ if (numHosts == hostArraySize) {
newHostArray = calloc(2 * hostArraySize, sizeof(struct hostData));
newHostReplied = calloc(2 * hostArraySize, sizeof(unsigned char));
memcpy(newHostArray, hostArray, (i * sizeof(struct hostData)));
hostArraySize = 2 * hostArraySize;
} else
{
- for (j = numHosts; j > i; j--){
+ for (j = numHosts; j > i; j--) {
hostArray[j] = hostArray[j-1];
hostReplied[j] = hostReplied[j-1];
}
hostArray[i] = newHost;
hostReplied[i] = 0;
}
- for(j = 0; j < numBlocks; j++){
+ for(j = 0; j < numBlocks; j++) {
if (blockOwnerArray[j] >= i)
blockOwnerArray[j]++;
}
}
//nothing greater, add to end
- if (numHosts == hostArraySize){
+ if (numHosts == hostArraySize) {
newHostArray = calloc(2 * hostArraySize, sizeof(struct hostData));
newHostReplied = calloc(2 * hostArraySize, sizeof(unsigned char));
memcpy(newHostArray, hostArray, (numHosts * sizeof(struct hostData)));
void makeAssignments() {
int i;
- if (numBlocks < numHosts){
+ if (numBlocks < numHosts) {
free(blockOwnerArray);
while (numBlocks < numHosts)
numBlocks *= 2;
struct in_addr tmpAddr;
fprintf(logfile, "numHosts = %d\n", numHosts);
- for (i = 0; i < numHosts; i++){
+ for (i = 0; i < numHosts; i++) {
tmpAddr.s_addr = htonl(hostArray[i].ipAddr);
fprintf(logfile, "%d) %s, %d\n", i, inet_ntoa(tmpAddr),
hostArray[i].maxKeyCapacity);
va_start(args, format);
// if (fprintf(logfile, "%d.%06d:", now.tv_sec, now.tv_usec) < 0)
// { perror("dhtLog():fprintf()"); }
- if (vfprintf(logfile, format, args) < 0){
+ if (vfprintf(logfile, format, args) < 0) {
perror("dhtLog():vfprintf()");
}
- if (fflush(logfile) == EOF){
+ if (fflush(logfile) == EOF) {
perror("dhtLog():fflush()");
}
va_end(args);
dhtLog("udpListen(): linstening on port %d...\n", UDP_PORT);
- while (1){
+ while (1) {
pollret = poll(&udpPollSock, 1, TIMEOUT_PERIOD);
pthread_mutex_lock(&stateMutex);
oldState = state;
- if (pollret < 0){
+ if (pollret < 0) {
perror("udpListen():poll()");
} else if (pollret > 0) {
bytesRcvd = recvfrom(udpPollSock.fd, inBuffer, MAX_MSG_SIZE, 0,
(struct sockaddr *)&peerAddr, &socklen);
- if (bytesRcvd < 1){
+ if (bytesRcvd < 1) {
dhtLog("udpListen(): ERROR: bytesRcvd = %d\n", bytesRcvd);
} else if (inBuffer[0] >= NUM_MSG_TYPES) {
dhtLog("udpListen(): ERROR: unknown msg type = %d\n", inBuffer[0]);
dhtLog(" %x", inBuffer[i]);
dhtLog("\n");
peerIp = ntohl(peerAddr.sin_addr.s_addr);
- if (peerIp == seed && inBuffer[0] == WHO_IS_LEADER_RES){
+ if (peerIp == seed && inBuffer[0] == WHO_IS_LEADER_RES) {
tmpHost.ipAddr = peerIp;
tmpHost.maxKeyCapacity = 0;
addHost(tmpHost);
leader = read4(&inBuffer[1]);
tmpAddr.s_addr = htonl(leader);
dhtLog("leader = %s\n", inet_ntoa(tmpAddr));
- if (leader != 0){
+ if (leader != 0) {
setState(INIT2_STATE);
outBuffer[0] = JOIN_REQ;
write4(&outBuffer[1], myHostData.maxKeyCapacity);
dhtLog(" %x", inBuffer[i]);
dhtLog("\n");
peerIp = ntohl(peerAddr.sin_addr.s_addr);
- switch (inBuffer[0]){
+ switch (inBuffer[0]) {
case INSERT_CMD:
if (state == NORMAL_STATE || state == LEAD_NORMAL1_STATE
|| state == LEAD_NORMAL2_STATE || state == REBUILD4_STATE
- || state == REBUILD5_STATE || state == LEAD_REBUILD3_STATE){
+ || state == REBUILD5_STATE || state == LEAD_REBUILD3_STATE) {
tmpKey = read4(&inBuffer[1]);
tmpVal = read4(&inBuffer[5]);
outBuffer[0] = INSERT_RES;
- if (getKeyOwner(tmpKey) == myHostData.ipAddr){
+ if (getKeyOwner(tmpKey) == myHostData.ipAddr) {
if (chashInsert(myHashTable, tmpKey, (void *)tmpVal) == 0)
outBuffer[1] = OPERATION_OK;
else
case REMOVE_CMD:
if (state == NORMAL_STATE || state == LEAD_NORMAL1_STATE
- || state == LEAD_NORMAL2_STATE){
+ || state == LEAD_NORMAL2_STATE) {
tmpKey = read4(&inBuffer[1]);
outBuffer[0] = REMOVE_RES;
- if (getKeyOwner(tmpKey) == myHostData.ipAddr){
+ if (getKeyOwner(tmpKey) == myHostData.ipAddr) {
if (chashRemove(myHashTable, tmpKey) == 0)
outBuffer[1] = OPERATION_OK;
else
case SEARCH_CMD:
if (state == NORMAL_STATE || state == LEAD_NORMAL1_STATE
- || state == LEAD_NORMAL2_STATE){
+ || state == LEAD_NORMAL2_STATE) {
tmpKey = read4(&inBuffer[1]);
outBuffer[0] = SEARCH_RES;
- if (getKeyOwner(tmpKey) == myHostData.ipAddr){
- if ((tmpVal = (unsigned int)chashSearch(myHashTable, tmpKey)) != 0){
+ if (getKeyOwner(tmpKey) == myHostData.ipAddr) {
+ if ((tmpVal = (unsigned int)chashSearch(myHashTable, tmpKey)) != 0) {
outBuffer[1] = OPERATION_OK;
write4(&outBuffer[2], tmpVal);
} else
break;
case JOIN_REQ:
- if (state == LEAD_NORMAL1_STATE || state == LEAD_NORMAL2_STATE){
+ if (state == LEAD_NORMAL1_STATE || state == LEAD_NORMAL2_STATE) {
tmpHost.ipAddr = peerIp;
tmpHost.maxKeyCapacity = read4(&inBuffer[1]);
addHost(tmpHost);
outBuffer[0] = JOIN_RES;
outBuffer[1] = 0; //status, success
udpSend(outBuffer, 2, peerIp);
- if (allReplied()){
+ if (allReplied()) {
makeAssignments();
setState(LEAD_REBUILD2_STATE);
outBuffer[0] = DHT_UPDATE_CMD;
break;
case JOIN_RES:
- if (state == REBUILD1_STATE){
+ if (state == REBUILD1_STATE) {
setState(REBUILD2_STATE);
} else if (state == INIT2_STATE) {
setState(NORMAL_STATE);
break;
case LEAVE_REQ:
- if (state == LEAD_NORMAL1_STATE || state == LEAD_NORMAL2_STATE){ //TODO: make this graceful, instead of just rebuilding
+ if (state == LEAD_NORMAL1_STATE || state == LEAD_NORMAL2_STATE) { //TODO: make this graceful, instead of just rebuilding
removeHost(peerIp);
if (state != LEAD_NORMAL2_STATE)
setState(LEAD_NORMAL2_STATE);
break;
case DHT_UPDATE_CMD:
- if (state == REBUILD2_STATE && peerIp == leader){
+ if (state == REBUILD2_STATE && peerIp == leader) {
free(hostArray);
free(blockOwnerArray);
numHosts = read2(&inBuffer[1]);
break;
case DHT_UPDATE_RES:
- if (state == LEAD_REBUILD2_STATE){
+ if (state == LEAD_REBUILD2_STATE) {
checkReplied(peerIp);
- if (allReplied()){
+ if (allReplied()) {
setState(LEAD_REBUILD3_STATE);
outBuffer[0] = FILL_DHT_CMD;
udpSendAll(outBuffer, 1);
case ELECT_LEADER_CMD:
tmpUInt = read4(&inBuffer[1]);
if ((state == ELECT1_STATE || state == ELECT2_STATE)
- && tmpUInt >= electionOriginator){ //already participating in a higher-priority election
+ && tmpUInt >= electionOriginator) { //already participating in a higher-priority election
outBuffer[0] = ELECT_LEADER_RES;
outBuffer[1] = 0xFF;
udpSend(outBuffer, 2, peerIp);
//don't bother forwarding the message to originator or parent
checkReplied(electionOriginator);
checkReplied(electionParent);
- if (allReplied()){ //in case that is everybody I know of
+ if (allReplied()) { //in case that is everybody I know of
setState(ELECT2_STATE);
outBuffer[0] = ELECT_LEADER_RES;
outBuffer[1] = 0;
break;
case ELECT_LEADER_RES:
- if (state == ELECT1_STATE){
+ if (state == ELECT1_STATE) {
checkReplied(peerIp);
- if (inBuffer[1] != 0xFF){
+ if (inBuffer[1] != 0xFF) {
tmpUShort = read2(&inBuffer[2]);
hostDataPtr = (struct hostData *)&inBuffer[4];
for (i = 0; i < tmpUShort; i++)
addHost(hostDataPtr[i]);
writeHostList();
}
- if (allReplied()){
+ if (allReplied()) {
setState(ELECT2_STATE);
- if (electionOriginator == myHostData.ipAddr){
+ if (electionOriginator == myHostData.ipAddr) {
leader = hostArray[0].ipAddr;
- if (leader == myHostData.ipAddr){ //I am the leader
+ if (leader == myHostData.ipAddr) { //I am the leader
dhtLog("I am the leader!\n");
setState(LEAD_REBUILD1_STATE);
outBuffer[0] = REBUILD_CMD;
break;
case CONGRATS_CMD:
- if (state == ELECT2_STATE){ //I am the leader
+ if (state == ELECT2_STATE) { //I am the leader
leader = myHostData.ipAddr;
dhtLog("I am the leader!\n");
tmpUShort = read2(&inBuffer[1]);
break;
case REBUILD_REQ:
- if (state == LEAD_NORMAL1_STATE || state == LEAD_NORMAL2_STATE){
+ if (state == LEAD_NORMAL1_STATE || state == LEAD_NORMAL2_STATE) {
setState(LEAD_REBUILD1_STATE);
outBuffer[0] = REBUILD_CMD;
udpSendAll(outBuffer, 1);
break;
case FILL_DHT_CMD:
- if (state == REBUILD3_STATE && peerIp == leader){
+ if (state == REBUILD3_STATE && peerIp == leader) {
setState(REBUILD4_STATE);
if (fillStatus != 0)
dhtLog("udpListen(): ERROR: fillTask already running\n");
break;
case FILL_DHT_RES:
- if (state == LEAD_REBUILD3_STATE){
+ if (state == LEAD_REBUILD3_STATE) {
checkReplied(peerIp);
- if (allReplied() && fillStatus == 2){
+ if (allReplied() && fillStatus == 2) {
fillStatus = 0;
setState(LEAD_REBUILD4_STATE);
outBuffer[0] = RESUME_NORMAL_CMD;
break;
case RESUME_NORMAL_CMD:
- if (state == REBUILD5_STATE && peerIp == leader){
+ if (state == REBUILD5_STATE && peerIp == leader) {
setState(NORMAL_STATE);
outBuffer[0] = RESUME_NORMAL_RES;
udpSend(outBuffer, 1, leader);
break;
case RESUME_NORMAL_RES:
- if (state == LEAD_REBUILD4_STATE){
+ if (state == LEAD_REBUILD4_STATE) {
checkReplied(peerIp);
- if (allReplied()){
+ if (allReplied()) {
setState(LEAD_NORMAL1_STATE);
}
}
}
}
}
- if (state == REBUILD4_STATE){
- switch (fillStatus){
+ if (state == REBUILD4_STATE) {
+ switch (fillStatus) {
case 0: dhtLog("udpListen(): ERROR: fillStatus=0 in REBUILD4_STATE\n");
break;
break;
}
}
- if (state == LEAD_REBUILD3_STATE){
- switch (fillStatus){
+ if (state == LEAD_REBUILD3_STATE) {
+ switch (fillStatus) {
case 0: dhtLog("udpListen(): ERROR: fillStatus=0 in LEAD_REBUILD3_STATE\n");
break;
break;
case 2: //I'm done, now is everybody else also done?
- if (allReplied()){
+ if (allReplied()) {
fillStatus = 0;
setState(LEAD_REBUILD4_STATE);
outBuffer[0] = RESUME_NORMAL_CMD;
break;
}
}
- if (timerSet){
+ if (timerSet) {
gettimeofday(&now, NULL);
- if (timercmp(&now, &timer, >)){
- if (timeoutCntr < retry_vals[state]){
+ if (timercmp(&now, &timer, >)) {
+ if (timeoutCntr < retry_vals[state]) {
timeoutCntr++;
timeradd(&now, &timeout_vals[state], &timer);
dhtLog("udpListen(): retry: %d\n", timeoutCntr);
- switch (state){
+ switch (state) {
case INIT1_STATE:
outBuffer[0] = WHO_IS_LEADER_CMD;
udpSend(outBuffer, 1, seed);
break;
case ELECT2_STATE:
- if (electionOriginator == myHostData.ipAddr){ //retry notify leader
+ if (electionOriginator == myHostData.ipAddr) { //retry notify leader
outBuffer[0] = CONGRATS_CMD;
write2(&outBuffer[1], numHosts);
memcpy(&outBuffer[3], hostArray, sizeof(struct hostData)
{
dhtLog("udpListen(): timed out in state %s after %d retries\n",
state_names[state], timeoutCntr);
- switch (state){
+ switch (state) {
case INIT1_STATE:
setState(EXIT2_STATE);
break;
dhtLog("after\n");
writeHostList();
setState(ELECT2_STATE);
- if (electionOriginator == myHostData.ipAddr){
+ if (electionOriginator == myHostData.ipAddr) {
leader = hostArray[0].ipAddr;
- if (leader == myHostData.ipAddr){ //I am the leader
+ if (leader == myHostData.ipAddr) { //I am the leader
dhtLog("I am the leader!\n");
setState(LEAD_REBUILD1_STATE);
outBuffer[0] = REBUILD_CMD;
/* Create an array of oids for modified objects */
oidmod = (unsigned int *) calloc(fixed.nummod, sizeof(unsigned int));
- if (oidmod == NULL){
+ if (oidmod == NULL) {
printf("calloc error %s, %d\n", __FILE__, __LINE__);
return 1;
}
UnLock(STATUSPTR(header));
} else {
UnLock(STATUSPTR(header));
- if ((sd = socket(AF_INET, SOCK_STREAM, 0)) < 0){
+ if ((sd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
perror("processReqNotify():socket()");
return;
}
remoteAddr.sin_port = htons(LISTEN_PORT);
remoteAddr.sin_addr.s_addr = htonl(mid);
- if (connect(sd, (struct sockaddr *)&remoteAddr, sizeof(remoteAddr)) < 0){
+ if (connect(sd, (struct sockaddr *)&remoteAddr, sizeof(remoteAddr)) < 0) {
printf("Error: processReqNotify():error %d connecting to %s:%d\n", errno,
inet_ntoa(remoteAddr.sin_addr), LISTEN_PORT);
close(sd);
memset(&interfaceInfo, 0, sizeof(struct ifreq));
- if((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0){
+ if((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
perror("getMyIpAddr():socket()");
return 1;
}
strcpy(interfaceInfo.ifr_name, interfaceStr);
myAddr->sin_family = AF_INET;
- if(ioctl(sock, SIOCGIFADDR, &interfaceInfo) != 0){
+ if(ioctl(sock, SIOCGIFADDR, &interfaceInfo) != 0) {
perror("getMyIpAddr():ioctl()");
return 1;
}
keys = calloc(*numKeys, sizeof(unsigned int));
keyindex = 0;
- for (i = 0; i < mlookup.size; i++){
- if (mlookup.table[i].key != 0){
+ for (i = 0; i < mlookup.size; i++) {
+ if (mlookup.table[i].key != 0) {
curr = &mlookup.table[i];
- while (curr != NULL){
+ while (curr != NULL) {
keys[keyindex++] = curr->key;
curr = curr->next;
}
inline int findmax(int *array, int arraylength) {
int max, i;
max = array[0];
- for(i = 0; i < arraylength; i++){
+ for(i = 0; i < arraylength; i++) {
if(array[i] > max) {
max = array[i];
}
/* This function initializes things required in the transaction start*/
transrecord_t *transStart() {
transrecord_t *tmp;
- if((tmp = calloc(1, sizeof(transrecord_t))) == NULL){
+ if((tmp = calloc(1, sizeof(transrecord_t))) == NULL) {
printf("%s() Calloc error at line %d, %s\n", __func__, __LINE__, __FILE__);
return NULL;
}
return NULL;
}
- if((objheader = chashSearch(record->lookupTable, oid)) != NULL){
+ if((objheader = chashSearch(record->lookupTable, oid)) != NULL) {
#ifdef TRANSSTATS
nchashSearch++;
#endif
for (i = 0; i < threadnum; i++) {
rc = pthread_join(thread[i], NULL);
- if(rc){
+ if(rc) {
printf("Error: return code from pthread_join() is %d\n", rc);
pthread_cond_destroy(&tcond);
pthread_mutex_destroy(&tlock);
/* clear objects from prefetch cache */
cleanPCache(tdata);
#endif
- } else if(transagree == tdata->buffer->f.mcount){
+ } else if(transagree == tdata->buffer->f.mcount) {
/* Send Commit */
*(tdata->replyctrl) = TRANS_COMMIT;
*(tdata->replyretry) = 0;
pthread_cond_wait(localtdata->tdata->threshold, localtdata->tdata->lock);
}
pthread_mutex_unlock(localtdata->tdata->lock);
- if(*(localtdata->tdata->replyctrl) == TRANS_ABORT){
+ if(*(localtdata->tdata->replyctrl) == TRANS_ABORT) {
if(transAbortProcess(localtdata) != 0) {
printf("Error in transAbortProcess() %s,%d\n", __FILE__, __LINE__);
fflush(stdout);
goto tuple;
}
//Entire prefetch is local
- if (newbase==endindex&&checkoid(oid)){
+ if (newbase==endindex&&checkoid(oid)) {
numLocal++;
goto tuple;
}
int bytesSent;
int status;
- if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0){
+ if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
perror("startRemoteThread():socket()");
return -1;
}
remoteAddr.sin_port = htons(LISTEN_PORT);
remoteAddr.sin_addr.s_addr = htonl(mid);
- if (connect(sock, (struct sockaddr *)&remoteAddr, sizeof(remoteAddr)) < 0){
+ if (connect(sock, (struct sockaddr *)&remoteAddr, sizeof(remoteAddr)) < 0) {
printf("startRemoteThread():error %d connecting to %s:%d\n", errno,
inet_ntoa(remoteAddr.sin_addr), LISTEN_PORT);
status = -1;
static unsigned int id = 0xFFFFFFFF;
unsigned int getNewOID(void) {
id += 2;
- if (id > oidMax || id < oidMin){
+ if (id > oidMax || id < oidMin) {
id = (oidMin | 1);
}
return id;
in_addr_t tmpAddr;
configFile = fopen(CONFIG_FILENAME, "r");
- if (configFile == NULL){
+ if (configFile == NULL) {
printf("error opening %s:\n", CONFIG_FILENAME);
perror("");
return -1;
sizeOfHostArray = 8;
hostIpAddrs = calloc(sizeOfHostArray, sizeof(unsigned int));
- while(fgets(lineBuffer, maxLineLength, configFile) != NULL){
+ while(fgets(lineBuffer, maxLineLength, configFile) != NULL) {
commentBegin = strchr(lineBuffer, '#');
if (commentBegin != NULL)
*commentBegin = '\0';
token = strtok(lineBuffer, delimiters);
- while (token != NULL){
+ while (token != NULL) {
tmpAddr = inet_addr(token);
- if ((int)tmpAddr == -1){
+ if ((int)tmpAddr == -1) {
printf("error in %s: bad token:%s\n", CONFIG_FILENAME, token);
fclose(configFile);
return -1;
fclose(configFile);
- if (numHostsInSystem < 1){
+ if (numHostsInSystem < 1) {
printf("error in %s: no IP Adresses found\n", CONFIG_FILENAME);
return -1;
}
myIpAddr = getMyIpAddr("eth0");
#endif
myIndexInHostArray = findHost(myIpAddr);
- if (myIndexInHostArray == -1){
+ if (myIndexInHostArray == -1) {
printf("error in %s: IP Address of eth0 not found\n", CONFIG_FILENAME);
return -1;
}
if (findHost(hostIp) != -1)
return;
- if (numHostsInSystem == sizeOfHostArray){
+ if (numHostsInSystem == sizeOfHostArray) {
tmpArray = calloc(sizeOfHostArray * 2, sizeof(unsigned int));
memcpy(tmpArray, hostIpAddrs, sizeof(unsigned int) * numHostsInSystem);
free(hostIpAddrs);
return;
}
- if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0){
+ if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
perror("reqNotify():socket()");
return -1;
}
}
/* Send number of oids, oidarry, version array, machine id and threadid */
- if (connect(sock, (struct sockaddr *)&remoteAddr, sizeof(remoteAddr)) < 0){
+ if (connect(sock, (struct sockaddr *)&remoteAddr, sizeof(remoteAddr)) < 0) {
printf("reqNotify():error %d connecting to %s:%d\n", errno,
inet_ntoa(remoteAddr.sin_addr), LISTEN_PORT);
free(ndata);
return;
} else {
for(i = 0; i < ndata->numoid; i++) {
- if(ndata->oidarry[i] == oid){
+ if(ndata->oidarry[i] == oid) {
objIsFound = 1;
index = i;
}
}
- if(objIsFound == 0){
+ if(objIsFound == 0) {
printf("threadNotify(): Oid not found %s, %d\n", __FILE__, __LINE__);
return;
} else {
- if(version <= ndata->versionarry[index]){
+ if(version <= ndata->versionarry[index]) {
printf("threadNotify(): New version %d has not changed since last version for oid = %d, %s, %d\n", version, oid, __FILE__, __LINE__);
return;
} else {
ptr = *head;
mid = ptr->mid;
//create a socket connection to that machine
- if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0){
+ if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
perror("notifyAll():socket()");
return -1;
}
remoteAddr.sin_port = htons(LISTEN_PORT);
remoteAddr.sin_addr.s_addr = htonl(mid);
//send Thread Notify response and threadid to that machine
- if (connect(sock, (struct sockaddr *)&remoteAddr, sizeof(remoteAddr)) < 0){
+ if (connect(sock, (struct sockaddr *)&remoteAddr, sizeof(remoteAddr)) < 0) {
printf("notifyAll():error %d connecting to %s:%d\n", errno,
inet_ntoa(remoteAddr.sin_addr), LISTEN_PORT);
fflush(stdout);
thread_data_array[i].numreceiveobjs = 0;
printf("[main] creating thread %d\n", i);
rc[i] = pthread_create(&threads[i], NULL, run, (void *)&thread_data_array[i]);
- if (rc[i]){
+ if (rc[i]) {
printf("[main] ERROR; return code from pthread_create() is %d\n", rc[i]);
fflush(stdout);
exit(-1);
#ifdef RAWDEBUG
raw_test_pass(0xee13);
#endif
- while(halt--){
+ while(halt--) {
}
isfirst = false;
#ifdef RAWDEBUG
int hashCodetpd(struct taskparamdescriptor *ftd) {
int hash=(int)ftd->task;
int i;
- for(i=0; i<ftd->numParameters; i++){
+ for(i=0; i<ftd->numParameters; i++) {
hash^=(int)ftd->parameterArray[i];
}
return hash;
tpd->task=task;
tpd->numParameters=numiterators+1;
tpd->parameterArray=RUNMALLOC(sizeof(void *)*(numiterators+1));
- for(j=0; j<=numiterators; j++){
+ for(j=0; j<=numiterators; j++) {
tpd->parameterArray[j]=taskpointerarray[j]; //store the actual parameters
}
/* Enqueue task */
tpd->task=task;
tpd->numParameters=numiterators+1;
tpd->parameterArray=RUNMALLOC_I(sizeof(void *)*(numiterators+1));
- for(j=0; j<=numiterators; j++){
+ for(j=0; j<=numiterators; j++) {
tpd->parameterArray[j]=taskpointerarray[j]; //store the actual parameters
}
/* Enqueue task */
if(hashsize(activetasks) == 1) {
// only one task right now, wait a little while before next try
int halt = 10000;
- while(halt--){
+ while(halt--) {
}
}
goto newtask;
}*/
/* Actually call task */
#ifdef PRECISE_GC
- ((int *)taskpointerarray)[0]=currtpd->numParameters;
+ ((int *)taskpointerarray)[0]=currtpd->numParameters;
taskpointerarray[1]=NULL;
#endif
execute:
- if(debugtask){
+ if(debugtask) {
#ifndef RAW
printf("ENTER %s count=%d\n",currtpd->task->name, (instaccum-instructioncount));
#endif
int hashCodetpd(struct taskparamdescriptor *ftd) {
int hash=(int)ftd->task;
int i;
- for(i=0; i<ftd->numParameters; i++){
+ for(i=0; i<ftd->numParameters; i++) {
hash^=(int)ftd->parameterArray[i];
}
return hash;
void flagorand(void * ptr, int ormask, int andmask) {
#ifdef OPTIONAL
struct ___Object___ * obj = (struct ___Object___ *)ptr;
- if(obj->numfses){ /*store the information about fses*/
+ if(obj->numfses) { /*store the information about fses*/
int flag, i, j,counter, offset=0;
for(i=0; i<obj->numfses; i++) {
int oldoffset;
int checktags(struct ___Object___ * currobj, struct fsanalysiswrapper * fswrapper) {
/* Check Tags */
struct ___Object___ * tagptr = currobj->___tags___;
- if(fswrapper->numtags>0){
+ if(fswrapper->numtags>0) {
if (tagptr==NULL)
return 0; //that means the object has no tag but that param
//needs tag
/* Find initial state */
for(j=0; j<numiterators; j++) {
backtrackinit:
- if(toiHasNext(¶meter->iterators[j], taskpointerarray OPTARG(failed))){
+ if(toiHasNext(¶meter->iterators[j], taskpointerarray OPTARG(failed))) {
toiNext(¶meter->iterators[j], taskpointerarray OPTARG(failed));
} else if (j>0) {
/* Need to backtrack */
#ifdef OPTIONAL
tpd->failed=RUNMALLOC(sizeof(int)*(numiterators+1));
#endif
- for(j=0; j<=numiterators; j++){
+ for(j=0; j<=numiterators; j++) {
tpd->parameterArray[j]=taskpointerarray[j]; //store the actual parameters
#ifdef OPTIONAL
tpd->failed[j]=failed[j];
for(j=numiterators-1; j<numiterators; j++) {
backtrackinc:
- if(toiHasNext(¶meter->iterators[j], taskpointerarray OPTARG(failed))){
+ if(toiHasNext(¶meter->iterators[j], taskpointerarray OPTARG(failed))) {
toiNext(¶meter->iterators[j], taskpointerarray OPTARG(failed));
} else if (j>0) {
/* Need to backtrack */
restorecheckpoint(currtpd->task->numParameters, currtpd->parameterArray, checkpoint, forward, reverse);
#ifdef OPTIONAL
- for(counter=0; counter<currtpd->task->numParameters; counter++){
+ for(counter=0; counter<currtpd->task->numParameters; counter++) {
//enqueue as failed
enqueueoptional(currtpd->parameterArray[counter], numfsesarray[counter], fsesarray[counter], currtpd->task, counter);
}
/* Actually call task */
#ifdef PRECISE_GC
- ((int *)taskpointerarray)[0]=currtpd->numParameters;
+ ((int *)taskpointerarray)[0]=currtpd->numParameters;
taskpointerarray[1]=NULL;
#endif
#ifdef OPTIONAL
((struct ___Object___ *)taskpointerarray[i+OFFSET])->fses=fsesarray[i];
}
#endif
- if(debugtask){
+ if(debugtask) {
printf("ENTER %s count=%d\n",currtpd->task->name, (instaccum-instructioncount));
((void(*) (void **))currtpd->task->taskptr)(taskpointerarray);
printf("EXIT %s count=%d\n",currtpd->task->name, (instaccum-instructioncount));
sp_catch_brace = Add
sp_brace_catch = Add
sp_try_brace = Add
+sp_after_sparen = Add
\ No newline at end of file
sp_brace_else = Add
sp_catch_brace = Add
sp_brace_catch = Add
-sp_try_brace = Add
\ No newline at end of file
+sp_try_brace = Add
+sp_after_sparen = Add
\ No newline at end of file