This commit is contained in:
aozhiwei 2018-11-30 09:48:57 +08:00
commit c6017a4fe2
2 changed files with 11 additions and 2 deletions

View File

@ -12,9 +12,18 @@ namespace a8
{ {
a8::tick_t XGetTickCount() a8::tick_t XGetTickCount()
{ {
#if 1
struct timeval tv;
gettimeofday(&tv, NULL);
long long time = tv.tv_usec;
time /= 1000;
time += (tv.tv_sec * 1000);
return time;
#else
struct timespec ts; struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts); clock_gettime(CLOCK_MONOTONIC, &ts);
return (ts.tv_sec*1000 + ts.tv_nsec/(1000*1000)); return (ts.tv_sec*1000 + ts.tv_nsec/(1000*1000));
#endif
} }
long long XGetNanoSeconds() long long XGetNanoSeconds()

View File

@ -245,7 +245,7 @@ namespace a8
int idle_time = 1; int idle_time = 1;
for (int lv1_idx = base_->timer_tick & TVR_MASK; lv1_idx < TVR_SIZE; ++lv1_idx) { for (int lv1_idx = base_->timer_tick & TVR_MASK; lv1_idx < TVR_SIZE; ++lv1_idx) {
if (!list_empty(base_->tv1.vec + lv1_idx)) { if (!list_empty(base_->tv1.vec + lv1_idx)) {
return idle_time; return idle_time <= 1 ? 1 : idle_time - 1;
} }
++idle_time; ++idle_time;
} }
@ -257,7 +257,7 @@ namespace a8
idle_time += TVR_SIZE; idle_time += TVR_SIZE;
} }
#endif #endif
return idle_time; return idle_time <= 1 ? 1 : idle_time - 1;
} }
void Timer::UpdateTimer() void Timer::UpdateTimer()