1 package DEOS; 20 21 import gov.nasa.jpf.jvm.Verify; 22 23 24 27 class PriorityListOfThreads { 28 static final int numberOfThreadPriorities = 4; int itsHighestPriorityMember; 30 threadList[] itsList; 31 32 public PriorityListOfThreads () { 33 itsHighestPriorityMember = 0; 35 itsList = new threadList[numberOfThreadPriorities]; 36 37 for (int i = 0; i < numberOfThreadPriorities; i++) { 38 itsList[i] = new threadList(); 39 } 40 } 41 42 public boolean isEmpty () { 43 return highestPriorityMember().isEmpty(); 44 } 45 46 public void addAtBeginning (threadListNode theNode) { 47 int threadPriority = theNode.parent().currentPriority(); 50 itsList[threadPriority].addAtBeginning(theNode); 51 52 if (itsHighestPriorityMember < threadPriority) { 53 itsHighestPriorityMember = threadPriority; 54 } 55 56 } 58 59 public void addAtEnd (threadListNode theNode) { 60 int threadPriority = theNode.parent().currentPriority(); 62 itsList[threadPriority].addAtEnd(theNode); 63 64 if (itsHighestPriorityMember < threadPriority) { 65 itsHighestPriorityMember = threadPriority; 66 } 67 68 } 70 71 public threadListNode head () { 72 return highestPriorityMember().head(); 73 } 74 75 public void mergeList (PriorityListOfThreads otherList) { 76 threadList mine = itsList[0]; 78 threadList his = otherList.itsList[0]; 79 int end = otherList.itsHighestPriorityMember + 1; 80 int i = 0; 81 82 do { 83 mine.mergeList(his); 84 i++; 85 mine = itsList[i]; 86 his = otherList.itsList[i]; 87 } while (i != end); 88 89 if (itsHighestPriorityMember < otherList.itsHighestPriorityMember) { 90 itsHighestPriorityMember = otherList.itsHighestPriorityMember; 91 } 92 93 otherList.itsHighestPriorityMember = 0; 94 95 } 97 98 public void mergeList (threadList otherList) { 99 if (!otherList.isEmpty()) { 102 int otherListPriority = otherList.head().parent().currentPriority(); 103 104 105 itsList[otherListPriority].mergeList(otherList); 109 110 if (itsHighestPriorityMember < otherListPriority) { 111 itsHighestPriorityMember = otherListPriority; 112 } 113 } 114 115 } 117 118 private threadList highestPriorityMember () { 119 int hipri = itsHighestPriorityMember; 121 122 for (; hipri > 0; hipri--) { 123 if (!itsList[hipri].isEmpty()) { 124 break; 125 } 126 } 127 128 itsHighestPriorityMember = hipri; 129 130 return itsList[hipri]; 133 } 134 } | Popular Tags |