_POSIX_TIMERS & _POSIX_THREAD_CPUTIME 在 unistd.h

头文件定义,但并未包含。之前写法不正确,可以工作只是巧合。
现改为,默认使用 clock_gettime,当为 Max OSX 平台时,使用兼容方法。
This commit is contained in:
Yecheng Fu
2012-12-20 16:25:20 +08:00
parent 5d83155334
commit 5eb87dc769
3 changed files with 11 additions and 11 deletions

View File

@@ -9,7 +9,7 @@
#include <string.h>
#include <stdlib.h>
#if !defined(_POSIX_TIMERS)
#if defined(__APPLE__)
#include <sys/time.h>
#endif
@@ -203,7 +203,7 @@ skynet_timeout(uint32_t handle, int time, int session) {
static uint32_t
_gettime(void) {
uint32_t t;
#if defined(_POSIX_TIMERS)
#if !defined(__APPLE__)
struct timespec ti;
clock_gettime(CLOCK_MONOTONIC, &ti);
t = (uint32_t)(ti.tv_sec & 0xffffff) * 100;
@@ -245,7 +245,7 @@ skynet_timer_init(void) {
TI = timer_create_timer();
TI->current = _gettime();
#if defined(_POSIX_TIMERS)
#if !defined(__APPLE__)
struct timespec ti;
clock_gettime(CLOCK_REALTIME, &ti);
uint32_t sec = (uint32_t)ti.tv_sec;