mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 12:20:41 +00:00
_POSIX_TIMERS & _POSIX_THREAD_CPUTIME 在 unistd.h
头文件定义,但并未包含。之前写法不正确,可以工作只是巧合。 现改为,默认使用 clock_gettime,当为 Max OSX 平台时,使用兼容方法。
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user