add start time

This commit is contained in:
云风
2012-08-13 10:34:51 +08:00
parent d7227cfd1a
commit 7f98adaf0d
3 changed files with 17 additions and 0 deletions

View File

@@ -356,6 +356,12 @@ skynet_command(struct skynet_context * context, const char * cmd , const char *
return NULL;
}
if (strcmp(cmd,"STARTTIME") == 0) {
uint32_t sec = skynet_gettime_fixsec();
sprintf(context->result,"%u",sec);
return context->result;
}
return NULL;
}

View File

@@ -38,6 +38,7 @@ struct timer {
int lock;
int time;
uint32_t current;
uint32_t starttime;
};
static struct timer * TI = NULL;
@@ -217,6 +218,11 @@ skynet_updatetime(void) {
}
}
uint32_t
skynet_gettime_fixsec(void) {
return TI->starttime;
}
uint32_t
skynet_gettime(void) {
return TI->current;
@@ -226,4 +232,8 @@ void
skynet_timer_init(void) {
TI = timer_create_timer();
TI->current = _gettime();
struct timespec ti;
clock_gettime(CLOCK_MONOTONIC, &ti);
TI->starttime = (uint32_t)(ti.tv_sec & 0xff000000);
}

View File

@@ -8,6 +8,7 @@
int skynet_timeout(uint32_t handle, int time, int session);
void skynet_updatetime(void);
uint32_t skynet_gettime(void);
uint32_t skynet_gettime_fixsec(void);
void skynet_timer_init(void);