1
This commit is contained in:
parent
4e70850cd9
commit
e2b946dcb4
@ -1,8 +1,32 @@
|
||||
package a6;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
|
||||
public class SysUtils {
|
||||
|
||||
public static void test() {
|
||||
System.out.println("test");
|
||||
}
|
||||
|
||||
public static int getDaySeconds(int time_val, int incdays) {
|
||||
int time_zone = 8;
|
||||
return (int)((time_val + time_zone * 3600)/3600/24 + incdays) * 3600 * 24 - 3600 * time_zone;
|
||||
}
|
||||
|
||||
public static int now() {
|
||||
return (int)(System.currentTimeMillis() / 1000);
|
||||
}
|
||||
|
||||
public static final <T> T[] newArray(Class<T> cls, int size) {
|
||||
T[] arr = (T[])Array.newInstance(cls, size);
|
||||
try {
|
||||
for (int i = 0; i < arr.length; ++i) {
|
||||
arr[i] = cls.newInstance();
|
||||
}
|
||||
return arr;
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
53
Timer.java
53
Timer.java
@ -43,7 +43,13 @@ public class Timer {
|
||||
private void initTimerList(Timer timer, TimerType timer_type, int milli_seconds,
|
||||
XParams param, ITimerFunc timerFunc, ITimerAfterFunc afterFunc)
|
||||
{
|
||||
|
||||
this.timerType = timer_type;
|
||||
this.expires = timer.getTickCount.GetTickCount(timer.content) + milli_seconds;
|
||||
this.milli_seconds = milli_seconds;
|
||||
this.fixedTimerExecuteTimes = 0;
|
||||
this.timerFunc = timerFunc;
|
||||
this.timerAfterFunc = afterFunc;
|
||||
this.param = param;
|
||||
}
|
||||
}
|
||||
|
||||
@ -63,11 +69,11 @@ public class Timer {
|
||||
private Object content;
|
||||
private int gcTime = 0;
|
||||
private int cacheTimerNum = 0;
|
||||
private ListHead[] tv1 = new ListHead[TVR_SIZE];
|
||||
private ListHead[] tv2 = new ListHead[TVN_SIZE];
|
||||
private ListHead[] tv3 = new ListHead[TVN_SIZE];
|
||||
private ListHead[] tv4 = new ListHead[TVN_SIZE];
|
||||
private ListHead[] tv5 = new ListHead[TVN_SIZE];
|
||||
private ListHead[] tv1 = SysUtils.newArray(ListHead.class, TVR_SIZE);
|
||||
private ListHead[] tv2 = SysUtils.newArray(ListHead.class, TVN_SIZE);
|
||||
private ListHead[] tv3 = SysUtils.newArray(ListHead.class, TVN_SIZE);
|
||||
private ListHead[] tv4 = SysUtils.newArray(ListHead.class, TVN_SIZE);
|
||||
private ListHead[] tv5 = SysUtils.newArray(ListHead.class, TVN_SIZE);
|
||||
private ListHead workList = new ListHead();
|
||||
private ListHead cascadeList = new ListHead();
|
||||
|
||||
@ -79,7 +85,7 @@ public class Timer {
|
||||
}
|
||||
|
||||
public void unInit() {
|
||||
|
||||
clear();
|
||||
}
|
||||
|
||||
public void update() {
|
||||
@ -140,6 +146,7 @@ public class Timer {
|
||||
ITimerAfterFunc after_func) {
|
||||
TimerList timer = newTimerList();
|
||||
timer.initTimerList(this, TimerType.DEADLINE, expire_time, param, timer_func, after_func);
|
||||
modifyTimer(timer, expire_time);
|
||||
return timer;
|
||||
}
|
||||
|
||||
@ -169,8 +176,22 @@ public class Timer {
|
||||
return timer;
|
||||
}
|
||||
|
||||
public void modifyTimer(TimerList timer_list, int expire_time) {
|
||||
|
||||
public void modifyTimer(TimerList timer, int expire_time) {
|
||||
detachTimer(timer);
|
||||
if (timer.timerType == TimerType.FIXED) {
|
||||
long tick = System.currentTimeMillis();
|
||||
int today_passed_seconds = SysUtils.now() - SysUtils.getDaySeconds(SysUtils.now(), 0);
|
||||
timer.expires = (tick - today_passed_seconds * 1000) + expire_time;
|
||||
if (timer.fixedTimerExecuteTimes > 0) {
|
||||
if (timer.expires <= tick) {
|
||||
timer.expires += 1000 * 3600 * 24;
|
||||
}
|
||||
} else {
|
||||
timer.expires = getTickCount.GetTickCount(content) + expire_time;
|
||||
}
|
||||
}
|
||||
timer.milli_seconds = expire_time;
|
||||
internalAddTimer(timer);
|
||||
}
|
||||
|
||||
public TimerList getTimerByAttach(ListHead attach_entry) {
|
||||
@ -181,8 +202,9 @@ public class Timer {
|
||||
return timer_list.param;
|
||||
}
|
||||
|
||||
public long getRemainTime(TimerList timer_list) {
|
||||
return 0;
|
||||
public long getRemainTime(TimerList timer) {
|
||||
long remain_time = timer.expires - getTickCount.GetTickCount(content);
|
||||
return remain_time;
|
||||
}
|
||||
|
||||
public TimerList getRunningTimer() {
|
||||
@ -190,7 +212,14 @@ public class Timer {
|
||||
}
|
||||
|
||||
public int getIdleableMillSeconds() {
|
||||
return 0;
|
||||
int idle_time = 1;
|
||||
for (int lv1_idx = (int)(timerTick % TVR_MASK); lv1_idx < TVR_SIZE; ++lv1_idx) {
|
||||
if (!tv1[lv1_idx].empty()){
|
||||
return idle_time <= 1 ? 1 : idle_time - 1;
|
||||
}
|
||||
++idle_time;
|
||||
}
|
||||
return idle_time;
|
||||
}
|
||||
|
||||
public void deleteTimer(TimerList timer_list) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user