mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-22 02:53:09 +00:00
add start time
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user