mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 20:23:06 +00:00
Merge pull request #725 from dingmingxin/master
using clock_gettime in macos(in macos_10.12 and later)
This commit is contained in:
@@ -13,6 +13,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#if defined(__APPLE__)
|
#if defined(__APPLE__)
|
||||||
|
#include <AvailabilityMacros.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <mach/task.h>
|
#include <mach/task.h>
|
||||||
#include <mach/mach.h>
|
#include <mach/mach.h>
|
||||||
@@ -232,7 +233,7 @@ skynet_timeout(uint32_t handle, int time, int session) {
|
|||||||
// centisecond: 1/100 second
|
// centisecond: 1/100 second
|
||||||
static void
|
static void
|
||||||
systime(uint32_t *sec, uint32_t *cs) {
|
systime(uint32_t *sec, uint32_t *cs) {
|
||||||
#if !defined(__APPLE__)
|
#if !defined(__APPLE__) || defined(AVAILABLE_MAC_OS_X_VERSION_10_12_AND_LATER)
|
||||||
struct timespec ti;
|
struct timespec ti;
|
||||||
clock_gettime(CLOCK_REALTIME, &ti);
|
clock_gettime(CLOCK_REALTIME, &ti);
|
||||||
*sec = (uint32_t)ti.tv_sec;
|
*sec = (uint32_t)ti.tv_sec;
|
||||||
@@ -248,7 +249,7 @@ systime(uint32_t *sec, uint32_t *cs) {
|
|||||||
static uint64_t
|
static uint64_t
|
||||||
gettime() {
|
gettime() {
|
||||||
uint64_t t;
|
uint64_t t;
|
||||||
#if !defined(__APPLE__)
|
#if !defined(__APPLE__) || defined(AVAILABLE_MAC_OS_X_VERSION_10_12_AND_LATER)
|
||||||
struct timespec ti;
|
struct timespec ti;
|
||||||
clock_gettime(CLOCK_MONOTONIC, &ti);
|
clock_gettime(CLOCK_MONOTONIC, &ti);
|
||||||
t = (uint64_t)ti.tv_sec * 100;
|
t = (uint64_t)ti.tv_sec * 100;
|
||||||
@@ -305,7 +306,7 @@ skynet_timer_init(void) {
|
|||||||
|
|
||||||
uint64_t
|
uint64_t
|
||||||
skynet_thread_time(void) {
|
skynet_thread_time(void) {
|
||||||
#if !defined(__APPLE__)
|
#if !defined(__APPLE__) || defined(AVAILABLE_MAC_OS_X_VERSION_10_12_AND_LATER)
|
||||||
struct timespec ti;
|
struct timespec ti;
|
||||||
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ti);
|
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ti);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user