1
This commit is contained in:
parent
7cfe69fdcd
commit
ea394ad9a9
@ -1,33 +1,38 @@
|
||||
package a6;
|
||||
|
||||
public class ListHead {
|
||||
public final class ListHead {
|
||||
|
||||
public ListHead next;
|
||||
public ListHead prev;
|
||||
public Object data;
|
||||
|
||||
public ListHead() {
|
||||
next = this;
|
||||
prev = this;
|
||||
init();
|
||||
}
|
||||
|
||||
public void del() {
|
||||
|
||||
public final void del() {
|
||||
next.prev = prev;
|
||||
prev.next = next;
|
||||
init();
|
||||
}
|
||||
|
||||
public void delInit() {
|
||||
|
||||
public final void delInit() {
|
||||
del();
|
||||
}
|
||||
|
||||
public void addTail(ListHead newNode) {
|
||||
|
||||
public final void addTail(ListHead pnew) {
|
||||
ListHead tmp_prev = prev;
|
||||
prev = pnew;
|
||||
pnew.next = this;
|
||||
pnew.prev = tmp_prev;
|
||||
tmp_prev.next = pnew;
|
||||
}
|
||||
|
||||
public Object firstEntry() {
|
||||
public final Object firstEntry() {
|
||||
return next.data;
|
||||
}
|
||||
|
||||
public void replace(ListHead pnew) {
|
||||
public final void replace(ListHead pnew) {
|
||||
pnew.next = next;
|
||||
pnew.next.prev = pnew;
|
||||
pnew.prev = prev;
|
||||
@ -35,17 +40,18 @@ public class ListHead {
|
||||
pnew.data = data;
|
||||
}
|
||||
|
||||
public void replaceInit(ListHead pnew) {
|
||||
public final void replaceInit(ListHead pnew) {
|
||||
replace(pnew);
|
||||
init();
|
||||
}
|
||||
|
||||
public boolean empty() {
|
||||
public final boolean empty() {
|
||||
return next == this;
|
||||
}
|
||||
|
||||
public void init() {
|
||||
|
||||
public final void init() {
|
||||
next = this;
|
||||
prev = this;
|
||||
}
|
||||
|
||||
}
|
||||
|
47
Timer.java
47
Timer.java
@ -69,6 +69,7 @@ public class Timer {
|
||||
private ListHead[] tv4 = new ListHead[TVN_SIZE];
|
||||
private ListHead[] tv5 = new ListHead[TVN_SIZE];
|
||||
private ListHead workList = new ListHead();
|
||||
private ListHead cascadeList = new ListHead();
|
||||
|
||||
public void init(IGetTickCountFunc func, Object content, int gc_time, int cache_timer_num) {
|
||||
this.getTickCount = func;
|
||||
@ -86,11 +87,11 @@ public class Timer {
|
||||
int index = (int)(timerTick & TVR_MASK);
|
||||
|
||||
if (index == 0 &&
|
||||
cascade(tv2, (int)((timerTick >> (TVR_BITS + 0 * TVN_BITS)) & TVN_MASK)) == 0 &&
|
||||
cascade(tv3, (int)((timerTick >> (TVR_BITS + 1 * TVN_BITS)) & TVN_MASK)) == 0 &&
|
||||
cascade(tv4, (int)((timerTick >> (TVR_BITS + 2 * TVN_BITS)) & TVN_MASK)) == 0
|
||||
cascade(tv2, getTimerIndex(index)) == 0 &&
|
||||
cascade(tv3, getTimerIndex(index)) == 0 &&
|
||||
cascade(tv4, getTimerIndex(index)) == 0
|
||||
) {
|
||||
cascade(tv5, (int)((timerTick >> (TVR_BITS + 3 * TVN_BITS)) & TVN_MASK));
|
||||
cascade(tv5, getTimerIndex(index));
|
||||
}
|
||||
|
||||
++timerTick;
|
||||
@ -227,7 +228,43 @@ public class Timer {
|
||||
}
|
||||
|
||||
private int cascade(ListHead[] tv, int index) {
|
||||
return 0;
|
||||
tv[index].replaceInit(cascadeList);
|
||||
|
||||
while (!cascadeList.empty()) {
|
||||
// internalAddTimer();
|
||||
}
|
||||
cascadeList.init();
|
||||
return index;
|
||||
}
|
||||
|
||||
private final int getTimerIndex(int index) {
|
||||
return (int)((timerTick >> (TVR_BITS + index * TVN_BITS)) & TVN_MASK);
|
||||
}
|
||||
|
||||
private final void internalAddTimer(TimerList timer) {
|
||||
long expires = timer.expires;
|
||||
long idx = expires - timerTick;
|
||||
ListHead vec;
|
||||
|
||||
if (idx < 0) {
|
||||
vec = tv1[(int)(timerTick & TVR_MASK)];
|
||||
} else if (idx < TVR_SIZE) {
|
||||
int i = (int)(expires & TVR_MASK);
|
||||
vec = tv1[i];
|
||||
} else if (idx < (1 << (TVR_BITS + TVN_BITS))) {
|
||||
int i = (int)(expires >> TVR_BITS) & TVN_MASK;
|
||||
vec = tv2[i];
|
||||
} else if (idx < (1 << (TVR_BITS + 2 * TVN_BITS))) {
|
||||
int i = (int)(expires >> (TVR_BITS + TVN_BITS)) & TVN_MASK;
|
||||
vec = tv3[i];
|
||||
} else if (idx < (1 << (TVR_BITS + 3 * TVN_BITS))) {
|
||||
int i = (int)(expires >> (TVR_BITS + 2 * TVN_BITS)) & TVN_MASK;
|
||||
vec = tv4[i];
|
||||
} else {
|
||||
int i = (int)(expires >> (TVR_BITS + 3 * TVN_BITS)) & TVN_MASK;
|
||||
vec = tv5[i];
|
||||
}
|
||||
vec.addTail(vec);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user