compiles on macosx

This commit is contained in:
Yecheng Fu
2012-11-27 20:07:50 +08:00
parent b6314b537f
commit 8f29655d25
6 changed files with 232 additions and 28 deletions

View File

@@ -9,6 +9,10 @@
#include <string.h>
#include <stdlib.h>
#if !defined(_POSIX_TIMERS)
#include <sys/time.h>
#endif
typedef void (*timer_execute_func)(void *ud,void *arg);
#define TIME_NEAR_SHIFT 8
@@ -198,11 +202,18 @@ skynet_timeout(uint32_t handle, int time, int session) {
static uint32_t
_gettime(void) {
uint32_t t;
#if defined(_POSIX_TIMERS)
struct timespec ti;
clock_gettime(CLOCK_MONOTONIC, &ti);
uint32_t t = (uint32_t)(ti.tv_sec & 0xffffff) * 100;
t = (uint32_t)(ti.tv_sec & 0xffffff) * 100;
t += ti.tv_nsec / 10000000;
#else
struct timeval tv;
gettimeofday(&tv, NULL);
t = (uint32_t)(tv.tv_sec & 0xffffff) * 100;
t += tv.tv_usec / 10000;
#endif
return t;
}
@@ -234,9 +245,15 @@ skynet_timer_init(void) {
TI = timer_create_timer();
TI->current = _gettime();
#if defined(_POSIX_TIMERS)
struct timespec ti;
clock_gettime(CLOCK_REALTIME, &ti);
uint32_t sec = (uint32_t)ti.tv_sec;
#else
struct timeval tv;
gettimeofday(&tv, NULL);
uint32_t sec = (uint32_t)tv.tv_sec;
#endif
uint32_t mono = _gettime() / 100;
TI->starttime = sec - mono;